Skip to content

Commit

Permalink
Updated build-push workflow to push to ghcr and to use buildx to buil…
Browse files Browse the repository at this point in the history
…d an amd64 and arm64 image
  • Loading branch information
spectrapulse authored Sep 25, 2023
1 parent 489ae1d commit 9453732
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
name: Docker Image CI
name: Build and push to registry

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
packages: write
contents: read

jobs:
build-and-push:
name: Build Docker image and push to repository
name: Build Docker image and push to registry
runs-on: ubuntu-latest

steps:
Expand All @@ -17,17 +24,36 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to repository
- name: Login to GitHub's Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate image metadata
id: spoticord-database # used in next step
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: ghcr.io/${{ github.event.repository.name }}
# Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Build image and push to registry
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
tags: |
${{ secrets.REGISTRY_URL }}/spoticord/database:latest
push: ${{ github.ref == 'refs/heads/main' }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.spoticord-database.outputs.tags }}
labels: ${{ steps.spoticord-database.outputs.labels }}
# Some basic caching of the layers...
cache-from: ghcr.io/${{ github.event.repository.name }}:latest-cache
cache-to: ghcr.io/${{ github.event.repository.name }}:latest-cache

0 comments on commit 9453732

Please sign in to comment.