Skip to content

Commit

Permalink
github actions: don't attempt to push docker image from forks
Browse files Browse the repository at this point in the history
- only push the docker image to the ghcr registry when on the original shaarli/Shaarli fork
- only run trivy docker image scans on the original shaarli/Shaarli fork
- prevents 'Username and password required' errors when committing to forks which do not have the required CI secrets (registry username/password) set
  • Loading branch information
nodiscc committed Dec 5, 2023
1 parent 61a365b commit b7e920b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/docker-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
if: github.repository == 'shaarli/Shaarli'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.repository == 'shaarli/Shaarli'
uses: docker/login-action@v2
with:
registry: ghcr.io
Expand All @@ -34,12 +36,13 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
push: true
push: ${{ github.repository == 'shaarli/Shaarli' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
${{ secrets.DOCKER_IMAGE }}:latest
ghcr.io/${{ secrets.DOCKER_IMAGE }}:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Run trivy scanner on latest docker image
if: github.repository == 'shaarli/Shaarli'
run: make test_trivy_docker TRIVY_EXIT_CODE=0 TRIVY_TARGET_DOCKER_IMAGE=ghcr.io/${{ secrets.DOCKER_IMAGE }}:latest
7 changes: 4 additions & 3 deletions .github/workflows/docker-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
if: github.repository == 'shaarli/Shaarli'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
- name: Login to GitHub Container Registry
if: github.repository == 'shaarli/Shaarli'
uses: docker/login-action@v2
with:
registry: ghcr.io
Expand All @@ -34,7 +35,7 @@ jobs:
id: docker_build
uses: docker/build-push-action@v3
with:
push: true
push: ${{ github.repository == 'shaarli/Shaarli' }}
platforms: linux/amd64,linux/arm/v7
tags: |
${{ secrets.DOCKER_IMAGE }}:${{ env.REF }}
Expand Down

0 comments on commit b7e920b

Please sign in to comment.