Skip to content

Commit 0b70fd4

Browse files
Thomas TupperThomas Tupper
authored andcommitted
ci: switch image publishing target to Docker Hub with graceful secret gating
1 parent 3fa7114 commit 0b70fd4

1 file changed

Lines changed: 38 additions & 7 deletions

File tree

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
11
name: publish-image
2+
23
on:
34
push:
45
branches: [main]
56
workflow_dispatch:
7+
68
permissions:
79
contents: read
8-
packages: write
10+
911
jobs:
1012
build-and-push:
1113
runs-on: ubuntu-latest
1214
steps:
1315
- uses: actions/checkout@v4
14-
- name: Log in to GHCR
16+
17+
- name: Set image metadata
18+
id: meta
19+
run: |
20+
echo "image=docker.io/foxlightfoundation/foxmemory-deploy" >> "$GITHUB_OUTPUT"
21+
echo "sha_tag=${GITHUB_SHA::12}" >> "$GITHUB_OUTPUT"
22+
23+
- name: Check Docker Hub secrets
24+
id: secrets
25+
env:
26+
DH_USER: ${{ secrets.foxlightfoundation }}
27+
DH_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
28+
run: |
29+
if [ -n "$DH_USER" ] && [ -n "$DH_TOKEN" ]; then
30+
echo "ready=true" >> "$GITHUB_OUTPUT"
31+
else
32+
echo "ready=false" >> "$GITHUB_OUTPUT"
33+
fi
34+
35+
- name: Log in to Docker Hub
36+
if: steps.secrets.outputs.ready == 'true'
1537
uses: docker/login-action@v3
1638
with:
17-
registry: ghcr.io
18-
username: ${{ github.actor }}
19-
password: ${{ secrets.GITHUB_TOKEN }}
20-
- name: Build and push
39+
username: ${{ secrets.foxlightfoundation }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Build and push (Docker Hub)
43+
if: steps.secrets.outputs.ready == 'true'
2144
uses: docker/build-push-action@v6
2245
with:
2346
context: .
2447
push: true
25-
tags: ghcr.io/foxlight-foundation/foxmemory-deploy:latest
48+
tags: |
49+
${{ steps.meta.outputs.image }}:latest
50+
${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.sha_tag }}
51+
52+
- name: Skip publish (missing secrets)
53+
if: steps.secrets.outputs.ready != 'true'
54+
run: |
55+
echo "Docker Hub secrets are not configured."
56+
echo "Set foxlightfoundation and DOCKERHUB_TOKEN in repo secrets to enable publish."

0 commit comments

Comments
 (0)