1+ # #######################################
2+ # Multi-target Docker image build #
3+ # #######################################
4+
5+ # This file defines multiple build targets using Docker Bake,
6+ # allowing for fine-grained control over how images are built,
7+ # tagged, and promoted across environments (dev, test, release, etc.).
8+
9+ # ─────────────────────────────────────
10+ # 🏗️ Image Targets
11+ # ─────────────────────────────────────
12+ # dev:
13+ # Lightweight image for development and local testing.
14+ # Uses a single architecture and avoids production overhead.
15+
16+ # test:
17+ # Image used for automated testing pipelines.
18+ # Always pulls latest base layers to validate rebuild reliability.
19+
20+ # release:
21+ # Final production image, tagged for distribution.
22+ # Uses full multi-arch build, add annotations, disables cache, and
23+ # assigns versioned + semantic tags (e.g., latest, major, minor,
24+ # timestamp).
25+
26+ # ─────────────────────────────────────
27+ # 💡 Usage Notes
28+ # ─────────────────────────────────────
29+ # - Use `dev` when iterating locally.
30+ # - Use `test` in CI pipelines to verify integrity.
31+ # - Use `release` only in actual publishing pipelines.
32+
33+ # Build with:
34+ # docker buildx bake <target>
35+ #
36+ # Example:
37+ # docker buildx bake dev
38+
139# ========== VARIABLES ========== #
240
341# General properties
@@ -55,33 +93,32 @@ function "date" {
5593
5694# ========== TARGETS ========== #
5795
58- target "dev " {
59- description = " Builds the image for development purposes ."
96+ target "_common " {
97+ description = " Base configuration inherited by all other targets ."
6098 args = {
6199 MINECRAFT_VERSION = " ${ MINECRAFT_VERSION } "
62100 }
63- tags = [
64- tag (" dev" )
65- ]
101+ }
102+
103+ target "dev" {
104+ inherits = [" _common" ]
105+ description = " Builds a lightweight image for development and local testing."
106+ tags = [ tag (" dev" ) ]
107+ }
108+
109+ target "test" {
110+ inherits = [" _common" ]
111+ description = " Builds a test image with fresh base layers (always pulls upstream images)."
112+ pull = true
113+ tags = [ tag (" test" ) ]
66114}
67115
68116target "release" {
69- description = " Builds the image for production purposes."
70- args = {
71- MINECRAFT_VERSION = " ${ MINECRAFT_VERSION } "
72- }
117+ inherits = [" _common" ]
118+ description = " Builds and tags the production image for publishing."
73119 platforms = [" linux/amd64" , " linux/arm64" ]
74120 pull = true
75121 no-cache = true
76- # Docker tag format: <mc-version>-v<image-version>-<timestamp-YYYYMMDD>
77- tags = [
78- equal (IS_LATEST_RELEASE, true ) ? tag (" latest" ) : " " ,
79- equal (IS_LATEST_RELEASE, true ) ? tag (" ${ MINECRAFT_VERSION } " ) : " " ,
80- tag (" ${ MINECRAFT_VERSION } -v${ IMAGE_VERSION } " ),
81- tag (" ${ MINECRAFT_VERSION } -v${ IMAGE_VERSION } -${ date ()} " ),
82- tag (" ${ MINECRAFT_VERSION } -v${ extractMajorMinorFromSemVer (IMAGE_VERSION)} " ),
83- tag (" ${ MINECRAFT_VERSION } -v${ extractMajorFromSemVer (IMAGE_VERSION)} " )
84- ]
85122 annotations = [
86123 annotation (" org.opencontainers.image.title" , " PaperMC Server" ),
87124 annotation (" org.opencontainers.image.description" , " Dockerized and fine-grained customizable PaperMC server." ),
@@ -96,12 +133,15 @@ target "release" {
96133 notequal (REVISION, " " ) ? annotation (" org.opencontainers.image.revision" , REVISION) : " "
97134 ]
98135 attest = [
99- {
100- type = " provenance" ,
101- mode = " max" ,
102- },
103- {
104- type = " sbom" ,
105- }
136+ { type = " provenance" , mode = " max" , },
137+ { type = " sbom" , }
138+ ]
139+ tags = [
140+ equal (IS_LATEST_RELEASE, true ) ? tag (" latest" ) : " " ,
141+ equal (IS_LATEST_RELEASE, true ) ? tag (" ${ MINECRAFT_VERSION } " ) : " " ,
142+ tag (" ${ MINECRAFT_VERSION } -v${ IMAGE_VERSION } " ),
143+ tag (" ${ MINECRAFT_VERSION } -v${ IMAGE_VERSION } -${ date ()} " ),
144+ tag (" ${ MINECRAFT_VERSION } -v${ extractMajorMinorFromSemVer (IMAGE_VERSION)} " ),
145+ tag (" ${ MINECRAFT_VERSION } -v${ extractMajorFromSemVer (IMAGE_VERSION)} " )
106146 ]
107147}
0 commit comments