Changes CI config to GitHub Actions

This commit is contained in:
Maximilian Kratz 2023-01-29 12:56:52 +01:00
parent df9a4bb41a
commit a800e49c3c
2 changed files with 31 additions and 98 deletions

View file

@ -1,98 +0,0 @@
kind: pipeline
name: default
#
# Global definitions
#
# This CI uses a fork of docker/dind which also provides buildx support.
.buildimage: &buildimage
image: maniator/dind-buildx
# Environment setup.
.env: &env
environment:
USERNAME:
from_secret: dockerhub_username
PASSWORD:
from_secret: dockerhub_password
REPO: maxkratz/postfix_exporter
# Define a temporary volue for communicating with the dind service.
.dockervolume: &dockervolume
volumes:
- name: dockersock
path: /var/run
# Wait a bit for dind to start
.sleep: &sleep
sleep 5
# Login to dockerhub.
.login: &login
docker login -u $USERNAME -p $PASSWORD
# Setup the buildx builder.
.setup: &setup
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && docker buildx create --name builder --driver docker-container --use && docker buildx inspect --bootstrap
# ^normally, one would use a syntax like this:
#.setup: &setup
# - docker ..
# - docker ..
# BUT: The YAML parser of drone does not allow it and returns an error:
# > cannot unmarshal !!seq into string
# Therefore, the setup block uses && to run all three docker comands as one single string.
#
# Additionally, this command breaks if some newlines `\` are included.
# Only build and push images if commit is on the branch `main`.
.ismain: &ismain
when:
branch:
include:
- main
# Only build(-only) images if commit is NOT on the branch `main`.
.isnotmain: &isnotmain
when:
branch:
exclude:
- main
steps:
# Build latest image without pushing it.
- name: build-latest
<<: *buildimage
<<: *dockervolume
<<: *env
commands:
- *sleep
- *setup
- docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t $REPO:latest .
<<: *isnotmain
# Build and push latest image.
- name: build-and-push-latest
<<: *buildimage
<<: *dockervolume
<<: *env
commands:
- *sleep
- *login
- *setup
- docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t $REPO:latest --push .
<<: *ismain
#
# Dind service for building Docker images.
#
services:
- name: docker
image: docker:dind
privileged: true
<<: *dockervolume
# The temporary volume for the dockersocket.
volumes:
- name: dockersock
temp: {}

31
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,31 @@
name: Build Docker images
on:
push:
branches:
- 'main'
- 'testing/**'
- 'feature/**'
- 'hotfix/**'
jobs:
build-latest:
runs-on: [ubuntu-22.04]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build latest
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name == 'push' && contains(github.ref, 'refs/heads/main') && github.event_name != 'schedule' }}
tags: maxkratz/postfix_exporter:latest
platforms: linux/amd64,linux/arm64,linux/arm/v7