fix: Use actions from Docker for publishing image

This commit is contained in:
2025-08-02 21:09:58 +02:00
parent f1930eca14
commit efa3119e6a
+30 -4
View File
@@ -11,6 +11,10 @@ on:
paths: paths:
- 'docker/**' - 'docker/**'
env:
REGISTRY: ghcr.io
IMAGE_NAME: 2martens/docker-nginx
jobs: jobs:
fact-finding: fact-finding:
name: Detect changed environments name: Detect changed environments
@@ -31,6 +35,11 @@ jobs:
matrix: matrix:
env: [ test ] env: [ test ]
environment: ${{ matrix.env }} environment: ${{ matrix.env }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Exit if this environment wasn't changed - name: Exit if this environment wasn't changed
@@ -43,12 +52,29 @@ jobs:
echo "should_deploy=false" >> $GITHUB_OUTPUT echo "should_deploy=false" >> $GITHUB_OUTPUT
fi fi
shell: bash shell: bash
- name: Perform docker login
if: steps.check.outputs.should_deploy == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.check.outputs.should_deploy == 'true'
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ matrix.env }}
- name: Build & push Nginx image to GHCR - name: Build & push Nginx image to GHCR
if: steps.check.outputs.should_deploy == 'true' if: steps.check.outputs.should_deploy == 'true'
run: | uses: docker/build-push-action@v6
docker build -t ghcr.io/2martens/docker-nginx:${{ matrix.env }} docker/${{ matrix.env }}/nginx with:
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u 2martens --password-stdin context: docker/${{ matrix.env }}/nginx
docker push ghcr.io/2martens/docker-nginx:${{ matrix.env }} push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Copy files to remote - name: Copy files to remote
if: steps.check.outputs.should_deploy == 'true' if: steps.check.outputs.should_deploy == 'true'
uses: burnett01/rsync-deployments@7.0.2 uses: burnett01/rsync-deployments@7.0.2