-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (94 loc) · 3.61 KB
/
Copy pathbuild.yml
File metadata and controls
104 lines (94 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: build
# Publishes images to GitHub Container Registry. By default only the slim image
# (org.openprojectx.* Maven artifacts) is built. The full image (full Maven build with all
# deps + jars) is opt-in: trigger the workflow manually with "build_full" enabled.
on:
push:
branches: [ main, master ]
tags: [ 'v*' ]
pull_request:
workflow_dispatch:
inputs:
build_full:
description: 'Also build and push the full (heavy) image'
type: boolean
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Print the full, uncollapsed output of every build instruction (no TUI grouping).
BUILDKIT_PROGRESS: plain
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Push everywhere except on pull requests (PRs from forks can't access GHCR).
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# First 8 characters of the commit hash, used as an image tag.
- name: Short commit SHA
id: vars
run: echo "short_sha=${GITHUB_SHA:0:8}" >> "$GITHUB_OUTPUT"
# Full image: opt-in only (manual run with build_full=true). Disabled by default.
- name: Docker metadata
id: meta
if: ${{ inputs.build_full }}
uses: docker/metadata-action@v5
with:
# metadata-action lowercases the image name, so mixed-case owners are fine.
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=${{ steps.vars.outputs.short_sha }}
type=raw,value=latest,enable={{is_default_branch}}
# The Dockerfile runs `mvn install` (install the deps and build in the image build),
# keeping the downloaded deps, built jars and source inside the published image.
- name: Build and push image
if: ${{ inputs.build_full }}
uses: docker/build-push-action@v6
with:
context: .
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
# Same image repo, tags suffixed with -slim (e.g. latest-slim, <shortsha>-slim).
- name: Docker metadata (slim)
id: meta-slim
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
suffix=-slim,onlatest=true
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=${{ steps.vars.outputs.short_sha }}
type=raw,value=latest,enable={{is_default_branch}}
# The slim image only populates the Maven local repo with the org.openprojectx.* artifacts.
- name: Build and push slim image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.slim
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-slim.outputs.tags }}
labels: ${{ steps.meta-slim.outputs.labels }}
cache-from: type=gha,scope=slim
cache-to: type=gha,mode=max,scope=slim