Skip to content

Commit 01a7c78

Browse files
committed
Enhance Docker deployment workflow
- Added a step to resolve the Docker image version, prioritizing the bumped version and falling back to the version specified in `ha-addon/config.yaml`. - Updated image tagging in the build and push steps to use the resolved version. - Removed obsolete metadata extraction steps for tags and labels, simplifying the workflow.
1 parent 8846d7a commit 01a7c78

1 file changed

Lines changed: 33 additions & 36 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ jobs:
8282
- name: Set Docker image name (lowercase for GHCR)
8383
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
8484

85+
- name: Resolve image version
86+
id: ver
87+
# Prefer the bumped version (set on push to main); fall back to ha-addon/config.yaml on tag pushes.
88+
run: |
89+
v="${{ needs.bump-version.outputs.version }}"
90+
if [ -z "$v" ]; then
91+
v=$(awk -F'"' '/^version:/ {print $2; exit}' ha-addon/config.yaml)
92+
fi
93+
echo "version=$v" >> "$GITHUB_OUTPUT"
94+
echo "Resolved version: $v"
95+
8596
- name: Log in to the Container registry
8697
uses: docker/login-action@v3
8798
with:
@@ -95,27 +106,18 @@ jobs:
95106
- name: Set up Docker Buildx
96107
uses: docker/setup-buildx-action@v3
97108

98-
- name: Extract metadata (tags, labels) for Docker
99-
id: meta
100-
uses: docker/metadata-action@v5
101-
with:
102-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app
103-
tags: |
104-
type=ref,event=branch
105-
type=semver,pattern={{version}}
106-
type=semver,pattern={{major}}.{{minor}}
107-
108109
- name: Build and push App image
109110
uses: docker/build-push-action@v5
110111
with:
111112
context: .
112113
file: ./Dockerfile.app
113114
push: true
114115
platforms: linux/amd64,linux/arm64,linux/arm/v7
115-
tags: ${{ steps.meta.outputs.tags }}
116-
labels: ${{ steps.meta.outputs.labels }}
116+
tags: |
117+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.ver.outputs.version }}
118+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:main
117119
build-args: |
118-
VITE_APP_BUILD_VERSION=${{ github.ref_name }}@${{ github.sha }}
120+
VITE_APP_BUILD_VERSION=v${{ steps.ver.outputs.version }}@${{ github.sha }}
119121
VITE_INSTALL_KIND=docker
120122
cache-from: type=gha
121123
cache-to: type=gha,mode=max
@@ -151,6 +153,18 @@ jobs:
151153
- name: Set Docker image name (lowercase for GHCR)
152154
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
153155

156+
- name: Resolve image version
157+
id: ver
158+
# Use bumped version from bump-version job; fall back to the version line in ha-addon/config.yaml.
159+
# HA Supervisor pulls images at exactly this tag (matching ha-addon/config.yaml `version`).
160+
run: |
161+
v="${{ needs.bump-version.outputs.version }}"
162+
if [ -z "$v" ]; then
163+
v=$(awk -F'"' '/^version:/ {print $2; exit}' ha-addon/config.yaml)
164+
fi
165+
echo "version=$v" >> "$GITHUB_OUTPUT"
166+
echo "Resolved version: $v"
167+
154168
- name: Log in to the Container registry
155169
uses: docker/login-action@v3
156170
with:
@@ -164,37 +178,20 @@ jobs:
164178
- name: Set up Docker Buildx
165179
uses: docker/setup-buildx-action@v3
166180

167-
- name: Extract metadata (tags, labels)
168-
id: meta
169-
uses: docker/metadata-action@v5
170-
with:
171-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-addon-${{ matrix.arch }}
172-
tags: |
173-
type=ref,event=branch
174-
type=semver,pattern={{version}}
175-
176-
- name: Determine App Tag
177-
id: app_tag
178-
run: |
179-
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
180-
echo "tag=main" >> $GITHUB_OUTPUT
181-
else
182-
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
183-
fi
184-
185181
- name: Build and push Add-on image
186182
uses: docker/build-push-action@v5
187183
with:
188184
context: .
189185
file: ./Dockerfile
190186
push: true
191187
platforms: ${{ matrix.platform }}
192-
tags: ${{ steps.meta.outputs.tags }}
193-
labels: ${{ steps.meta.outputs.labels }}
188+
tags: |
189+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-addon-${{ matrix.arch }}:${{ steps.ver.outputs.version }}
190+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-addon-${{ matrix.arch }}:main
194191
build-args: |
195-
BUILD_FROM=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.app_tag.outputs.tag }}
196-
BUILD_VERSION=${{ github.ref_name }}
197-
VITE_APP_BUILD_VERSION=${{ github.ref_name }}@${{ github.sha }}
192+
BUILD_FROM=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app:${{ steps.ver.outputs.version }}
193+
BUILD_VERSION=${{ steps.ver.outputs.version }}
194+
VITE_APP_BUILD_VERSION=v${{ steps.ver.outputs.version }}@${{ github.sha }}
198195
VITE_INSTALL_KIND=docker
199196
cache-from: type=gha
200197
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)