Skip to content

Enable build-time caching layers in Dockerfile to improve dependency … #5

Enable build-time caching layers in Dockerfile to improve dependency …

Enable build-time caching layers in Dockerfile to improve dependency … #5

Workflow file for this run

name: "Build and Push Multi-JDK Docker Image"
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
env:
REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: "Set lowercase image name"
run: echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: "Log in to GHCR"
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Docker meta"
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=sha
- name: "Build and push"
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
load: ${{ github.event_name == 'pull_request' }}
- name: "Smoke tests"
run: |
set -euo pipefail
image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}"
for cmd in "java -version" "gradle --version" "node --version" "rg --version" "fd --version"; do
echo "==> $cmd"
docker run --rm "$image" bash -c "source /opt/sdkman/bin/sdkman-init.sh && $cmd"
done