Skip to content

Commit 78a12e8

Browse files
committed
feat: add Docker image publishing workflow for Maven artifacts
- Configured `build.gradle.kts` to support publishing Maven artifacts to a local image-specific repository. - Added a Dockerfile for packaging Maven artifacts into a lightweight Docker image. - Updated `.github/workflows/release.yml` to automate the Docker image build and publish process. - Configured `.dockerignore` to optimize build context and exclude unnecessary files.
1 parent f35ffd0 commit 78a12e8

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**
2+
!build/
3+
!build/image/
4+
!build/image/m2/
5+
!build/image/m2/repository/
6+
!build/image/m2/repository/**
7+
!docker/
8+
!docker/maven-artifacts.Dockerfile

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,51 @@ jobs:
7171
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
7272
run: |
7373
./gradlew --no-configuration-cache release $EXTRA_GRADLE_ARGS
74+
75+
- name: Checkout release tag
76+
run: |
77+
git fetch --tags --force
78+
release_tag="$(git describe --tags --abbrev=0)"
79+
echo "RELEASE_TAG=$release_tag" >> "$GITHUB_ENV"
80+
git checkout "$release_tag"
81+
82+
- name: Read release version
83+
run: |
84+
release_version="$(sed -n 's/^version=//p' gradle.properties)"
85+
echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV"
86+
87+
- name: Set image name
88+
run: |
89+
echo "IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY,,}/maven-artifacts" >> "$GITHUB_ENV"
90+
91+
- name: Publish Maven artifacts for image
92+
env:
93+
SIGNING_KEY_FILE: ${{ runner.temp }}/signing-key.asc
94+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
95+
run: |
96+
./gradlew --no-configuration-cache publishMavenArtifactsForImage
97+
98+
- name: Set up Docker Buildx
99+
uses: docker/setup-buildx-action@v3
100+
101+
- name: Log in to GitHub Container Registry
102+
uses: docker/login-action@v3
103+
with:
104+
registry: ghcr.io
105+
username: ${{ github.actor }}
106+
password: ${{ secrets.GITHUB_TOKEN }}
107+
108+
- name: Publish Maven artifacts image
109+
uses: docker/build-push-action@v6
110+
with:
111+
context: .
112+
file: docker/maven-artifacts.Dockerfile
113+
push: true
114+
tags: |
115+
${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
116+
${{ env.IMAGE_NAME }}:${{ env.RELEASE_TAG }}
117+
${{ env.IMAGE_NAME }}:latest
118+
labels: |
119+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
120+
org.opencontainers.image.revision=${{ github.sha }}
121+
org.opencontainers.image.version=${{ env.RELEASE_VERSION }}

build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ subprojects {
8383
}
8484

8585
extensions.configure<PublishingExtension>("publishing") {
86+
repositories {
87+
maven {
88+
name = "imageMaven"
89+
url = rootProject.layout.buildDirectory.dir("image/m2/repository").get().asFile.toURI()
90+
}
91+
}
92+
8693
publications {
8794
if (project.name != "plugin" && findByName("mavenJava") == null) {
8895
create<MavenPublication>("mavenJava") {
@@ -150,6 +157,12 @@ subprojects {
150157
}
151158
}
152159

160+
tasks.register("publishMavenArtifactsForImage") {
161+
group = "publishing"
162+
description = "Publishes all Maven publications into build/image/m2/repository for the Docker image."
163+
dependsOn(subprojects.map { "${it.path}:publishAllPublicationsToImageMavenRepository" })
164+
}
165+
153166
nexusPublishing {
154167
repositories {
155168
sonatype {

docker/maven-artifacts.Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM gcr.io/distroless/java17-debian13
2+
3+
WORKDIR /root/.m2/repository
4+
COPY build/image/m2/repository/ /root/.m2/repository/

0 commit comments

Comments
 (0)