Skip to content

Commit 199c74c

Browse files
ci: introduce self-host docker publish workflow (auto tag from package.json) []
1 parent a89e8d7 commit 199c74c

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed
Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
name: Self-host Docker Image
22
on:
3+
push:
4+
branches:
5+
- main
36
workflow_dispatch:
4-
inputs:
5-
branch:
6-
description: "Git branch to build"
7-
required: true
8-
default: main
9-
type: string
10-
image_version:
11-
description: "Docker image version (e.g. 1.2.3)"
12-
required: true
13-
type: string
147

158
permissions:
169
contents: read
@@ -19,16 +12,26 @@ jobs:
1912
build:
2013
runs-on: ubuntu-latest
2114
environment: self-host
22-
env:
23-
DOCKER_IMAGE_VERSION: ${{ inputs.image_version }}
24-
BUILD_BRANCH: ${{ inputs.branch }}
2515

2616
steps:
2717
- name: Checkout
2818
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ env.BUILD_BRANCH }}
31-
fetch-depth: 0
19+
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+
3235

3336
- name: Set up QEMU
3437
uses: docker/setup-qemu-action@v3
@@ -44,9 +47,11 @@ jobs:
4447

4548
- name: Build and push (multi-arch)
4649
run: |
47-
echo "Building version: ${DOCKER_IMAGE_VERSION}"
50+
set -euo pipefail
51+
VERSION='${{ steps.version.outputs.full }}'
52+
echo "Building image tag: $VERSION"
4853
docker buildx build \
4954
--platform linux/amd64,linux/arm64 \
50-
-t sparrowapi/sparrow-proxy:${DOCKER_IMAGE_VERSION} \
55+
-t $DOCKER_IMAGE_NAME:$VERSION \
5156
-t sparrowapi/sparrow-proxy:latest \
5257
--push .

0 commit comments

Comments
 (0)