Skip to content

Commit

Permalink
Refactor GitHub workflow (#11)
Browse files Browse the repository at this point in the history
Use a different way to build
  • Loading branch information
felixschndr committed Oct 30, 2024
1 parent 6a856ed commit e4f83cf
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
name: Deploy Images to GitHub Container Registry

on: push
on:
push:
workflow_dispatch:

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
PLATFORMS: linux/amd64,linux/arm64

jobs:
push-store-image:
build-and-push-image:
runs-on: ubuntu-latest

steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@main

- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.CONTAINER_REGISTRY_TOKEN}}
username: ${{ github.actor }}
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}

- name: "Build Image and Push to Container Registry"
run: |
docker build . --tag ghcr.io/${{github.repository}}:${{github.ref_name}}
docker push ghcr.io/${{github.repository}}:${{github.ref_name}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}

- name: "Build Image as latest and Push to Container Registry"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
platforms: ${{ env.PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image as latest
if: github.ref == 'refs/heads/main'
run: |
docker build . --tag ghcr.io/${{github.repository}}:latest
docker push ghcr.io/${{github.repository}}:latest
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
platforms: ${{ env.PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }},${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit e4f83cf

Please sign in to comment.