Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for GraalVM build #228

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"semanticCommits": "enabled",
"dependencyDashboard": true,
"dependencyDashboardLabels": ["type: process"],
"ignoreDeps": [
"org.graalvm.sdk:graal-sdk"
],
"packageRules": [
{
"matchPackagePatterns": [
Expand Down
1 change: 0 additions & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ branchProtectionRules:
- "lint"
- "units (8)"
- "units (11)"
# - "graalvm17"
- "units + e2e"
- "cla/google"
# Wait until we make the repo public before bringing this back
Expand Down
157 changes: 83 additions & 74 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,80 +111,89 @@ jobs:
env:
JOB_TYPE: clirr

# graalvm17:
# # 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)
# 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' }}"
# name: graalvm17
# runs-on: ubuntu-latest
# permissions:
# contents: 'read'
# id-token: 'write'
# issues: write
# pull-requests: write
# steps:
# - name: Remove PR label
# if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
# uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# try {
# await github.rest.issues.removeLabel({
# name: 'tests: run',
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: context.payload.pull_request.number
# });
# } catch (e) {
# console.log('Failed to remove label. Another job may have already removed it!');
# }
#
# - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
# with:
# ref: ${{ github.event.pull_request.head.sha }}
# repository: ${{ github.event.pull_request.head.repo.full_name }}
#
# - name: Set up GraalVM
# uses: graalvm/setup-graalvm@b11d36630f94ed5864e0a680a979b5afde449e9d
# with:
# version: 'latest'
# java-version: '17'
# components: 'native-image'
# github-token: ${{ secrets.GITHUB_TOKEN }}
#
# - id: 'auth'
# name: Authenticate to Google Cloud
# uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d # v1.0.0
# with:
# workload_identity_provider: ${{ secrets.PROVIDER_NAME }}
# service_account: ${{ secrets.SERVICE_ACCOUNT }}
# access_token_lifetime: 600s
#
# - id: 'secrets'
# name: Get Secrets
# uses: google-github-actions/get-secretmanager-secrets@7fced8b6579c75d7c465165b38ec29175d9a469c # v1.0.0
# with:
# secrets: |-
# ALLOYDB_INSTANCE_URI:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_URI
# ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS
#
# - run: .kokoro/build.sh
# env:
# ALLOYDB_DB: 'postgres'
# ALLOYDB_USER: 'postgres'
# ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}'
# ALLOYDB_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_URI }}'
# JOB_TYPE: graalvm17
# shell: bash
#
# - name: FlakyBot
# # only run flakybot on periodic (schedule) and continuous (push) events
# if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Linux' && always() }}
# run: |
# curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
# chmod +x ./flakybot
# ./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
#
graalvm17:
# run job on periodic (schedule) event
if: "${{ github.event_name == 'schedule' }}"
name: graalvm17
runs-on: [self-hosted, linux, x64]
permissions:
contents: "read"
id-token: "write"
issues: write
pull-requests: write
steps:
- name: Remove PR label
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'tests: run',
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
} catch (e) {
console.log('Failed to remove label. Another job may have already removed it!');
}

- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Setup Maven Action
uses: s4u/setup-maven-action@57ca7f1a813fd21035f9399bc015664601217110
with:
java-version: 17

- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
with:
distribution: "graalvm"
java-version: "17"
github-token: ${{ secrets.GITHUB_TOKEN }}

- id: "auth"
name: Authenticate to Google Cloud
uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1
with:
workload_identity_provider: ${{ secrets.PROVIDER_NAME }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
access_token_lifetime: 600s

- id: "secrets"
name: Get Secrets
uses: google-github-actions/get-secretmanager-secrets@4d6d3dfd94110800dda8d84109cb6da0f6a5919d # v1.0.1
with:
secrets: |-
ALLOYDB_INSTANCE_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_URI
ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS
ALLOYDB_IAM_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_JAVA_IAM_USER
ALLOYDB_INSTANCE_IP:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_IP
ALLOYDB_IMPERSONATED_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/IMPERSONATED_USER

- name: Run tests
env:
ALLOYDB_DB: 'postgres'
ALLOYDB_USER: 'postgres'
ALLOYDB_IAM_USER: '${{ steps.secrets.outputs.ALLOYDB_IAM_USER }}'
ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}'
ALLOYDB_INSTANCE_NAME: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_NAME }}'
ALLOYDB_INSTANCE_IP: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_IP }}'
ALLOYDB_IMPERSONATED_USER: '${{ steps.secrets.outputs.ALLOYDB_IMPERSONATED_USER }}'
JOB_TYPE: graalvm17
run: .kokoro/build.sh
shell: bash

- name: FlakyBot
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

unitsAndE2e:
# 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)
Expand Down
31 changes: 30 additions & 1 deletion alloydb-jdbc-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<properties>
<bouncycastle.version>1.76</bouncycastle.version>
<postgresql.version>42.6.0</postgresql.version>
</properties>

<build>
Expand Down Expand Up @@ -101,7 +102,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
<version>${postgresql.version}</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -167,5 +168,33 @@
<scope>test</scope>
</dependency>

<!-- com.google.cloud.alloydb.nativeimage.AlloyDBFeature needs the GraalVM
dependencies for compilation. The provided-scope dependencies do not add
additional dependencies to library users. -->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>22.0.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

<profiles>
<!-- The native maven plugin leaves provided scope dependencies out of the
classpath, so adding these drivers back in for the native profile is a
workaround.
-->
<profile>
<id>native</id>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
jackwotherspoon marked this conversation as resolved.
Show resolved Hide resolved
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.alloydb.nativeimage;

import com.google.api.gax.nativeimage.NativeImageUtils;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

/**
* Registers GraalVM configuration for the AlloyDB libraries.
*
* <p>This class is only used when this library is used in <a
* href="https://www.graalvm.org/22.0/reference-manual/native-image/">GraalVM native image</a>
* compilation.
*/
class AlloyDBFeature implements Feature {

private static final String ALLOYDB_SOCKET_CLASS = "com.google.cloud.alloydb.SocketFactory";

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (access.findClassByName(ALLOYDB_SOCKET_CLASS) == null) {
return;
}

// Register AlloyDB Socket.
NativeImageUtils.registerClassForReflection(access, ALLOYDB_SOCKET_CLASS);

// Register PostgreSQL driver config.
NativeImageUtils.registerClassForReflection(access, "org.postgresql.PGProperty");

// Register Hikari configs if used with AlloyDB.
if (access.findClassByName("com.zaxxer.hikari.HikariConfig") != null) {
NativeImageUtils.registerClassForReflection(access, "com.zaxxer.hikari.HikariConfig");

RuntimeReflection.register(
access.findClassByName("[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;"));

RuntimeReflection.register(access.findClassByName("[Ljava.sql.Statement;"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Args =\
-H:+AddAllCharsets \
--features=com.google.cloud.alloydb.nativeimage.AlloyDBFeature
69 changes: 69 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<site.installationModule>alloydb-connector-parent</site.installationModule>
<project.javadoc.protobufBaseURL>https://googleapis.dev/java/google-api-grpc/latest</project.javadoc.protobufBaseURL>
<error-prone.version>2.23.0</error-prone.version>
<native-image.version>0.9.28</native-image.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -164,12 +165,80 @@
<goals>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<!-- Native image test is not part of coverage execution -->
<exclude>com/google/cloud/alloydb/nativeimage/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<!-- This profile is used to enable GraalVM native image testing
(.kokoro/graalvm-native/linux) -->
<id>native</id>
<dependencyManagement>
<!-- Controlling version for dependencyConvergence enforcer rule -->
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.10.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- GraalVM native image test needs newer JUnit platform -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>junit-platform-native</artifactId>
<version>${native-image.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-image.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>
<buildArgs>
<buildArg>--no-fallback</buildArg>
<buildArg>--no-server</buildArg>
<buildArg>-Ob</buildArg>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<modules>
Expand Down
Loading