From 8353f19dc223c90e104a2925718b43372d29247c Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Wed, 6 Jul 2022 00:58:47 +0200 Subject: [PATCH] tests: docker dev pipelines --- .github/workflows/devel.docker.yml | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ci/get_latest_release.sh | 18 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .github/workflows/devel.docker.yml create mode 100755 ci/get_latest_release.sh diff --git a/.github/workflows/devel.docker.yml b/.github/workflows/devel.docker.yml new file mode 100644 index 0000000..8170222 --- /dev/null +++ b/.github/workflows/devel.docker.yml @@ -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 }} + - + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/ci/get_latest_release.sh b/ci/get_latest_release.sh new file mode 100755 index 0000000..3633763 --- /dev/null +++ b/ci/get_latest_release.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +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'" -- libgit2 1.7.2