Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxeye committed Aug 17, 2023
0 parents commit d7e646c
Show file tree
Hide file tree
Showing 12 changed files with 1,519 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
31 changes: 31 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
199 changes: 199 additions & 0 deletions .github/workflows/docker-multistage-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
name: "Build multistage docker images (multi -flavours, -versions, -architectures)"

on:
workflow_call:
###
### Variables
###
inputs:
matrix:
description: 'The build matrix'
required: true
type: string
stage:
description: 'The stage to build (Examples: base, mods, prod or work).'
required: true
type: string
stage_prev:
description: 'The previous stage (used for downloading previous artifact).'
required: true
type: string
artifact_prefix:
description: 'Unique artifact name prefix (to avoid overriding existing artifcats during parallel runs).'
required: true
type: string
has_refs:
description: 'The ref build matrix as JSON string (list of git refs to build/deploy).'
required: true
type: boolean
run_tests:
description: 'Dertermines whether we run integration tests or not.'
required: true
type: boolean
upload_artifact:
description: 'Dertermines whether we upload the artifact not.'
required: true
type: boolean
push_image:
description: 'Push docker image after build (and test if ran)?'
required: false
type: boolean
default: false
pull_base_image:
description: 'Pull Docker base image before building?'
required: false
type: boolean
default: false
###
### Secrets
###
secrets:
dockerhub_username:
description: 'The username for Dockerhub.'
required: false
dockerhub_password:
description: 'The password for Dockerhub.'
required: false

jobs:
# -----------------------------------------------------------------------------------------------
# JOB: BUILD
# -----------------------------------------------------------------------------------------------
build:
name: ${{ matrix.NAME }}-${{ matrix.VERSION }}-${{ inputs.stage }} (${{ matrix.ARCH }}) ${{ matrix.REFS }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(inputs.matrix) }}
steps:

# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: "[SETUP] Checkout repository (current)"
uses: actions/checkout@v3
with:
fetch-depth: 0
if: ${{ !inputs.has_refs }}

- name: "[SETUP] Checkout repository (ref: ${{ matrix.REFS }})"
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ matrix.REFS }}
if: ${{ inputs.has_refs }}

- name: "[SETUP] Install QEMU environment"
uses: docker/setup-qemu-action@v2
id: qemu
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: "[SETUP] Set artifact names"
id: set-artifact-name
run: |
VERSION="$( echo "${{ matrix.VERSION }}" )"
ARCH="$( echo "${{ matrix.ARCH }}" | sed 's|/|-|g' )"
NAME_PREV="${{ inputs.artifact_prefix }}-${VERSION}-${ARCH}-${{ inputs.stage_prev }}"
NAME_CURR="${{ inputs.artifact_prefix }}-${VERSION}-${ARCH}-${{ inputs.stage }}"
echo "prev=${NAME_PREV}" >> $GITHUB_OUTPUT
echo "curr=${NAME_CURR}" >> $GITHUB_OUTPUT
- name: "[SETUP] Determine Docker tag"
id: tag
uses: linuxeye/docker-tag-action@master

# https://github.com/alpinelinux/docker-alpine/issues/98
- name: "[SETUP] Fix Docker IP forwarding"
run: |
sysctl net.ipv4.ip_forward
sudo sysctl -w net.ipv4.ip_forward=1
sudo systemctl restart docker
# ------------------------------------------------------------
# Artifact Import
# ------------------------------------------------------------
- name: "[Artifact Load] Download previously built image"
uses: cytopia/[email protected]
with:
name: ${{ steps.set-artifact-name.outputs.prev }}
if: ${{ inputs.stage_prev != '' }}

- name: "[Artifact Load] Import previously built image"
uses: cytopia/[email protected]
with:
command: |
make load INFILE=${{ steps.set-artifact-name.outputs.prev }}
if: ${{ inputs.stage_prev != '' }}


# ------------------------------------------------------------
# Build
# ------------------------------------------------------------
- name: Pull
uses: cytopia/[email protected]
with:
command: |
make docker-pull-base-image VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} ARCH=${{ matrix.ARCH }}
if: ${{ inputs.pull_base_image }}

- name: Build
uses: cytopia/[email protected]
with:
command: |
make build VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} ARCH=${{ matrix.ARCH }}
# ------------------------------------------------------------
# Test
# ------------------------------------------------------------
- name: Test
uses: cytopia/[email protected]
with:
command: |
make test VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} ARCH=${{ matrix.ARCH }}
if: ${{ inputs.run_tests }}


# ------------------------------------------------------------
# Push
# ------------------------------------------------------------
- name: Docker Tag
uses: cytopia/[email protected]
with:
command: |
make tag VERSION="${{ matrix.VERSION }}" STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} TAG=${{ steps.tag.outputs.docker-tag }}
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_password }}
if: ${{ inputs.push_image }}

- name: Docker push
uses: cytopia/[email protected]
with:
command: |
make push VERSION="${{ matrix.version }}" STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.flavour }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }}
if: ${{ inputs.push_image }}


# ------------------------------------------------------------
# Artifact Export
# ------------------------------------------------------------
- name: "[Artifact Save] Upload built artifact"
uses: cytopia/[email protected]
with:
name: ${{ steps.set-artifact-name.outputs.curr }}
path: ${{ steps.set-artifact-name.outputs.curr }}
pre_command: |
make save-verify VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} ARCH=${{ matrix.ARCH }} OUTFILE=${{ steps.set-artifact-name.outputs.curr }} INFILE=${{ steps.set-artifact-name.outputs.curr }}
post_command: |
make load INFILE={{download_path}}
if: ${{ inputs.upload_artifact }}
Loading

0 comments on commit d7e646c

Please sign in to comment.