Skip to content

Commit

Permalink
Split workflow into CI and Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
outlyer-net committed Apr 20, 2024
1 parent 45c690b commit 57ebf45
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# Based on video "GitHub Packages. Containers in a GitHub repo?"" <https://www.youtube.com/watch?v=gqseP_wTZsk>
# TODO: DockerHub integration, see e.g. https://github.com/docker/metadata-action

# Builds for the current architecture on each push

name: Build on push

on:
push:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- name: Login to container registry
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
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# FIXME: :latest isn't added by default althought it should??? https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag
# adding a raw tag as a workaround
tags: |
type=raw,value=latest
type=sha
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=tag
type=ref,event=branch,suffix=-branch
# Standard build action:
#- name: Build and push Docker image
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# Non-standard using the makefile:
- name: Build
# IMAGE_NAME must match the github repository name
run: make REGISTRY=${{ env.REGISTRY }} IMAGE_NAME=${{ env.IMAGE_NAME }}
13 changes: 5 additions & 8 deletions .github/workflows/deploy-to-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# Based on video "GitHub Packages. Containers in a GitHub repo?"" <https://www.youtube.com/watch?v=gqseP_wTZsk>
# TODO: DockerHub integration, see e.g. https://github.com/docker/metadata-action

# Deploy to GHCR a multi-arch image when tagged

name: Deploy image to GHCR

# Runs on all pushes, all branches included
# on: [push]
on:
push:
# Note these are supposed to be OR'ed, i.e. when branch is main or a tag like v* is pushed
branches:
- 'master'
# tags:
# # This doesn't work: - 'v?[0-9]+.[0-9]+.[0-9]+([0-9]+)?'
# - 'v*.*'
tags:
# This doesn't work: - 'v?[0-9]+.[0-9]+.[0-9]+([0-9]+)?'
- '*.*'

env:
REGISTRY: ghcr.io
Expand Down

0 comments on commit 57ebf45

Please sign in to comment.