Skip to content

Commit 35f1060

Browse files
committed
Add get jdbc for postgres and mysql gradle task, add moquidemo actions release
1 parent 099f22c commit 35f1060

2 files changed

Lines changed: 296 additions & 0 deletions

File tree

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# MoquiDemo Release - Build and publish MoquiDemo zip, WAR, Docker images on release
2+
# Equivalent to make_demo.sh with multi-arch images, SBOM, provenance, and cosign signing
3+
name: MoquiDemo Release
4+
5+
on:
6+
release:
7+
types: [published]
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'Version (e.g., 3.0.0)'
12+
required: true
13+
type: string
14+
ref:
15+
description: 'Branch or tag to build from (default: default branch)'
16+
required: false
17+
type: string
18+
upload_to_release:
19+
description: 'Upload assets to GitHub Release'
20+
required: false
21+
type: boolean
22+
default: false
23+
24+
permissions:
25+
contents: write # Upload release assets
26+
id-token: write # OIDC for keyless cosign signing
27+
attestations: write # Attestations for provenance/SBOM
28+
packages: write # Push to ghcr.io
29+
30+
env:
31+
REGISTRY: ghcr.io
32+
33+
jobs:
34+
build-moquidemo:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
version: ${{ steps.vars.outputs.version }}
38+
version_minor: ${{ steps.vars.outputs.version_minor }}
39+
version_major: ${{ steps.vars.outputs.version_major }}
40+
41+
steps:
42+
- name: Get version
43+
id: vars
44+
run: |
45+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
46+
VERSION="${{ github.event.inputs.version }}"
47+
else
48+
# Strip 'v' prefix from tag (e.g., v3.0.0 -> 3.0.0)
49+
VERSION="${GITHUB_REF#refs/tags/v}"
50+
fi
51+
# Strip leading 'v' if user included it
52+
VERSION="${VERSION#v}"
53+
echo "version=$VERSION" >> $GITHUB_OUTPUT
54+
VERSION_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
55+
echo "version_minor=$VERSION_MINOR" >> $GITHUB_OUTPUT
56+
VERSION_MAJOR=$(echo "$VERSION" | cut -d. -f1)
57+
echo "version_major=$VERSION_MAJOR" >> $GITHUB_OUTPUT
58+
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
with:
62+
ref: ${{ github.event.inputs.ref || github.ref }}
63+
64+
- name: Set up JDK 21
65+
uses: actions/setup-java@v4
66+
with:
67+
java-version: '21'
68+
distribution: 'temurin'
69+
cache: 'gradle'
70+
71+
- name: Get runtime and demo components
72+
run: |
73+
./gradlew getRuntime getComponentSet -PcomponentSet=demo getComponent -Pcomponent=moqui-poi -PlocationType=release
74+
75+
- name: Download JDBC drivers and OpenSearch
76+
run: |
77+
./gradlew getMySqlJdbc getPostgresJdbc downloadOpenSearch
78+
79+
- name: Load data and run tests
80+
run: |
81+
./gradlew load test
82+
env:
83+
# Prevent ElasticSearch/OpenSearch from stealing focus
84+
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
85+
86+
- name: Wait for OpenSearch to stop
87+
run: sleep 5
88+
89+
- name: Create moqui-plus-runtime WAR
90+
run: ./gradlew addRuntime
91+
92+
- name: Create MoquiDemo zip and rename WAR
93+
run: |
94+
VERSION="${{ steps.vars.outputs.version }}"
95+
cp moqui-plus-runtime.war "MoquiDemo-${VERSION}.war"
96+
zip -r "MoquiDemo-${VERSION}.zip" . \
97+
-x "*.git*" \
98+
-x "*.git/*" \
99+
-x "build/*" \
100+
-x "framework/build/*" \
101+
-x "runtime/log/*" \
102+
-x "runtime/sessions/*" \
103+
-x "runtime/txlog/*" \
104+
-x "runtime/db/*" \
105+
-x "runtime/elasticsearch/data/*" \
106+
-x "runtime/opensearch/data/*" \
107+
-x "wartemp" \
108+
-x "moqui.war"
109+
# Include the renamed WAR in the zip
110+
zip -u "MoquiDemo-${VERSION}.zip" "MoquiDemo-${VERSION}.war"
111+
112+
- name: Upload artifacts
113+
uses: actions/upload-artifact@v4
114+
with:
115+
name: moquidemo-build
116+
path: |
117+
moqui-plus-runtime.war
118+
MoquiDemo-${{ steps.vars.outputs.version }}.zip
119+
MoquiDemo-${{ steps.vars.outputs.version }}.war
120+
docker/
121+
retention-days: 1
122+
123+
build-docker:
124+
needs: build-moquidemo
125+
runs-on: ubuntu-latest
126+
127+
steps:
128+
- name: Download build artifacts
129+
uses: actions/download-artifact@v4
130+
with:
131+
name: moquidemo-build
132+
133+
- name: Set up QEMU
134+
uses: docker/setup-qemu-action@v3
135+
136+
- name: Set up Docker Buildx
137+
uses: docker/setup-buildx-action@v3
138+
139+
- name: Log in to Container Registry
140+
uses: docker/login-action@v3
141+
with:
142+
registry: ${{ env.REGISTRY }}
143+
username: ${{ github.actor }}
144+
password: ${{ secrets.GITHUB_TOKEN }}
145+
146+
- name: Extract WAR and prepare Docker build context
147+
run: |
148+
unzip -q moqui-plus-runtime.war
149+
rm -f moqui-plus-runtime.war
150+
151+
- name: Build and push multi-arch Docker image
152+
id: build
153+
uses: docker/build-push-action@v6
154+
with:
155+
context: .
156+
file: ./docker/simple/Dockerfile
157+
platforms: linux/amd64,linux/arm64
158+
push: true
159+
provenance: mode=max
160+
sbom: true
161+
tags: |
162+
${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version }}
163+
${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }}
164+
${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_major }}
165+
${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:latest
166+
167+
- name: Sign container image with cosign (keyless)
168+
uses: sigstore/cosign-installer@v3
169+
- name: Sign the images
170+
run: |
171+
IMAGE="${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version }}"
172+
cosign sign --yes "$IMAGE"
173+
cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }}"
174+
cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_major }}"
175+
cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:latest"
176+
177+
push-dockerhub:
178+
needs: [build-docker, build-moquidemo]
179+
runs-on: ubuntu-latest
180+
if: vars.DOCKERHUB_USERNAME != ''
181+
182+
steps:
183+
- name: Set up Docker Buildx
184+
uses: docker/setup-buildx-action@v3
185+
186+
- name: Log in to Docker Hub
187+
uses: docker/login-action@v3
188+
with:
189+
username: ${{ vars.DOCKERHUB_USERNAME }}
190+
password: ${{ secrets.DOCKERHUB_TOKEN }}
191+
192+
- name: Copy images from GHCR to Docker Hub
193+
run: |
194+
SOURCE="${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo"
195+
for tag in ${{ needs.build-moquidemo.outputs.version }} ${{ needs.build-moquidemo.outputs.version_minor }} ${{ needs.build-moquidemo.outputs.version_major }} latest; do
196+
docker buildx imagetools create -t "moqui/moquidemo:${tag}" "${SOURCE}:${tag}"
197+
done
198+
199+
- name: Sign Docker Hub images with cosign (keyless)
200+
uses: sigstore/cosign-installer@v3
201+
- name: Sign the Docker Hub images
202+
run: |
203+
cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version }}
204+
cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }}
205+
cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version_major }}
206+
cosign sign --yes moqui/moquidemo:latest
207+
208+
upload-release:
209+
needs: [build-moquidemo, build-docker]
210+
runs-on: ubuntu-latest
211+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.upload_to_release == 'true')
212+
213+
steps:
214+
- name: Download build artifacts
215+
uses: actions/download-artifact@v4
216+
with:
217+
name: moquidemo-build
218+
219+
- name: Attest build provenance for release assets
220+
uses: actions/attest-build-provenance@v3
221+
with:
222+
subject-path: |
223+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip
224+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war
225+
226+
- name: Attest SBOM for release assets
227+
uses: actions/attest-sbom@v2
228+
with:
229+
subject-path: |
230+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip
231+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war
232+
233+
- name: Upload release assets
234+
uses: softprops/action-gh-release@v2
235+
with:
236+
tag_name: v${{ needs.build-moquidemo.outputs.version }}
237+
files: |
238+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip
239+
MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war
240+
fail_on_unmatched_files: true

build.gradle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,62 @@ task stopElasticSearch { doLast {
267267
stopSearch(moquiRuntime)
268268
} }
269269

270+
// ========== JDBC driver download tasks ==========
271+
272+
task getPostgresJdbc {
273+
description = "Download the latest PostgreSQL JDBC driver to runtime/lib"
274+
dependsOn 'getRuntime'
275+
doLast {
276+
def libDir = file(moquiRuntime + '/lib')
277+
if (!libDir.exists()) libDir.mkdirs()
278+
279+
// Remove existing Postgres JAR files
280+
fileTree(dir: libDir, include: 'postgres*.jar').each { it.delete() }
281+
282+
// Get the latest version from Maven repository
283+
def metadataUrl = 'https://repo1.maven.org/maven2/org/postgresql/postgresql/maven-metadata.xml'
284+
def metadataFile = file("${buildDir}/postgresql-maven-metadata.xml")
285+
ant.get(src: metadataUrl, dest: metadataFile)
286+
def metadata = new XmlSlurper().parse(metadataFile)
287+
def latestVersion = metadata.versioning.latest.text()
288+
metadataFile.delete()
289+
290+
// Download the latest version
291+
def downloadUrl = "https://repo1.maven.org/maven2/org/postgresql/postgresql/${latestVersion}/postgresql-${latestVersion}.jar"
292+
def jarFile = file("${libDir}/postgresql-${latestVersion}.jar")
293+
logger.lifecycle("Downloading PostgreSQL JDBC driver ${latestVersion} from ${downloadUrl}")
294+
ant.get(src: downloadUrl, dest: jarFile)
295+
logger.lifecycle("Downloaded PostgreSQL JDBC driver to ${jarFile}")
296+
}
297+
}
298+
299+
task getMySqlJdbc {
300+
description = "Download the latest MySQL JDBC driver to runtime/lib"
301+
dependsOn 'getRuntime'
302+
doLast {
303+
def libDir = file(moquiRuntime + '/lib')
304+
if (!libDir.exists()) libDir.mkdirs()
305+
306+
// Remove existing MySQL connector JAR files
307+
fileTree(dir: libDir, include: 'mysql-connector*.jar').each { it.delete() }
308+
309+
// Get the latest version from Maven repository
310+
def metadataUrl = 'https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/maven-metadata.xml'
311+
def metadataFile = file("${buildDir}/mysql-connector-j-maven-metadata.xml")
312+
ant.get(src: metadataUrl, dest: metadataFile)
313+
def metadata = new XmlSlurper().parse(metadataFile)
314+
def latestVersion = metadata.versioning.latest.text()
315+
metadataFile.delete()
316+
317+
// Download the latest version
318+
def downloadUrl = "https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/${latestVersion}/mysql-connector-j-${latestVersion}.jar"
319+
def jarFile = file("${libDir}/mysql-connector-j-${latestVersion}.jar")
320+
logger.lifecycle("Downloading MySQL JDBC driver ${latestVersion} from ${downloadUrl}")
321+
ant.get(src: downloadUrl, dest: jarFile)
322+
logger.lifecycle("Downloaded MySQL JDBC driver to ${jarFile}")
323+
}
324+
}
325+
270326
// ========== development tasks ==========
271327
task setupIntellij {
272328
description = "Adds all XML catalog items to intellij to enable autocomplete"

0 commit comments

Comments
 (0)