Skip to content

Commit

Permalink
use a dedicated versioning script for container builds
Browse files Browse the repository at this point in the history
  • Loading branch information
siosonel committed Oct 25, 2023
1 parent 133a8a0 commit 922e73b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 27 deletions.
34 changes: 13 additions & 21 deletions .github/workflows/CD-publish-app-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Publish Application Image"
on:
push:
branches:
- image
- app-image
- fake-image
paths-ignore:
- '**.md'
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
fi
- name: Check user permission
if: github.event_name == "workflow_dispatch"
if: github.event_name == 'workflow_dispatch'
id: check
uses: scherermichael-oss/action-has-permission@master
with:
Expand All @@ -44,7 +44,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Exit if user doesn't have write permission
if: github.event_name == "workflow_dispatch"
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ steps.check.outputs.has-permission }}" = "false" ]; then
echo "Only users with write permission are allowed to execute this workflow."
Expand All @@ -65,12 +65,6 @@ jobs:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
scope: '@sjcrh'
- run: npm ci

- name: Run version bump
run: |
./build/ci-version-update.sh $VERTYPE -w
# !!! --- merge back to master --- !!!

- name: Login to GitHub Container Registry
run: |
Expand All @@ -79,16 +73,14 @@ jobs:
CR_PAT: ${{ secrets.PAT }}

- name: Build and Publish Docker Images
run:
sleep 90;
cd container;
./build2.sh -r "ghcr.io/stjude/" server;
TAG="$(node -p "require('./server/package.json').version")";
HASH="$(git rev-parse --short HEAD)";
docker push ghcr.io/stjude/ppserver:$TAG-$HASH;
docker push ghcr.io/stjude/ppserver:latest;
run: |
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
MODE="-w"
if [[ "$BRANCH" != "app-image" && "$BRANCH" != "release-chain" && "$BRANCH" != "master" && ${{ github.event_name }} != "workflow_dispatch" ]]; then
MODE=""
fi
cd container
npm install glob
./release.sh "$MODE"
./build2.sh -r "ghcr.io/stjude/" full;
TAG="$(node -p "require('./full/package.json').version")";
docker push ghcr.io/stjude/ppfull:$TAG-$HASH;
docker push ghcr.io/stjude/ppfull:latest;
6 changes: 3 additions & 3 deletions .github/workflows/CD-publish-deps-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:

- name: Build image
run: |
cd container/deps
./version.sh -c
cd container
./version.sh deps
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "deps-image" && "${{ github.event_name }}" != "workflow_dispatch" ]]; then
if [[ "$BRANCH" != "publish-image" && "$BRANCH" != "release-chain" && "$BRANCH" != "master" && ${{ github.event_name }} != "workflow_dispatch" ]]; then
echo "skipping build and publishing"
else
./build.sh -m "ghcr.io/stjude/"
Expand Down
4 changes: 2 additions & 2 deletions container/build2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ docker buildx build . \
# Clean up
#############

git restore server/package.json
git restore full/package.json
# git restore server/package.json
# git restore full/package.json
2 changes: 1 addition & 1 deletion container/deps/app-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const serverconfigFile = path.join(__dirname, './serverconfig.json')
if (!fs.existsSync(serverconfigFile)) {
throw `missing serverconfig.json: did you forget to mount?`
}

console.log('test')
const serverconfig = require(serverconfigFile)
if (!serverconfig.genomes) {
serverconfig.genomes = [
Expand Down
36 changes: 36 additions & 0 deletions container/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# call from the container dir
# ./publish.sh [-w]
# -w option to commit changes

MODE="$1"
HASH="$(git rev-parse --short HEAD)"

./version.sh server
if [[ "$MODE" == "-w" ]]; then
./build2.sh -r "ghcr.io/stjude/" server
TAG="$(node -p "require('./server/package.json').version")"
docker push ghcr.io/stjude/ppserver:$TAG-$HASH
docker push ghcr.io/stjude/ppserver:latest
fi

./version.sh full
if [[ "$MODE" == "-w" ]]; then
./build2.sh -r "ghcr.io/stjude/" full
TAG="$(node -p "require('./full/package.json').version")"
docker push ghcr.io/stjude/ppfull:$TAG-$HASH
docker push ghcr.io/stjude/ppfull:latest
fi

if [[ "$MODE" == "-w" ]]; then
echo "committing version changes"
git config --global user.email "[email protected]"
git config --global user.name "PPTeam CI"
git add --all
ROOTPKGVER=$(node -p "require('../package.json').version")
SERVERPKGVER=$(node -p "require('../server/package.json').version")
FRONTPKGVER=$(node -p "require('../front/package.json').version")
git commit -m "image v$ROOTPKGVER server=$SERVERPKGVER front=$FRONTPKGVER"
git push
fi
49 changes: 49 additions & 0 deletions container/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -euxo pipefail

MODE=""
if (( $# == 0 )); then
echo "Missing subdir argument"
echo "Usage: call from within the container dir
./version.sh [subdir=deps|server|full] [-w]
subdir required, any of the container subdirectory that has a dockerfile
-w option to commit changes
"
exit 1
fi

SUBDIR=$1
MODE=""
if (( $# == 2 )); then
MODE="$2"
fi

cd ..
# container image builds will use published packages, so no need to the excluded workspaces here
UPDATED=$(./build/bump.js $MODE -x=rust -x=augen -x=server -x=client -x=front)
echo "UPDATED=[$UPDATED]"
cd container/$SUBDIR

DEPS="dependencies.@sjcrh/proteinpaint-"
if [[ "$(grep containerDeps ./package.json)" != "" ]]; then
DEPS=containerDeps.
fi

ROOTPKGVER=$(node -p "require('../../package.json').version")
echo "setting $SUBDIR package.version='$ROOTPKGVER'"
npm pkg set version=$ROOTPKGVER

SERVERPKGVER=$(node -p "require('../../server/package.json').version")
echo "setting $SUBDIR package.${DEPS}server='$SERVERPKGVER'"
npm pkg set "${DEPS}server"=$SERVERPKGVER

if [[ "$SUBDIR" == "full" ]]; then
FRONTPKGVER=$(node -p "require('../../front/package.json').version")
echo "setting $SUBDIR package.${DEPS}full='$SERVERPKGVER'"
npm pkg set "${DEPS}front"=$FRONTPKGVER
fi

cd ..

0 comments on commit 922e73b

Please sign in to comment.