03 - Powerpipe: Container Build and Release #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "03 - Powerpipe: Container Build and Release" | |
# Triggers the workflow manually with an input for release version. | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Powerpipe version (with 'v')" | |
required: true | |
env: | |
POWERPIPE_VERSION: ${{ github.event.inputs.version }} | |
IMAGE_DESCRIPTION: "Powerpipe container image ${{ github.event.inputs.version }}" | |
# Defines the build and release job. | |
jobs: | |
check_pre_release: | |
name: Check if pre-release | |
runs-on: ubuntu-latest | |
outputs: | |
is_pre_release: ${{ steps.pre_release_check.outputs.is_pre_release }} | |
steps: | |
- name: Check if pre-release | |
id: pre_release_check | |
run: | | |
if [[ "${{ github.event.inputs.version }}" =~ -alpha|-beta|-rc|-dev ]]; then | |
echo "is_pre_release=true" >> $GITHUB_OUTPUT | |
echo "This is a pre-release. The 'latest' tag will not be updated." | |
else | |
echo "is_pre_release=false" >> $GITHUB_OUTPUT | |
echo "This is a final release. The 'latest' tag will be set." | |
fi | |
build_and_release: | |
name: Build and Release | |
needs: check_pre_release | |
# The type of runner that the job will run on. | |
runs-on: ubuntu-latest | |
# check if it's a final release | |
if: needs.check_pre_release.outputs.is_pre_release == 'false' | |
steps: | |
# Checks out the Powerpipe repository code. | |
- name: Checkout Powerpipe repository | |
uses: actions/checkout@v4 | |
with: | |
path: powerpipe # Directory path under $GITHUB_WORKSPACE to place the repository. | |
# Sets up QEMU for multi-architecture builds, allowing builds for architectures like ARM and AMD64. | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# Sets up Docker Buildx for extended Docker build capabilities, including building multi-arch images. | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Logs in to the GitHub Container Registry to allow pushing and pulling images. | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GH_ACCESS_TOKEN }} | |
# Remove the 'v' from the version to get the docker tag | |
- name: Clean Version for Tag | |
id: generate_docker_tag | |
run: | | |
echo "docker_tag=${POWERPIPE_VERSION#"v"}" >> $GITHUB_OUTPUT | |
# Builds the Docker image and pushes it to the GitHub Container Registry. | |
- name: Build and Push to Container Registry | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
# The Docker build context. | |
context: powerpipe/docker/ | |
push: true | |
platforms: linux/amd64, linux/arm64 | |
build-args: | | |
TARGETVERSION=${{ github.event.inputs.version }} | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/powerpipe:${{ steps.generate_docker_tag.outputs.docker_tag }} | |
ghcr.io/${{ github.repository_owner }}/powerpipe:latest | |
outputs: type=image,name=powerpipe,annotation-index.org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} | |
# Outputs the image digest after the build. | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
build_and_release_pre_release: | |
name: Build and Release (For Pre-releases) | |
needs: check_pre_release | |
# The type of runner that the job will run on. | |
runs-on: ubuntu-latest | |
# check if it's a pre-release | |
if: needs.check_pre_release.outputs.is_pre_release == 'true' | |
steps: | |
# Checks out the Powerpipe repository code. | |
- name: Checkout Powerpipe repository | |
uses: actions/checkout@v4 | |
with: | |
path: powerpipe # Directory path under $GITHUB_WORKSPACE to place the repository. | |
# Sets up QEMU for multi-architecture builds, allowing builds for architectures like ARM and AMD64. | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# Sets up Docker Buildx for extended Docker build capabilities, including building multi-arch images. | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Logs in to the GitHub Container Registry to allow pushing and pulling images. | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GH_ACCESS_TOKEN }} | |
# Remove the 'v' from the version to get the docker tag | |
- name: Clean Version for Tag | |
id: generate_docker_tag | |
run: | | |
echo "docker_tag=${POWERPIPE_VERSION#"v"}" >> $GITHUB_OUTPUT | |
# Builds the Docker image and pushes it to the GitHub Container Registry. | |
- name: Build and Push to Container Registry | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
# The Docker build context. | |
context: powerpipe/docker/ | |
push: true | |
platforms: linux/amd64, linux/arm64 | |
build-args: | | |
TARGETVERSION=${{ github.event.inputs.version }} | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/powerpipe:${{ steps.generate_docker_tag.outputs.docker_tag }} | |
outputs: type=image,name=powerpipe,annotation-index.org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} | |
# Outputs the image digest after the build. | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} |