Add build & release pipeline for versioned images (#107)
* build: add release & build pipeline * build: add variable for project type * build: [TO_REVERT] configure for pushing images to ghcr.io * build: target both x86 and arm platforms for Docker images * build: fix multi-platform builds * Revert "build: [TO_REVERT] configure for pushing images to ghcr.io" This reverts commit 070162aa8c74c519612f30cb6b3038bc98fd86ad. * build: fix image name * build: fix permission issue with release please by only running it on commits on the main branch
This commit is contained in:
parent
f53f2535d0
commit
5d213de8b5
76
.github/workflows/build-images.yml
vendored
76
.github/workflows/build-images.yml
vendored
@ -1,76 +0,0 @@
|
||||
name: Build images
|
||||
|
||||
on:
|
||||
# schedule:
|
||||
# - cron: '0 0 * * *' # Midnight every day
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
build_type:
|
||||
description: Build Type
|
||||
required: true
|
||||
default: edge
|
||||
type: choice
|
||||
options:
|
||||
- edge
|
||||
- dev
|
||||
- stable
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build image
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: amd64,arm64,arm
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
install: true
|
||||
|
||||
- name: Create the tag
|
||||
id: image_tag
|
||||
run: |
|
||||
choice="${{ inputs.build_type }}"
|
||||
out=""
|
||||
|
||||
# if the workflow is running on a branch, let the tag be the branch name
|
||||
if [[ $GITHUB_REF == "refs/heads/"* ]] ; then
|
||||
echo "TAG=${GITHUB_REF#'refs/heads/'}" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
tag="${GITHUB_REF#'refs/tags/'}"
|
||||
case $choice in
|
||||
edge)
|
||||
out="TAG=$tag-edge"
|
||||
;;
|
||||
dev)
|
||||
out="TAG=$tag-dev"
|
||||
;;
|
||||
stable)
|
||||
out="TAG=$tag-stable,${{ vars.DOCKERHUB_TAG }}:latest"
|
||||
;;
|
||||
esac
|
||||
echo $out >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and publish image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ vars.DOCKERHUB_TAG }}:${{ steps.image_tag.outputs.TAG }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
77
.github/workflows/build-release.yaml
vendored
Normal file
77
.github/workflows/build-release.yaml
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
name: Build & Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
packages: write
|
||||
env:
|
||||
# login to docker hub with provided secrets
|
||||
REGISTRY: docker.io
|
||||
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
IMAGE_NAME: bellamy/wallos
|
||||
# For release-please, see available types at https://github.com/google-github-actions/release-please-action/tree/v4/?tab=readme-ov-file#release-types-supported
|
||||
PROJECT_TYPE: simple
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- id: rp
|
||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||
uses: google-github-actions/release-please-action@v4
|
||||
with:
|
||||
release-type: ${{ env.PROJECT_TYPE }}
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ env.REGISTRY_USERNAME }}
|
||||
password: ${{ env.REGISTRY_PASSWORD }}
|
||||
- name: Prepare tags for Docker meta
|
||||
id: tags
|
||||
env:
|
||||
# When release please is skipped, these values will be empty
|
||||
is_release: ${{ steps.rp.outputs.release_created }}
|
||||
version: v${{ steps.rp.outputs.major }}.${{ steps.rp.outputs.minor }}.${{ steps.rp.outputs.patch }}
|
||||
run: |
|
||||
tags=""
|
||||
if [[ "$is_release" = 'true' ]]; then
|
||||
tags="type=semver,pattern={{version}},value=$version
|
||||
type=semver,pattern={{major}},value=$version
|
||||
type=semver,pattern={{major}}.{{minor}},value=$version"
|
||||
else
|
||||
tags="type=ref,event=branch
|
||||
type=ref,event=pr"
|
||||
fi
|
||||
{
|
||||
echo 'tags<<EOF'
|
||||
echo "$tags"
|
||||
echo EOF
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: ${{ steps.tags.outputs.tags }}
|
||||
# necessary for multi-platform images
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
# necessary for multi-platform images
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
Loading…
Reference in New Issue
Block a user