refactor: refactor build workflow, add dependabot

This commit is contained in:
hackercat
2021-04-04 19:56:12 +00:00
parent bdcc8235a5
commit 7cf55a7620
2 changed files with 107 additions and 135 deletions
+7
View File
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'monthly'
+100 -135
View File
@@ -1,135 +1,100 @@
name: Build Docker image name: Build Docker image
on: on:
schedule: schedule:
- cron: 0 12 */7 * * - cron: 0 12 */7 * *
push: push:
paths: paths:
- '.github/workflows/build-images.yml' - '.github/workflows/build-images.yml'
- 'linux/**' - 'linux/**'
pull_request: pull_request:
paths: paths:
- '.github/workflows/build-images.yml' - '.github/workflows/build-images.yml'
- 'linux/**' - 'linux/**'
workflow_dispatch: workflow_dispatch:
jobs: env:
print-date: NODE: '12'
name: Provides current date
runs-on: ubuntu-latest jobs:
outputs: build:
date: ${{ steps.print-date.outputs.date }} name: Build
steps: runs-on: ubuntu-20.04
- name: Print date in UTC format if: ${{ github.actor == github.repository_owner && github.event_name != 'pull_request' }}
id: print-date strategy:
run: echo "::set-output name=date::$(date +%Y%m%d)" fail-fast: true
act-base: max-parallel: 4
name: Build matrix:
runs-on: ubuntu-${{ matrix.DISTRIB_RELEASE }} DISTRIB_ID: [ubuntu]
needs: DISTRIB_RELEASE: [latest, 20.04, 18.04, 16.04]
- print-date IMAGE_TYPE: [act, runner]
strategy: steps:
fail-fast: true - name: Login to GitHub Container Registry
max-parallel: 6 id: ghcr
matrix: if: ${{ github.actor == github.repository_owner }}
DISTRIB_ID: [ubuntu] uses: docker/login-action@v1
DISTRIB_RELEASE: [latest, 20.04, 18.04, 16.04] with:
IMAGE_TYPE: [act, runner] registry: ghcr.io
NODE_VERSION: ['12'] username: ${{ github.repository_owner }}
steps: password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- name: Login to Quay
- name: Set up QEMU id: quay
uses: docker/setup-qemu-action@v1 if: ${{ github.actor == github.repository_owner }}
uses: docker/login-action@v1
- name: Set up Docker Buildx with:
uses: docker/setup-buildx-action@v1 registry: quay.io
username: ${{ secrets.QUAY_USER }}
- name: Login to GitHub Container Registry password: ${{ secrets.QUAY_TOKEN }}
id: ghcr
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }} - name: Login to Docker Hub
uses: docker/login-action@v1 id: dckr
with: if: ${{ github.actor == github.repository_owner }}
registry: ghcr.io uses: docker/login-action@v1
username: ${{ github.repository_owner }} with:
password: ${{ secrets.GHCR_TOKEN }} username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay
id: quay - name: Print date in UTC format
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }} id: print-date
uses: docker/login-action@v1 run: echo "::set-output name=date::$(date +%Y%m%d)"
with:
registry: quay.io - name: Set Ubuntu version to RELEASE
username: catthehacker+docker_images id: release
password: ${{ secrets.QUAY_TOKEN }} run: |
if [ "latest" = "${{ matrix.DISTRIB_RELEASE }}" ]; then
- name: Login to Docker Hub echo "::set-output name=RELEASE::20.04"
id: dckr else
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }} echo "::set-output name=RELEASE::${{ matrix.DISTRIB_RELEASE }}"
uses: docker/login-action@v1 fi
with:
username: catthehacker - name: Set up QEMU
password: ${{ secrets.DCKR_TOKEN }} uses: docker/setup-qemu-action@v1
- name: Set Ubuntu version to RELEASE - name: Set up Docker Buildx
id: release uses: docker/setup-buildx-action@v1
run: echo "::set-output name=RELEASE::$(lsb_release -sr)"
- uses: actions/checkout@v2
- name: Build and push catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }}
id: docker_build - name: Build and push ${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ steps.print-date.outputs.date }}
uses: docker/build-push-action@v2 id: docker_build
with: uses: docker/build-push-action@v2
context: . with:
push: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }} context: .
file: ./linux/${{ matrix.DISTRIB_ID }}/${{ matrix.IMAGE_TYPE }}/Dockerfile push: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }}
platforms: linux/amd64,linux/arm64 file: ./linux/${{ matrix.DISTRIB_ID }}/${{ matrix.IMAGE_TYPE }}/Dockerfile
tags: | platforms: linux/amd64,linux/arm64
ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }} tags: |
ghcr.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }} ghcr.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
quay.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }} ghcr.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ steps.print-date.outputs.date }}
quay.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }} quay.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
docker.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }} quay.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ steps.print-date.outputs.date }}
docker.io/catthehacker/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ needs.print-date.outputs.date }} docker.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}
build-args: | docker.io/${{ github.repository_owner }}/${{ matrix.DISTRIB_ID }}:${{ matrix.IMAGE_TYPE }}-${{ matrix.DISTRIB_RELEASE }}-${{ steps.print-date.outputs.date }}
DISTRIB_ID=${{ matrix.DISTRIB_ID }} build-args: |
DISTRIB_RELEASE=${{ steps.release.outputs.RELEASE }} DISTRIB_ID=${{ matrix.DISTRIB_ID }}
NODE_VERSION=${{ matrix.NODE_VERSION }} DISTRIB_RELEASE=${{ steps.release.outputs.RELEASE }}
scan: NODE_VERSION=${{ env.NODE }}
if: ${{ github.event_name != 'pull_request' && github.event_name != 'push' }} BUILD_TAG_VERSION=${{ steps.print-date.outputs.date }}
name: Scan BUILD_TAG=${{ matrix.IMAGE_TYPE }}
runs-on: ubuntu-latest BUILD_REF=${{ github.sha }}
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:
- uses: azure/container-scan@v0
with:
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 }}