Skip to content

Build and Publish Docker Image #121

Build and Publish Docker Image

Build and Publish Docker Image #121

Workflow file for this run

name: Build and Publish Docker Image
permissions:
contents: read
packages: write
on:
push:
branches:
- main
schedule:
- cron: 43 2 * * 0
workflow_dispatch:
inputs:
psalmVersion:
description: 'Psalm version to build'
required: true
default: 'null'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: docker/setup-qemu-action@v2
- uses: actions/checkout@v3
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine Psalm version to build
run: |
if [[ -z "$PSALM_VERSION" ]]; then
PSALM_VERSION=`curl -sL https://api.github.com/repos/vimeo/psalm/releases/latest | jq -r ".tag_name" | sed -e 's/^v//'`
fi
if [[ "$PSALM_VERSION" == "null" ]]; then
echo "Failed to determine Psalm version to build"
exit 1
fi
echo "Building Psalm version $PSALM_VERSION"
echo "PSALM_VERSION=$PSALM_VERSION" >> $GITHUB_ENV
env:
PSALM_VERSION: ${{ github.event.inputs.psalmVersion }}
- name: Build Docker Image
run: |
docker buildx create --name builder --use
docker buildx build \
--progress plain \
--platform=linux/amd64,linux/arm64 \
--cache-from=ghcr.io/webfactory/psalm:build-cache \
--cache-to=type=registry,ref=ghcr.io/webfactory/psalm:build-cache,mode=max,push=true \
--pull \
--build-arg PSALM_VERSION="$PSALM_VERSION" \
.
- name: Run smoke tests
run: |
# Load image for current platform into local Docker (see https://github.com/docker/buildx/issues/59)
docker buildx build \
--progress plain \
--cache-from=ghcr.io/webfactory/psalm:build-cache \
--tag build \
--build-arg PSALM_VERSION="$PSALM_VERSION" \
--load .
# Check "psalm --version" output
docker run --rm build --version | grep -q $PSALM_VERSION
- name: Push image to registry
if: github.event_name != 'pull_request'
run: |
docker buildx build \
--progress plain \
--platform=linux/amd64,linux/arm64 \
--cache-from=ghcr.io/webfactory/psalm:build-cache \
--tag ghcr.io/webfactory/psalm:"$PSALM_VERSION" \
--label org.opencontainers.image.source=https://github.com/webfactory/docker-psalm \
--build-arg PSALM_VERSION="$PSALM_VERSION" \
--push .