11name : Self-host Docker Image
22on :
3+ push :
4+ branches :
5+ - main
36 workflow_dispatch :
4- inputs :
5- image_version :
6- description : " Docker image version (e.g. 1.2.3)"
7- required : true
8- type : string
97
108permissions :
119 contents : read
@@ -14,13 +12,27 @@ jobs:
1412 build :
1513 runs-on : ubuntu-latest
1614 environment : self-host
17- env :
18- DOCKER_IMAGE_VERSION : ${{ inputs.image_version }}
1915
2016 steps :
2117 - name : Checkout
2218 uses : actions/checkout@v4
2319
20+ - name : Read version from package.json
21+ id : version
22+ run : |
23+ if ! command -v jq >/dev/null 2>&1; then
24+ echo "jq not found"; exit 1
25+ fi
26+ V=$(jq -r '.version' package.json)
27+ if [ -z "$V" ] || [ "$V" = "null" ]; then
28+ echo "Version not found in package.json"; exit 1
29+ fi
30+ if ! [[ "$V" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
31+ echo "Version $V is not valid semver (expected X.Y.Z)"; exit 1
32+ fi
33+ echo "full=$V" >> "$GITHUB_OUTPUT"
34+
35+
2436 - name : Set up QEMU
2537 uses : docker/setup-qemu-action@v3
2638
@@ -35,10 +47,11 @@ jobs:
3547
3648 - name : Build and push (multi-arch)
3749 run : |
38- echo "Building version: ${DOCKER_IMAGE_VERSION}"
50+ set -euo pipefail
51+ VERSION='${{ steps.version.outputs.full }}'
52+ echo "Building image tag: $VERSION"
3953 docker buildx build \
4054 --platform linux/amd64,linux/arm64 \
41- --build-arg GITHUB_TOKEN=${{ secrets.SPARROW_GITHUB_TOKEN }} \
42- -t ssparrowapi/sparrow-proxy:self-host-${DOCKER_IMAGE_VERSION} \
43- -t ssparrowapi/sparrow-proxy:latest \
55+ -t $DOCKER_IMAGE_NAME:$VERSION \
56+ -t sparrowapi/sparrow-proxy:latest \
4457 --push .
0 commit comments