tests: docker dev pipelines
Diff
.github/workflows/devel.docker.yml | 125 ++++++++++++++++++++++++++++++++++++++-
ci/get_latest_release.sh | 18 +++++-
2 files changed, 143 insertions(+)
@@ -0,0 +1,125 @@
name: devel-docker
on:
pull_request:
push:
branches:
- master
- staging
- trying
env:
DOCKER_IMAGE: localhost:5000/joseluisq/static-web-server
jobs:
docker-alpine:
name: Docker test
strategy:
matrix:
arch:
- linux/amd64
- linux/386
- linux/arm64
- linux/arm/v7
- linux/arm/v6
runs-on: ubuntu-20.04
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Dependencies
run: |
sudo apt-get install jq
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
-
name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: static-web-server-${{ matrix.arch }}-buildx-${{ github.sha }}
restore-keys: |
static-web-server-${{ matrix.arch }}-buildx-
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Docker meta alpine
id: meta_alpine
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_IMAGE }}
flavor: |
latest=false
suffix=-alpine
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
-
name: Prepare Docker envs
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ci/get_latest_release.sh
cat /tmp/version >> $GITHUB_ENV
cat /tmp/version
echo "SERVER_DOCKERFILE=./docker/alpine/Dockerfile" >> $GITHUB_ENV
-
name: Build and export to Docker client
uses: docker/build-push-action@v2
with:
context: .
platforms: ${{ matrix.arch }}
file: ${{ env.SERVER_DOCKERFILE }}
load: true
tags: ${{ steps.meta_alpine.outputs.tags }}
labels: ${{ steps.meta_alpine.outputs.labels }}
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
-
name: Build and push to local registry
uses: docker/build-push-action@v2
with:
context: .
platforms: ${{ matrix.arch }}
file: ${{ env.SERVER_DOCKERFILE }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta_alpine.outputs.tags }}
labels: ${{ steps.meta_alpine.outputs.labels }}
build-args: |
SERVER_VERSION=${{ env.SERVER_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
-
name: Inspect image
run: |
docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta_alpine.outputs.version }}
-
name: Check manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta_alpine.outputs.version }}
-
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
@@ -0,0 +1,18 @@
set -e
echo "Getting latest release number..."
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/joseluisq/static-web-server/releases?per_page=5&page=1" | \
jq -c "[ .[] | select( .tag_name | contains(\"v2.\")) ] | .[0]" | \
jq -r ".tag_name" > /tmp/version
version=$(cat /tmp/version)
echo "SERVER_VERSION=${version#*v}" > /tmp/version
echo "Version saved on '/tmp/version'"