Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Configure Renovate - autoclosed #52

Configure Renovate - autoclosed

Configure Renovate - autoclosed #52

Workflow file for this run

name: Build & Upload Docker Image
on:
pull_request:
workflow_dispatch:
release:
types: [published]
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-matrix.outputs.version }}
build_matrix: ${{ steps.set-matrix.outputs.build_matrix }}
name: ${{ steps.set-matrix.outputs.name }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Matrix-Jobs
id: set-matrix
env:
VERSION: ${{ github.ref_name }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
echo "Run triggered by: ${GITHUB_EVENT_NAME}"
if grep -c -E '^v[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$' <<< ${VERSION}; then
VERSION=$(sed 's/^.\{1\}//g' <<< ${VERSION})
else
VERSION='0.0.0'
fi
echo "version=$(echo ${VERSION})" >> $GITHUB_OUTPUT
echo "name=$(echo ${GITHUB_REPOSITORY} | cut -f2 -d '/')" >> $GITHUB_OUTPUT
echo "build_matrix=$(cat .github/platforms.json)" >> $GITHUB_OUTPUT
Build:
runs-on: ubuntu-latest
needs: Setup
strategy:
fail-fast: false
matrix:
${{ insert }}: ${{ fromJson(needs.Setup.outputs.build_matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Perquisites
run: |
curl https://omnitruck.chef.io/install.sh | sudo bash -s -- -P inspec
inspec --chef-license=accept
- name: Build
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
NAME: ${{ needs.Setup.outputs.name }}
run: |
ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}')
echo ""
echo "============================================================="
echo "Building: ${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}"
echo "============================================================="
echo ""
docker buildx build \
--tag "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}" \
--platform ${PLATFORM} \
--load \
-f ./Dockerfile .
- name: Test
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
NAME: ${{ needs.Setup.outputs.name }}
run: |
set -a
ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}')
echo ""
echo "============================================================="
echo "Testing: ${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}"
echo "============================================================="
echo ""
exec ./test/test.sh
echo ""
- name: Login to Docker Hub
if: github.event_name == 'release'
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }}
- name: Push Images
if: github.event_name == 'release'
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
NAME: ${{ needs.Setup.outputs.name }}
run: |
ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}')
echo ""
echo "============================================================="
echo "Pushing: ${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}"
echo "============================================================="
echo ""
docker tag "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}" "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}"
docker tag "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}" "${DOCKER_USER}/${NAME}:${ARCH}"
docker push "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}"
docker push "${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}"
docker push "${DOCKER_USER}/${NAME}:${ARCH}"
Shared-Manifest:
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs:
- Build
- Setup
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }}
- name: Create and push shared manifest
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME }}
BUILD_NR: ${{ github.run_number }}
VERSION: ${{ needs.Setup.outputs.version }}
NAME: ${{ needs.Setup.outputs.name }}
run: |
echo ""
echo "============================================================="
echo "Pushing shared manifest: ${DOCKER_USER}/${NAME}:${VERSION}"
echo "============================================================="
echo ""
echo "#!/bin/bash" > push-shared-tags.sh
echo -n "docker manifest create ${DOCKER_USER}/${NAME}:${VERSION}" >> push-shared-tags.sh
while read -r PLATFORM; do
ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}')
echo -n " ${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}" >> push-shared-tags.sh
done <<< "$(cat .github/platforms.json | jq -r '.platforms | join("\n")')"
echo "" >> push-shared-tags.sh
echo -n "docker manifest create ${DOCKER_USER}/${NAME}:latest" >> push-shared-tags.sh
while read -r PLATFORM; do
ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}')
echo -n " ${DOCKER_USER}/${NAME}:${VERSION}-${ARCH}-${BUILD_NR}" >> push-shared-tags.sh
done <<< "$(cat .github/platforms.json | jq -r '.platforms | join("\n")')"
echo "" >> push-shared-tags.sh
echo "docker manifest push ${DOCKER_USER}/${NAME}:${VERSION}" >> push-shared-tags.sh
echo "docker manifest push ${DOCKER_USER}/${NAME}:latest" >> push-shared-tags.sh
cat push-shared-tags.sh
chmod +x ./push-shared-tags.sh
./push-shared-tags.sh
Check-Build:
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- Build
- Shared-Manifest
steps:
- run: |
result="${{ needs.Build.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi