Skip to content

Commit 006f285

Browse files
feat: add support for GraalVM build (#228)
1 parent 818fd81 commit 006f285

File tree

7 files changed

+243
-76
lines changed

7 files changed

+243
-76
lines changed

.github/renovate.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"semanticCommits": "enabled",
1616
"dependencyDashboard": true,
1717
"dependencyDashboardLabels": ["type: process"],
18+
"ignoreDeps": [
19+
"org.graalvm.sdk:graal-sdk"
20+
],
1821
"packageRules": [
1922
{
2023
"matchPackagePatterns": [

.github/sync-repo-settings.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ branchProtectionRules:
4545
- "lint"
4646
- "units (8)"
4747
- "units (11)"
48-
# - "graalvm17"
4948
- "units + e2e"
5049
- "cla/google"
5150
# Wait until we make the repo public before bringing this back

.github/workflows/ci.yaml

Lines changed: 83 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -111,80 +111,89 @@ jobs:
111111
env:
112112
JOB_TYPE: clirr
113113

114-
# graalvm17:
115-
# # run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label)
116-
# if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}"
117-
# name: graalvm17
118-
# runs-on: ubuntu-latest
119-
# permissions:
120-
# contents: 'read'
121-
# id-token: 'write'
122-
# issues: write
123-
# pull-requests: write
124-
# steps:
125-
# - name: Remove PR label
126-
# if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
127-
# uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0
128-
# with:
129-
# github-token: ${{ secrets.GITHUB_TOKEN }}
130-
# script: |
131-
# try {
132-
# await github.rest.issues.removeLabel({
133-
# name: 'tests: run',
134-
# owner: context.repo.owner,
135-
# repo: context.repo.repo,
136-
# issue_number: context.payload.pull_request.number
137-
# });
138-
# } catch (e) {
139-
# console.log('Failed to remove label. Another job may have already removed it!');
140-
# }
141-
#
142-
# - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
143-
# with:
144-
# ref: ${{ github.event.pull_request.head.sha }}
145-
# repository: ${{ github.event.pull_request.head.repo.full_name }}
146-
#
147-
# - name: Set up GraalVM
148-
# uses: graalvm/setup-graalvm@b11d36630f94ed5864e0a680a979b5afde449e9d
149-
# with:
150-
# version: 'latest'
151-
# java-version: '17'
152-
# components: 'native-image'
153-
# github-token: ${{ secrets.GITHUB_TOKEN }}
154-
#
155-
# - id: 'auth'
156-
# name: Authenticate to Google Cloud
157-
# uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d # v1.0.0
158-
# with:
159-
# workload_identity_provider: ${{ secrets.PROVIDER_NAME }}
160-
# service_account: ${{ secrets.SERVICE_ACCOUNT }}
161-
# access_token_lifetime: 600s
162-
#
163-
# - id: 'secrets'
164-
# name: Get Secrets
165-
# uses: google-github-actions/get-secretmanager-secrets@7fced8b6579c75d7c465165b38ec29175d9a469c # v1.0.0
166-
# with:
167-
# secrets: |-
168-
# ALLOYDB_INSTANCE_URI:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_URI
169-
# ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS
170-
#
171-
# - run: .kokoro/build.sh
172-
# env:
173-
# ALLOYDB_DB: 'postgres'
174-
# ALLOYDB_USER: 'postgres'
175-
# ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}'
176-
# ALLOYDB_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_URI }}'
177-
# JOB_TYPE: graalvm17
178-
# shell: bash
179-
#
180-
# - name: FlakyBot
181-
# # only run flakybot on periodic (schedule) and continuous (push) events
182-
# if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Linux' && always() }}
183-
# run: |
184-
# curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
185-
# chmod +x ./flakybot
186-
# ./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
187-
#
114+
graalvm17:
115+
# run job on periodic (schedule) event
116+
if: "${{ github.event_name == 'schedule' }}"
117+
name: graalvm17
118+
runs-on: [self-hosted, linux, x64]
119+
permissions:
120+
contents: "read"
121+
id-token: "write"
122+
issues: write
123+
pull-requests: write
124+
steps:
125+
- name: Remove PR label
126+
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
127+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
128+
with:
129+
github-token: ${{ secrets.GITHUB_TOKEN }}
130+
script: |
131+
try {
132+
await github.rest.issues.removeLabel({
133+
name: 'tests: run',
134+
owner: context.repo.owner,
135+
repo: context.repo.repo,
136+
issue_number: context.payload.pull_request.number
137+
});
138+
} catch (e) {
139+
console.log('Failed to remove label. Another job may have already removed it!');
140+
}
141+
142+
- name: Checkout code
143+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
144+
with:
145+
ref: ${{ github.event.pull_request.head.sha }}
146+
repository: ${{ github.event.pull_request.head.repo.full_name }}
147+
148+
- name: Setup Maven Action
149+
uses: s4u/setup-maven-action@57ca7f1a813fd21035f9399bc015664601217110
150+
with:
151+
java-version: 17
152+
153+
- name: Set up GraalVM
154+
uses: graalvm/setup-graalvm@v1
155+
with:
156+
distribution: "graalvm"
157+
java-version: "17"
158+
github-token: ${{ secrets.GITHUB_TOKEN }}
159+
160+
- id: "auth"
161+
name: Authenticate to Google Cloud
162+
uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1
163+
with:
164+
workload_identity_provider: ${{ secrets.PROVIDER_NAME }}
165+
service_account: ${{ secrets.SERVICE_ACCOUNT }}
166+
access_token_lifetime: 600s
167+
168+
- id: "secrets"
169+
name: Get Secrets
170+
uses: google-github-actions/get-secretmanager-secrets@4d6d3dfd94110800dda8d84109cb6da0f6a5919d # v1.0.1
171+
with:
172+
secrets: |-
173+
ALLOYDB_INSTANCE_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_URI
174+
ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS
175+
ALLOYDB_IAM_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_JAVA_IAM_USER
176+
ALLOYDB_INSTANCE_IP:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_IP
177+
ALLOYDB_IMPERSONATED_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/IMPERSONATED_USER
178+
179+
- name: Run tests
180+
env:
181+
ALLOYDB_DB: 'postgres'
182+
ALLOYDB_USER: 'postgres'
183+
ALLOYDB_IAM_USER: '${{ steps.secrets.outputs.ALLOYDB_IAM_USER }}'
184+
ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}'
185+
ALLOYDB_INSTANCE_NAME: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_NAME }}'
186+
ALLOYDB_INSTANCE_IP: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_IP }}'
187+
ALLOYDB_IMPERSONATED_USER: '${{ steps.secrets.outputs.ALLOYDB_IMPERSONATED_USER }}'
188+
JOB_TYPE: graalvm17
189+
run: .kokoro/build.sh
190+
shell: bash
191+
192+
- name: FlakyBot
193+
run: |
194+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
195+
chmod +x ./flakybot
196+
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
188197
189198
unitsAndE2e:
190199
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label)

alloydb-jdbc-connector/pom.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
<properties>
4242
<bouncycastle.version>1.76</bouncycastle.version>
43+
<postgresql.version>42.6.0</postgresql.version>
4344
</properties>
4445

4546
<build>
@@ -101,7 +102,7 @@
101102
<dependency>
102103
<groupId>org.postgresql</groupId>
103104
<artifactId>postgresql</artifactId>
104-
<version>42.6.0</version>
105+
<version>${postgresql.version}</version>
105106
<scope>provided</scope>
106107
</dependency>
107108

@@ -167,5 +168,33 @@
167168
<scope>test</scope>
168169
</dependency>
169170

171+
<!-- com.google.cloud.alloydb.nativeimage.AlloyDBFeature needs the GraalVM
172+
dependencies for compilation. The provided-scope dependencies do not add
173+
additional dependencies to library users. -->
174+
<dependency>
175+
<groupId>org.graalvm.sdk</groupId>
176+
<artifactId>graal-sdk</artifactId>
177+
<version>22.0.0</version>
178+
<scope>provided</scope>
179+
</dependency>
180+
170181
</dependencies>
182+
183+
<profiles>
184+
<!-- The native maven plugin leaves provided scope dependencies out of the
185+
classpath, so adding these drivers back in for the native profile is a
186+
workaround.
187+
-->
188+
<profile>
189+
<id>native</id>
190+
<dependencies>
191+
<dependency>
192+
<groupId>org.postgresql</groupId>
193+
<artifactId>postgresql</artifactId>
194+
<version>${postgresql.version}</version>
195+
<scope>test</scope>
196+
</dependency>
197+
</dependencies>
198+
</profile>
199+
</profiles>
171200
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.alloydb.nativeimage;
17+
18+
import com.google.api.gax.nativeimage.NativeImageUtils;
19+
import org.graalvm.nativeimage.hosted.Feature;
20+
import org.graalvm.nativeimage.hosted.RuntimeReflection;
21+
22+
/**
23+
* Registers GraalVM configuration for the AlloyDB libraries.
24+
*
25+
* <p>This class is only used when this library is used in <a
26+
* href="https://www.graalvm.org/22.0/reference-manual/native-image/">GraalVM native image</a>
27+
* compilation.
28+
*/
29+
class AlloyDBFeature implements Feature {
30+
31+
private static final String ALLOYDB_SOCKET_CLASS = "com.google.cloud.alloydb.SocketFactory";
32+
33+
@Override
34+
public void beforeAnalysis(BeforeAnalysisAccess access) {
35+
if (access.findClassByName(ALLOYDB_SOCKET_CLASS) == null) {
36+
return;
37+
}
38+
39+
// Register AlloyDB Socket.
40+
NativeImageUtils.registerClassForReflection(access, ALLOYDB_SOCKET_CLASS);
41+
42+
// Register PostgreSQL driver config.
43+
NativeImageUtils.registerClassForReflection(access, "org.postgresql.PGProperty");
44+
45+
// Register Hikari configs if used with AlloyDB.
46+
if (access.findClassByName("com.zaxxer.hikari.HikariConfig") != null) {
47+
NativeImageUtils.registerClassForReflection(access, "com.zaxxer.hikari.HikariConfig");
48+
49+
RuntimeReflection.register(
50+
access.findClassByName("[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;"));
51+
52+
RuntimeReflection.register(access.findClassByName("[Ljava.sql.Statement;"));
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Args =\
2+
-H:+AddAllCharsets \
3+
--features=com.google.cloud.alloydb.nativeimage.AlloyDBFeature

pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<site.installationModule>alloydb-connector-parent</site.installationModule>
6161
<project.javadoc.protobufBaseURL>https://googleapis.dev/java/google-api-grpc/latest</project.javadoc.protobufBaseURL>
6262
<error-prone.version>2.23.0</error-prone.version>
63+
<native-image.version>0.9.28</native-image.version>
6364
</properties>
6465

6566
<dependencyManagement>
@@ -164,12 +165,80 @@
164165
<goals>
165166
<goal>report</goal>
166167
</goals>
168+
<configuration>
169+
<excludes>
170+
<!-- Native image test is not part of coverage execution -->
171+
<exclude>com/google/cloud/alloydb/nativeimage/*</exclude>
172+
</excludes>
173+
</configuration>
167174
</execution>
168175
</executions>
169176
</plugin>
170177
</plugins>
171178
</build>
172179
</profile>
180+
181+
<profile>
182+
<!-- This profile is used to enable GraalVM native image testing
183+
(.kokoro/graalvm-native/linux) -->
184+
<id>native</id>
185+
<dependencyManagement>
186+
<!-- Controlling version for dependencyConvergence enforcer rule -->
187+
<dependencies>
188+
<dependency>
189+
<groupId>org.junit.platform</groupId>
190+
<artifactId>junit-platform-engine</artifactId>
191+
<version>1.10.0</version>
192+
</dependency>
193+
<dependency>
194+
<groupId>org.junit.platform</groupId>
195+
<artifactId>junit-platform-commons</artifactId>
196+
<version>1.10.0</version>
197+
</dependency>
198+
</dependencies>
199+
</dependencyManagement>
200+
<dependencies>
201+
<!-- GraalVM native image test needs newer JUnit platform -->
202+
<dependency>
203+
<groupId>org.junit.vintage</groupId>
204+
<artifactId>junit-vintage-engine</artifactId>
205+
<version>5.10.0</version>
206+
<scope>test</scope>
207+
</dependency>
208+
<dependency>
209+
<groupId>org.graalvm.buildtools</groupId>
210+
<artifactId>junit-platform-native</artifactId>
211+
<version>${native-image.version}</version>
212+
<scope>test</scope>
213+
</dependency>
214+
</dependencies>
215+
<build>
216+
<plugins>
217+
<plugin>
218+
<groupId>org.graalvm.buildtools</groupId>
219+
<artifactId>native-maven-plugin</artifactId>
220+
<version>${native-image.version}</version>
221+
<extensions>true</extensions>
222+
<executions>
223+
<execution>
224+
<id>test-native</id>
225+
<goals>
226+
<goal>test</goal>
227+
</goals>
228+
<phase>test</phase>
229+
</execution>
230+
</executions>
231+
<configuration>
232+
<buildArgs>
233+
<buildArg>--no-fallback</buildArg>
234+
<buildArg>--no-server</buildArg>
235+
<buildArg>-Ob</buildArg>
236+
</buildArgs>
237+
</configuration>
238+
</plugin>
239+
</plugins>
240+
</build>
241+
</profile>
173242
</profiles>
174243

175244
<modules>

0 commit comments

Comments
 (0)