Skip to content

Commit

Permalink
fix: better docker publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tedostrem committed Nov 6, 2024
1 parent 1d97664 commit 6d267bf
Showing 1 changed file with 24 additions and 46 deletions.
70 changes: 24 additions & 46 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,63 @@
---
name: Docker Build and Publish
name: Docker

"on":
on:
push:
branches: ["main"]
tags: ['v*.*.*']
branches: [ "main" ]
tags: [ 'v*.*.*' ]
pull_request:
branches: ["main"]
branches: [ "main" ]

env:
REGISTRY: docker.io
RUSTYGATE_IMAGE: 3loc/rustygate
TESTS_IMAGE: 3loc/rustygate-tests
PLATFORMS: linux/amd64,linux/arm64
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

- name: Log into Docker Hub
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: tedostrem
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata for RustyGate
id: meta-rustygate
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.RUSTYGATE_IMAGE }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Extract Docker metadata for Tests
id: meta-tests
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.TESTS_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push RustyGate image
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-rustygate.outputs.tags }}
labels: ${{ steps.meta-rustygate.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
type=sha,format=long
- name: Build and push Tests image
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
file: tests/python/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-tests.outputs.tags }}
labels: ${{ steps.meta-tests.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false # Disable SLSA provenance to avoid issues with some registries

0 comments on commit 6d267bf

Please sign in to comment.