Skip to content

Commit

Permalink
container: add container image version
Browse files Browse the repository at this point in the history
This will allow to checkout older commits and run `make dockerdev`
without worrying if the container image version changed.
  • Loading branch information
Beerosagos committed Dec 10, 2024
1 parent e1d6d34 commit 5be2b03
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
1 change: 1 addition & 0 deletions .containerversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26
61 changes: 41 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,45 @@ concurrency:
cancel-in-progress: true

env:
# Use alternative image when running on GitHub workflows CI to avoid potential
# rate limiting when executing jobs in parallel: they can't cache docker images
# and always pull.
#
# To update this image, generate a personal token with write:packages scope
# on https://github.com/settings/tokens and authenticate yourself locally with
# "docker login ghcr.io -u <github-username>" using the
# newly generated token as password.
# Once logged in, tag an new image:
# docker tag shiftcrypto/bitbox-wallet-app:VERSION \
# ghcr.io/bitboxswiss/bitbox-wallet-app-ci:VERSION
# and push as usual:
# docker push ghcr.io/bitboxswiss/bitbox-wallet-app-ci:VERSION
# Lastly, update the next line to use the newly pushed image version.
# See docs for more details:
# https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images
#
# Keep this in sync with default in scripts/github-ci.sh.
CI_IMAGE: ghcr.io/bitboxswiss/bitbox-wallet-app-ci:26
GITHUB_BUILD_DIR: ${{github.workspace}}

jobs:
setup-env:
runs-on: ubuntu-22.04
outputs:
ci_image: ${{ steps.set-ci-image.outputs.ci_image }}
steps:
- name: Clone the repo
uses: actions/checkout@v4

- name: Read CI Image Version
id: set-ci-image
run: |
# Use alternative image when running on GitHub workflows CI to avoid potential
# rate limiting when executing jobs in parallel: they can't cache docker images
# and always pull.
#
# To update this image, generate a personal token with write:packages scope
# on https://github.com/settings/tokens and authenticate yourself locally with
# "docker login ghcr.io -u <github-username>" using the
# newly generated token as password.
# Once logged in, tag an new image:
# docker tag shiftcrypto/bitbox-wallet-app:VERSION \
# ghcr.io/bitboxswiss/bitbox-wallet-app-ci:VERSION
# and push as usual:
# docker push ghcr.io/bitboxswiss/bitbox-wallet-app-ci:VERSION
# Lastly, update the next line to use the newly pushed image version.
# See docs for more details:
# https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images
#
# Keep this in sync with default in scripts/github-ci.sh.
CI_IMAGE_VERSION=$(cat .containerversion)
echo "CI_IMAGE=ghcr.io/bitboxswiss/bitbox-wallet-app-ci:$CI_IMAGE_VERSION" >> $GITHUB_ENV
echo "::set-output name=ci_image::ghcr.io/bitboxswiss/bitbox-wallet-app-ci:$CI_IMAGE_VERSION"
test-lint:
runs-on: ubuntu-22.04
needs: setup-env
steps:
- name: Clone the repo
with:
Expand All @@ -42,8 +57,11 @@ jobs:
run: ./scripts/github-ci.sh ci
env:
OS_NAME: linux
CI_IMAGE: ${{ needs.setup-env.outputs.ci_image }}

android:
runs-on: ubuntu-22.04
needs: setup-env
outputs:
artifact-url: ${{ steps.upload.outputs.artifact-url }}
steps:
Expand All @@ -60,6 +78,7 @@ jobs:
run: ./scripts/github-ci.sh android
env:
OS_NAME: linux
CI_IMAGE: ${{ needs.setup-env.outputs.ci_image }}
- name: Upload APK
id: upload
uses: actions/upload-artifact@v4
Expand All @@ -69,6 +88,7 @@ jobs:
if-no-files-found: error
qt-linux:
runs-on: ubuntu-22.04
needs: setup-env
outputs:
artifact-url-ai: ${{ steps.upload-ai.outputs.artifact-url }}
artifact-url-deb: ${{ steps.upload-deb.outputs.artifact-url }}
Expand All @@ -82,6 +102,7 @@ jobs:
run: ./scripts/github-ci.sh qt-linux
env:
OS_NAME: linux
CI_IMAGE: ${{ needs.setup-env.outputs.ci_image }}
- name: Upload AppImage
id: upload-ai
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -193,7 +214,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
with:
submodules: recursive
- name: Install Node.js
uses: actions/setup-node@v4
Expand Down
17 changes: 8 additions & 9 deletions scripts/dockerdev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
CONTAINER_VERSION="$(cat $DIR/../.containerversion)"

if [ -n "$CONTAINER_RUNTIME" ]; then
RUNTIME="$CONTAINER_RUNTIME"
Expand All @@ -25,11 +26,7 @@ fi

dockerdev () {
local container_name=bitbox-wallet-dev

if ! $RUNTIME images | grep -q bitbox-wallet-app; then
echo "No bitbox-wallet docker image found! Maybe you need to run 'make dockerinit'?" >&2
exit 1
fi
local image_name=bitbox-wallet-app

USERFLAG=""
if [ "$RUNTIME" = "docker" ] ; then
Expand All @@ -38,13 +35,15 @@ dockerdev () {
fi

# If already running, enter the container.
if $RUNTIME ps | grep -q $container_name; then
if $RUNTIME ps | grep -q $image_name:$CONTAINER_VERSION; then
$RUNTIME exec $USERFLAG -it $container_name /opt/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/scripts/docker_init.sh
return
fi

if $RUNTIME ps -a | grep -q $container_name; then
$RUNTIME rm $container_name
# A container based on a different image version is running. Let's stop and remove it.
if $RUNTIME ps | grep -q $container_name; then
$RUNTIME stop $container_name
$RUNTIME rm $container_name
fi

local repo_path="$DIR/.."
Expand All @@ -58,7 +57,7 @@ dockerdev () {
--add-host="dev1.shiftcrypto.ch:176.9.28.155" \
--add-host="dev2.shiftcrypto.ch:176.9.28.156" \
-v "$repo_path":/opt/go/src/github.com/BitBoxSwiss/bitbox-wallet-app \
shiftcrypto/bitbox-wallet-app bash
shiftcrypto/$image_name:$CONTAINER_VERSION bash

if [ "$RUNTIME" = "docker" ] ; then
# Use same user/group id as on the host, so that files are not created as root in the
Expand Down

0 comments on commit 5be2b03

Please sign in to comment.