|
1 | 1 | name: publish-image |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | branches: [main] |
5 | 6 | workflow_dispatch: |
| 7 | + |
6 | 8 | permissions: |
7 | 9 | contents: read |
8 | | - packages: write |
| 10 | + |
9 | 11 | jobs: |
10 | 12 | build-and-push: |
11 | 13 | runs-on: ubuntu-latest |
12 | 14 | steps: |
13 | 15 | - 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' |
15 | 37 | uses: docker/login-action@v3 |
16 | 38 | 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' |
21 | 44 | uses: docker/build-push-action@v6 |
22 | 45 | with: |
23 | 46 | context: . |
24 | 47 | 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