Refactor build workflow

This commit is contained in:
hackercat
2021-02-16 13:50:26 +00:00
parent c769888e60
commit bd8d7af121
+53 -32
View File
@@ -2,7 +2,7 @@ name: Build Docker image
on:
schedule:
- cron: 0 12 * * *
- cron: 0 12 */7 * *
push:
paths:
- '.github/workflows/build-images.yml'
@@ -14,12 +14,23 @@ on:
workflow_dispatch:
jobs:
act-base:
name: Build base docker images for act
print-date:
name: Provides current date
runs-on: ubuntu-latest
outputs:
date: ${{ steps.print-date.outputs.date }}
steps:
- name: Print date in UTC format
id: print-date
run: echo "::set-output name=date::$(date +%Y%m%d)"
act-base:
name: Build
runs-on: ubuntu-${{ matrix.DISTRIB_RELEASE }}
needs:
- print-date
strategy:
fail-fast: false
max-parallel: 12
fail-fast: true
max-parallel: 6
matrix:
DISTRIB_ID: [ubuntu]
DISTRIB_RELEASE: [latest, 20.04, 18.04, 16.04]
@@ -35,6 +46,7 @@ jobs:
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
id: ghcr
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
uses: docker/login-action@v1
with:
@@ -43,6 +55,7 @@ jobs:
password: ${{ secrets.GHCR_TOKEN }}
- name: Login to Quay
id: quay
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
uses: docker/login-action@v1
with:
@@ -51,21 +64,20 @@ jobs:
password: ${{ secrets.QUAY_TOKEN }}
- name: Login to Docker Hub
id: dckr
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
uses: docker/login-action@v1
with:
username: catthehacker
password: ${{ secrets.DCKR_TOKEN }}
- name: Check which version is currently `ubuntu-latest`
id: ubuntu_latest
if: ${{ matrix.DISTRIB_RELEASE == 'latest' }}
run: echo "::set-output name=UBUNTU_LATEST::$(lsb_release -sr)"
- name: Set Ubuntu version to RELEASE
id: release
run: echo "::set-output name=RELEASE::$(lsb_release -sr)"
- name: Build and push ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
id: docker_build_version
- name: Build and push catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
id: docker_build
uses: docker/build-push-action@v2
if: ${{ matrix.DISTRIB_RELEASE != 'latest' }}
with:
context: .
push: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
@@ -73,33 +85,21 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
quay.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
quay.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
docker.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
docker.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
build-args: |
DISTRIB_ID=${{ matrix.DISTRIB_ID }}
DISTRIB_RELEASE=${{ matrix.DISTRIB_RELEASE }}
NODE_VERSION=${{ matrix.NODE_VERSION }}
- name: Build and push ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
id: docker_build_latest
uses: docker/build-push-action@v2
if: ${{ matrix.DISTRIB_RELEASE == 'latest' }}
with:
context: .
push: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
file: ./linux/${{ matrix.DISTRIB_ID }}/${{ matrix.IMAGE_TYPE }}/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
quay.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
docker.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
build-args: |
DISTRIB_ID=${{ matrix.DISTRIB_ID }}
DISTRIB_RELEASE=${{ steps.ubuntu_latest.outputs.UBUNTU_LATEST }}
DISTRIB_RELEASE=${{ steps.release.outputs.RELEASE }}
NODE_VERSION=${{ matrix.NODE_VERSION }}
scan:
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
name: Scan
runs-on: ubuntu-latest
needs:
- print-date
- act-base
strategy:
max-parallel: 4
@@ -111,4 +111,25 @@ jobs:
steps:
- uses: azure/container-scan@v0
with:
image-name: ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
image-name: ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
measure:
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
name: Measure
runs-on: ubuntu-latest
needs:
- print-date
- act-base
strategy:
max-parallel: 4
fail-fast: false
matrix:
DISTRIB_ID: [ubuntu]
DISTRIB_RELEASE: [latest, 20.04, 18.04, 16.04]
IMAGE_TYPE: [act, runner]
steps:
- name: Install `dive`
run: |
wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb
sudo dpkg -i dive_0.9.2_linux_amd64.deb
- name: Scan images size
run: dive --lowestEfficiency 0 --highestUserWastedPercent 1 ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}