Dockerise semonitor #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create and publish Container image | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- 'v*' | |
pull_request: | |
branches: | |
- master | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
TEST_TAG: ${{ github.repository }}:${{github.run_id}} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
include: | |
- container: Containerfile.debian | |
autotag: false | |
suffix: -debian | |
- container: Containerfile.alpine | |
autotag: auto | |
runuser: apk add --no-cache bash runuser && | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=edge | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
flavor: | | |
latest=${{ matrix.autotag }} | |
suffix=${{ matrix.suffix }} | |
- name: Build and export | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ${{ matrix.container }} | |
load: true | |
tags: ${{ env.TEST_TAG }} | |
- name: Test | |
run: > | |
docker container run \ | |
--rm \ | |
--user 'root:root' \ | |
--volume "$(pwd)/test:/usr/local/src/semonitor/test" \ | |
${{ env.TEST_TAG }} \ | |
'/bin/sh' -c '${{ matrix.runuser }} runuser --user semonitor -- ./test/test.sh' | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6 | |
context: . | |
file: Containerfile | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |