Push only if image test succeeds

This commit is contained in:
Leonard Jonathan Oh 2023-04-14 08:55:46 +00:00
parent 5fac68f2c4
commit 9f3a47ed53
5 changed files with 35 additions and 11 deletions

View file

@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1
FROM alpine:3.15 AS builder FROM alpine:3.15 AS builder
RUN apk add --no-cache php7 php7-json php-phar php-zip RUN apk add --no-cache php7 php7-json php-phar php-zip
RUN apk add --no-cache npm RUN apk add --no-cache npm

View file

@ -1,3 +0,0 @@
#!/bin/sh
set -eu
docker build -t snappymail/snappymail:test -f .docker/release/Dockerfile .

View file

@ -0,0 +1,7 @@
#!/bin/sh
# This script uses docker buildx to build a docker image, and loads it into the docker daemon. Then it executes ./test.sh to test the docker image
# It is useful for testing release builds in development
set -eu
IMAGE=snappymail/snappymail:test
DOCKER_BUILDX=1 docker buildx build --progress plain --load -t "$IMAGE" -f .docker/release/Dockerfile .
.docker/release/test/test.sh "$IMAGE"

View file

@ -1,10 +1,9 @@
#!/bin/sh #!/bin/sh
# This script tests a given docker image using https://github.com/GoogleContainerTools/container-structure-test # This script tests a given docker image using https://github.com/GoogleContainerTools/container-structure-test
set -eu set -eu
IMAGE=${1:-snappymail/snappymail:test}
SCRIPT_DIR=$( cd "$(dirname "$0")" && pwd ) SCRIPT_DIR=$( cd "$(dirname "$0")" && pwd )
docker inspect "$IMAGE" > /dev/null 2>&1 || docker pull "$IMAGE" # Pull the image if it doesn't exist in docker daemon IMAGE=${1:-}
echo "Testing image: $IMAGE"
docker run --rm -i \ docker run --rm -i \
-v /var/run/docker.sock:/var/run/docker.sock:ro \ -v /var/run/docker.sock:/var/run/docker.sock:ro \
-v "$SCRIPT_DIR/config.yaml:/config.yaml:ro" \ -v "$SCRIPT_DIR/config.yaml:/config.yaml:ro" \

View file

@ -79,6 +79,30 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
# See: https://github.com/docker/buildx/issues/59
- name: Build
id: build
uses: docker/build-push-action@v3
with:
context: '.'
file: ./.docker/release/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Docker images
run: |
docker images
- name: Test
run: |
TAG=$( echo "${{ steps.meta.outputs.tags }}" | head -n1 )
.docker/release/test/test.sh "$TAG"
- name: Build and push - name: Build and push
id: build-and-push id: build-and-push
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
@ -94,11 +118,6 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Test
run: |
TAG=$( echo "${{ steps.meta.outputs.tags }}" | head -n1 )
.docker/release/test/test.sh "$TAG"
# Temp fix # Temp fix
# https://github.com/docker/build-push-action/issues/252 # https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896 # https://github.com/moby/buildkit/issues/1896