Skip to content

Commit 793d823

Browse files
committed
CI: robust registry selection and ensure package-lock.json before build; fix build-push inputs
1 parent fd0644a commit 793d823

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

.github/workflows/docker-build.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,44 @@ jobs:
2828
if [ -z "${{ secrets.ACR_USERNAME }}" ]; then echo "ERROR: secrets.ACR_USERNAME is not set"; exit 1; fi
2929
if [ -z "${{ secrets.ACR_PASSWORD }}" ]; then echo "ERROR: secrets.ACR_PASSWORD is not set"; exit 1; fi
3030
31+
- name: Determine registry to use
32+
id: registry
33+
run: |
34+
# Prefer explicit secret ACR_LOGIN_SERVER when present, otherwise use env.REGISTRY
35+
if [ -n "${{ secrets.ACR_LOGIN_SERVER }}" ]; then
36+
echo "registry=${{ secrets.ACR_LOGIN_SERVER }}" >> $GITHUB_OUTPUT
37+
else
38+
echo "registry=${{ env.REGISTRY }}" >> $GITHUB_OUTPUT
39+
fi
40+
3141
- name: Set up Docker Buildx
3242
uses: docker/setup-buildx-action@v3
3343

3444
- name: Log in to Azure Container Registry
3545
uses: docker/login-action@v3
3646
with:
37-
registry: ${{ env.REGISTRY }}
47+
registry: ${{ steps.registry.outputs.registry }}
3848
username: ${{ secrets.ACR_USERNAME }}
3949
password: ${{ secrets.ACR_PASSWORD }}
4050

4151
- name: Extract metadata
4252
id: meta
4353
uses: docker/metadata-action@v5
4454
with:
45-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
55+
images: ${{ steps.registry.outputs.registry }}/${{ env.IMAGE_NAME }}
4656
tags: |
4757
type=ref,event=branch
4858
type=ref,event=pr
4959
type=sha,prefix={{branch}}-
5060
type=raw,value=latest,enable={{is_default_branch}}
5161
52-
- name: Build and push Docker image
53-
uses: docker/build-push-action@v5
54-
# Ensure package-lock.json exists to avoid BuildKit checksum errors when restoring cache
55-
# (some previous caches may reference package-lock.json; creating a harmless file prevents failures)
56-
env:
57-
GITHUB_WORKSPACE: ${{ github.workspace }}
5862
- name: Ensure package-lock.json exists
5963
run: |
6064
if [ ! -f package-lock.json ]; then echo '{}' > package-lock.json; fi
6165
66+
- name: Build and push Docker image
67+
id: build
68+
uses: docker/build-push-action@v5
6269
with:
6370
context: .
6471
file: ./Dockerfile

0 commit comments

Comments
 (0)