Skip to content

Commit

Permalink
feat: final version of build pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
loboda4450 committed Sep 4, 2024
1 parent 4f5139c commit 59bbb7e
Show file tree
Hide file tree
Showing 9 changed files with 551 additions and 420 deletions.
123 changes: 70 additions & 53 deletions .github/workflows/build-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ name: Build and Push voltaserve/api

on:
workflow_dispatch:
inputs:
branch:
required: false
default: ""
type: string
description: Override code checkout branch (e.g. "feature/branch")
push:
branches:
- main
Expand All @@ -26,57 +20,19 @@ on:
tags:
- 'v*'

jobs:
prepare_env:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.input_branch.outputs.branch }}
tags: ${{ steps.tag.outputs.tags || steps.tags.outputs.tags }}
steps:
- name: Prepare input branch
id: input_branch
if: ${{ github.event.inputs.branch != '' }}
run: echo "branch=refs/heads/${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
env:
IMAGE: voltaserve/api

- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ steps.input_branch.outputs.branch || github.ref }}

- name: Create tag list matching semver from executing tag
id: tag
if: ${{ github.ref_type == 'tag' }}
run: |
name="voltaserve/api"
version="${{ github.ref_name }}"
version="${version#v}"
IFS='.' read -r -a parts <<< "$version"
TAGS="$name:$version"
for ((i=${#parts[@]}-1; i>0; i--)); do
tag=$(IFS='.'; echo "${parts[*]:0:$i}")
TAGS+=",$name:$tag"
done
TAGS+=",$name:latest"
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Set the tag on workflow dispatch
id: tags
if: ${{ github.ref_type != 'tag' }}
run: echo "tags=voltaserve/api:$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

build_and_push:
jobs:
build:
runs-on: ubuntu-latest
needs: prepare_env
strategy:
fail-fast: false
matrix:
platform: [ "arm64", "amd64" ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_env.outputs.branch || github.ref }}

- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -92,10 +48,71 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=ref,event=branch,enable=${{ github.ref_type != 'tag' }}
type=ref,event=tag
type=sha,enable=${{ github.ref_type != 'tag' }}
type=semver,pattern={{version}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}},enable=${{ github.ref_type == 'tag' }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
id: build
uses: docker/build-push-action@v6
with:
context: ./api
push: true
tags: ${{ needs.prepare_env.outputs.tags }}
platforms: ${{ matrix.platform }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE }}@sha256:%s ' *)
26 changes: 13 additions & 13 deletions .github/workflows/build-console.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=ref,event=branch,enable=${{ github.ref_type != 'tag' }}
type=ref,event=tag
type=sha,enable=${{ github.ref_type != 'tag' }}
type=semver,pattern={{version}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}},enable=${{ github.ref_type == 'tag' }}
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
with:
Expand All @@ -61,6 +48,19 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=ref,event=branch,enable=${{ github.ref_type != 'tag' }}
type=ref,event=tag
type=sha,enable=${{ github.ref_type != 'tag' }}
type=semver,pattern={{version}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}},enable=${{ github.ref_type == 'tag' }}
- name: Build and Push Docker Image
id: build
uses: docker/build-push-action@v6
Expand Down
120 changes: 68 additions & 52 deletions .github/workflows/build-conversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ name: Build and Push voltaserve/conversion

on:
workflow_dispatch:
inputs:
branch:
required: false
default: ""
type: string
description: Override code checkout branch (e.g. "feature/branch")
push:
branches:
- main
Expand All @@ -26,57 +20,19 @@ on:
tags:
- 'v*'

jobs:
prepare_env:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.input_branch.outputs.branch }}
tags: ${{ steps.tag.outputs.tags || steps.tags.outputs.tags }}
steps:
- name: Prepare input branch
id: input_branch
if: ${{ github.event.inputs.branch != '' }}
run: echo "branch=refs/heads/${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
env:
IMAGE: voltaserve/conversion

- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ steps.input_branch.outputs.branch || github.ref }}

- name: Create tag list matching semver from executing tag
id: tag
if: ${{ github.ref_type == 'tag' }}
run: |
name="voltaserve/conversion"
version="${{ github.ref_name }}"
version="${version#v}"
IFS='.' read -r -a parts <<< "$version"
TAGS="$name:$version"
for ((i=${#parts[@]}-1; i>0; i--)); do
tag=$(IFS='.'; echo "${parts[*]:0:$i}")
TAGS+=",$name:$tag"
done
TAGS+=",$name:latest"
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Set the tag on workflow dispatch
id: tags
if: ${{ github.ref_type != 'tag' }}
run: echo "tags=voltaserve/conversion:$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

build_and_push:
jobs:
build:
runs-on: ubuntu-latest
needs: prepare_env
strategy:
fail-fast: false
matrix:
platform: [ "arm64", "amd64" ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_env.outputs.branch || github.ref }}

- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -92,10 +48,70 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=ref,event=branch,enable=${{ github.ref_type != 'tag' }}
type=ref,event=tag
type=sha,enable=${{ github.ref_type != 'tag' }}
type=semver,pattern={{version}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref_type == 'tag' }}
type=semver,pattern={{major}},enable=${{ github.ref_type == 'tag' }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./conversion
push: true
tags: ${{ needs.prepare_env.outputs.tags }}
platforms: ${{ matrix.platform }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE }}@sha256:%s ' *)
Loading

0 comments on commit 59bbb7e

Please sign in to comment.