1
0
mirror of https://github.com/gilbN/theme.park.git synced 2024-11-09 12:42:40 +01:00
theme.park/.github/workflows/docker-build.yml

149 lines
5.9 KiB
YAML
Raw Normal View History

2022-03-20 17:16:25 +01:00
name: docker build
on:
release:
2022-03-20 18:20:11 +01:00
types:
2022-03-22 10:05:36 +01:00
- released
2022-03-23 20:48:47 +01:00
workflow_dispatch:
2022-03-23 21:23:58 +01:00
inputs:
branch:
description: 'Select branch'
required: true
type: choice
options:
2022-04-02 15:15:18 +02:00
- master
- develop
2022-03-31 20:54:30 +02:00
- testing
2022-03-23 21:46:48 +01:00
tag:
description: 'Add a tag'
2022-03-22 10:05:36 +01:00
push:
branches:
2022-04-02 15:15:18 +02:00
- develop
2022-03-31 20:54:30 +02:00
- testing
2022-04-03 15:31:09 +02:00
paths-ignore:
- '.github/**'
2022-03-20 17:16:25 +01:00
jobs:
2022-04-02 15:15:18 +02:00
build-and-push-it-to-the-limit:
2022-03-20 17:16:25 +01:00
runs-on: ubuntu-latest
2022-04-02 19:07:32 +02:00
strategy:
matrix:
2022-04-03 12:48:26 +02:00
architecture: [linux-arm-v7,linux-arm64,linux-amd64]
2022-03-20 17:16:25 +01:00
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
2022-04-02 19:07:32 +02:00
- name: Prepare
id: prep
run: |
ARCHITECTURE=${{ matrix.architecture }}
2022-04-03 12:48:26 +02:00
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
2022-04-03 16:15:28 +02:00
echo ::set-output name=title::${GITHUB_REPOSITORY,,}:${{ github.ref_name }}
2022-04-03 12:48:26 +02:00
echo ::set-output name=revision::${GITHUB_SHA}
2022-04-03 16:15:28 +02:00
echo ::set-output name=source::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY,,}/tree/${{ github.ref_name }}
2022-04-03 12:48:26 +02:00
echo ::set-output name=vendor::${{ github.repository_owner }}
2022-04-03 12:53:40 +02:00
echo ::set-output name=url::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY,,}/blob/master/README.md
2022-04-02 19:07:32 +02:00
echo ::set-output name=VERSION::${{ github.event.release.tag_name }}
2022-04-02 20:29:25 +02:00
echo ::set-output name=platform::${ARCHITECTURE//-/\/}
2022-04-03 16:15:28 +02:00
echo ::set-output name=cache::${GITHUB_REPOSITORY,,}:${{ github.ref_name }}-cache-${{ matrix.architecture }}
echo ::set-output name=tag::${GITHUB_REPOSITORY,,}:${{ github.ref_name }}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}-${{ matrix.architecture }}
2022-04-03 16:54:26 +02:00
echo ::set-output name=release::${{ github.event.release.target_commitish }}
2022-04-02 15:15:18 +02:00
2022-03-31 20:54:30 +02:00
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
2022-04-02 15:15:18 +02:00
2022-03-31 20:54:30 +02:00
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
2022-04-02 15:15:18 +02:00
2022-03-20 17:16:25 +01:00
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
2022-04-02 15:15:18 +02:00
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DH_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
2022-04-03 15:10:26 +02:00
- name: build&push
2022-03-31 20:54:30 +02:00
uses: docker/build-push-action@v2
2022-03-20 17:36:31 +01:00
with:
2022-03-31 20:54:30 +02:00
push: ${{ github.event_name != 'pull_request' }}
2022-04-03 12:48:26 +02:00
platforms: ${{ steps.prep.outputs.platform }}
file: ./${{ matrix.architecture }}.Dockerfile
cache-from: docker.io/${{ steps.prep.outputs.cache }}
cache-to: docker.io/${{ steps.prep.outputs.cache }}
tags: |
docker.io/${{ steps.prep.outputs.tag }}
ghcr.io/${{ steps.prep.outputs.tag }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.title=${{ steps.prep.outputs.title }}
org.opencontainers.image.revision=${{ steps.prep.outputs.revision }}
org.opencontainers.image.source=${{ steps.prep.outputs.source }}
org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }}
org.opencontainers.image.url=${{ steps.prep.outputs.url }}
2022-04-03 16:43:03 +02:00
org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }}
2022-04-03 12:48:26 +02:00
build-args: |
TP_RELEASE=${{ steps.prep.outputs.VERSION }}
BUILD_DATE=${{ steps.date_time.outputs.created }}
BUILD_ARCHITECTURE=${{ matrix.architecture }}
publish:
2022-04-03 15:10:26 +02:00
runs-on: ubuntu-latest
2022-04-03 12:48:26 +02:00
strategy:
matrix:
registry: [docker.io, ghcr.io]
needs: [build-and-push-it-to-the-limit]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to DockerHub
if: matrix.registry == 'docker.io'
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DH_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: matrix.registry == 'ghcr.io'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: Create manifests
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
2022-04-03 12:53:40 +02:00
IMAGE=${{ matrix.registry }}/${GITHUB_REPOSITORY,,}
2022-04-03 16:15:28 +02:00
TAG=${{ github.ref_name }}
2022-04-03 12:48:26 +02:00
SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
VERSION=${{ steps.prep.outputs.VERSION }}
[[ -f linux-amd64.Dockerfile ]] && AMD64=${SOURCE}-linux-amd64
[[ -f linux-arm64.Dockerfile ]] && ARM64=${SOURCE}-linux-arm64
[[ -f linux-arm-v7.Dockerfile ]] && ARMV7=${SOURCE}-linux-arm-v7
docker manifest create ${IMAGE}:${TAG} ${AMD64} ${ARM64} ${ARMV7}
2022-04-03 17:20:09 +02:00
docker manifest push ${IMAGE}:${TAG}
2022-04-03 16:54:26 +02:00
docker manifest create ${IMAGE}:${TAG}-${GITHUB_SHA:0:7} ${AMD64} ${ARM64} ${ARMV7}
2022-04-03 17:20:09 +02:00
docker manifest push ${IMAGE}:${TAG}-${GITHUB_SHA:0:7}
- name: Latest manifest
if: ${{ github.event.release.target_commitish == 'master' }}
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
IMAGE=${{ matrix.registry }}/${GITHUB_REPOSITORY,,}
2022-04-03 17:34:18 +02:00
TAG=${{ github.ref_name }}
2022-04-03 17:31:16 +02:00
SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}
[[ -f linux-amd64.Dockerfile ]] && AMD64=${SOURCE}-linux-amd64
[[ -f linux-arm64.Dockerfile ]] && ARM64=${SOURCE}-linux-arm64
2022-04-03 17:25:29 +02:00
[[ -f linux-arm-v7.Dockerfile ]] && ARMV7=${SOURCE}-linux-arm-v7
2022-04-03 16:34:13 +02:00
docker manifest create ${IMAGE}:latest ${AMD64} ${ARM64} ${ARMV7}
2022-04-03 17:20:09 +02:00
docker manifest push ${IMAGE}:latest