Skip to content

Commit 73d9fa3

Browse files
AnshulPatniAnshul Patni
andauthored
chore(release): setup kokoro builds (#389)
Co-authored-by: Anshul Patni <anshulpatni@google.com>
1 parent a765214 commit 73d9fa3

4 files changed

Lines changed: 162 additions & 105 deletions

File tree

.kokoro/build.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- protobuffer -*-
2+
# proto-file: google3/devtools/kokoro/config/proto/build.proto
3+
# proto-message: BuildConfig
4+
5+
build_file: "functions-framework-java/.kokoro/build.sh"
6+
container_properties {
7+
# Use the full image which has Java, Maven, and gcloud CLI pre-installed
8+
docker_image: "us-central1-docker.pkg.dev/kokoro-container-bakery/kokoro/ubuntu/ubuntu2204/full:current"
9+
}
10+
11+
fileset_artifacts {
12+
name: "artifacts"
13+
# We will copy the built jars to this folder in build.sh for signing
14+
artifact_globs: "artifacts/*"
15+
error_if_missing: true
16+
destinations {
17+
store_attestation: true
18+
gcs {
19+
gcs_root_path: "oss-exit-gate-prod-projects-bucket/ff-releases/mavencentral/attestations"
20+
}
21+
}
22+
generate_sbom_from_fileset: true
23+
generate_attestation: true
24+
}

.kokoro/build.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# The repo is cloned to $KOKORO_ARTIFACTS_DIR/git/functions-framework-java
5+
REPO_DIR="${KOKORO_ARTIFACTS_DIR}/git/functions-framework-java"
6+
cd "${REPO_DIR}"
7+
8+
# ==============================================================================
9+
# 1. Configure Airlock and AR Credentials
10+
# ==============================================================================
11+
# Get OAuth token from GCE metadata server inside Kokoro VM
12+
MAVEN_TOKEN=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google" | grep -oP '"access_token":"\K[^"]+')
13+
14+
# Create a temporary settings.xml to configure Airlock mirror and AR auth
15+
cat > settings.xml <<EOF
16+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
17+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
19+
<mirrors>
20+
<!-- Redirect ALL downloads to Airlock Maven Central mirror -->
21+
<mirror>
22+
<id>airlock-mirror</id>
23+
<name>Airlock Maven Central mirror</name>
24+
<url>https://us-maven.pkg.dev/artifact-foundry-prod/maven-3p-trusted</url>
25+
<mirrorOf>*</mirrorOf>
26+
</mirror>
27+
</mirrors>
28+
<servers>
29+
<!-- Credentials for the Airlock mirror -->
30+
<server>
31+
<id>airlock-mirror</id>
32+
<username>oauth2accesstoken</username>
33+
<password>${MAVEN_TOKEN}</password>
34+
</server>
35+
<!-- Credentials for the Exit Gate AR deployment repo -->
36+
<server>
37+
<id>exit-gate-ar</id>
38+
<username>oauth2accesstoken</username>
39+
<password>${MAVEN_TOKEN}</password>
40+
</server>
41+
</servers>
42+
</settings>
43+
EOF
44+
45+
# ==============================================================================
46+
# 2. Retrieve GPG keys from Secret Manager
47+
# ==============================================================================
48+
GPG_KEYRING="${KOKORO_ARTIFACTS_DIR}/gpg-keyring"
49+
GPG_PASSPHRASE_FILE="${KOKORO_ARTIFACTS_DIR}/gpg-passphrase"
50+
51+
# Read names from environment variables injected by Louhi
52+
PROJECT_ID="${_LOUHI_SECRET_PROJECT_ID}"
53+
KEYRING_NAME="${_LOUHI_GPG_KEYRING_SECRET_NAME}"
54+
PASSPHRASE_NAME="${_LOUHI_GPG_PASSPHRASE_SECRET_NAME}"
55+
56+
echo "Fetching secrets from project: ${PROJECT_ID}"
57+
gcloud secrets versions access latest --secret="${KEYRING_NAME}" --project="${PROJECT_ID}" > "${GPG_KEYRING}"
58+
gcloud secrets versions access latest --secret="${PASSPHRASE_NAME}" --project="${PROJECT_ID}" > "${GPG_PASSPHRASE_FILE}"
59+
60+
export GPG_TTY=$(tty)
61+
export GPG_PASSPHRASE=$(cat "${GPG_PASSPHRASE_FILE}")
62+
export GNUPGHOME=/tmp/gpg
63+
mkdir -p "${GNUPGHOME}"
64+
gpg --batch --import "${GPG_KEYRING}"
65+
66+
# ==============================================================================
67+
# 3. Build, Sign, and Deploy
68+
# ==============================================================================
69+
# Detect which package to build based on the Louhi trigger tag
70+
if [[ -n "${_LOUHI_REF_NAME:-}" ]]; then
71+
echo "Triggered by Louhi tag: ${_LOUHI_REF_NAME}"
72+
if [[ "${_LOUHI_REF_NAME}" == *functions-framework-api* ]]; then
73+
PACKAGE_DIR="functions-framework-api"
74+
elif [[ "${_LOUHI_REF_NAME}" == *function-maven-plugin* ]]; then
75+
PACKAGE_DIR="function-maven-plugin"
76+
elif [[ "${_LOUHI_REF_NAME}" == *java-function-invoker* ]]; then
77+
PACKAGE_DIR="invoker"
78+
else
79+
echo "Unknown tag format: ${_LOUHI_REF_NAME}. Defaulting to invoker."
80+
PACKAGE_DIR="invoker"
81+
fi
82+
else
83+
# Fallback for manual/non-tag builds (e.g. testing)
84+
echo "No Louhi tag detected. Falling back to KOKORO_JOB_NAME detection."
85+
if [[ $KOKORO_JOB_NAME == *"function-maven-plugin"* ]]; then
86+
PACKAGE_DIR="function-maven-plugin"
87+
elif [[ $KOKORO_JOB_NAME == *"functions-framework-api"* ]]; then
88+
PACKAGE_DIR="functions-framework-api"
89+
else
90+
PACKAGE_DIR="invoker"
91+
fi
92+
fi
93+
94+
echo "Building package in directory: ${PACKAGE_DIR}"
95+
cd "${PACKAGE_DIR}"
96+
97+
# Run maven deploy using the temporary settings.xml
98+
# We use altDeploymentRepository to override the deploy target without editing pom.xml
99+
mvn clean deploy -B \
100+
-P sonatype-oss-release \
101+
--settings=../settings.xml \
102+
-DaltDeploymentRepository=exit-gate-ar::https://us-maven.pkg.dev/oss-exit-gate-prod/ff-releases--mavencentral \
103+
-Dgpg.executable=gpg \
104+
-Dgpg.passphrase="${GPG_PASSPHRASE}" \
105+
-Dgpg.homedir="${GNUPGHOME}"
106+
107+
# ==============================================================================
108+
# 4. Copy artifacts to 'artifacts/' folder for Kokoro Attestation Generation
109+
# ==============================================================================
110+
ARTIFACTS_DIR="${REPO_DIR}/artifacts"
111+
mkdir -p "${ARTIFACTS_DIR}"
112+
113+
# Copy target jars and poms (excluding test jars) to be captured by build.cfg
114+
find target/ -maxdepth 1 -name "*.jar" -o -name "*.pom" | grep -v "test" | xargs -I {} cp {} "${ARTIFACTS_DIR}/"

.kokoro/release.cfg

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1+
# -*- protobuffer -*-
2+
# proto-file: google3/devtools/kokoro/config/proto/build.proto
3+
# proto-message: BuildConfig
4+
15
build_file: "functions-framework-java/.kokoro/release.sh"
6+
container_properties {
7+
docker_image: "us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/ubuntu:22.04"
8+
}
29

3-
before_action {
4-
fetch_keystore {
5-
keystore_resource {
6-
keystore_config_id: 75669
7-
keyname: "functions-framework-java-release-bot-sonatype-password"
8-
}
9-
keystore_resource {
10-
keystore_config_id: 75669
11-
keyname: "functions-framework-release-sonatype-central-portal-username"
12-
}
13-
keystore_resource {
14-
keystore_config_id: 75669
15-
keyname: "functions-framework-release-sonatype-central-portal-password"
16-
}
17-
keystore_resource {
18-
keystore_config_id: 70247
19-
keyname: "maven-gpg-pubkeyring"
20-
}
21-
keystore_resource {
22-
keystore_config_id: 70247
23-
keyname: "maven-gpg-keyring"
24-
}
25-
keystore_resource {
26-
keystore_config_id: 70247
27-
keyname: "maven-gpg-passphrase"
10+
fileset_artifacts {
11+
name: "manifest"
12+
artifact_globs: "manifest.json"
13+
error_if_missing: true
14+
destinations {
15+
store_attestation: false
16+
gcs {
17+
gcs_root_path: "oss-exit-gate-prod-projects-bucket/ff-releases/mavencentral/manifests"
18+
populate_content_type: true
2819
}
2920
}
21+
generate_sbom_from_fileset: false
22+
generate_attestation: false
3023
}

.kokoro/release.sh

100644100755
Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,10 @@
11
#!/bin/bash
2+
set -euo pipefail
23

3-
# Stop execution when any command fails.
4-
set -e
4+
cd "${KOKORO_ARTIFACTS_DIR}"
55

6-
# update the Maven version to 3.9.11
7-
pushd /usr/local
8-
wget https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.tar.gz
9-
tar -xvzf apache-maven-3.9.11-bin.tar.gz apache-maven-3.9.11
10-
rm -f /usr/local/apache-maven
11-
ln -s /usr/local/apache-maven-3.9.11 /usr/local/apache-maven
12-
rm apache-maven-3.9.11-bin.tar.gz
13-
popd
14-
15-
16-
# Get secrets from keystore and set and environment variables.
17-
setup_environment_secrets() {
18-
export GPG_TTY=$(tty)
19-
export GPG_PASSPHRASE=$(cat ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-passphrase)
20-
21-
# Add the key ring files to $GNUPGHOME to verify the GPG credentials.
22-
export GNUPGHOME=/tmp/gpg
23-
mkdir $GNUPGHOME
24-
mv ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-pubkeyring $GNUPGHOME/pubring.gpg
25-
mv ${KOKORO_KEYSTORE_DIR}/70247_maven-gpg-keyring $GNUPGHOME/secring.gpg
26-
gpg -k
27-
}
28-
29-
create_settings_xml_file() {
30-
echo "<settings>
31-
<profiles>
32-
<profile>
33-
<activation>
34-
<activeByDefault>true</activeByDefault>
35-
</activation>
36-
<properties>
37-
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
38-
</properties>
39-
</profile>
40-
</profiles>
41-
<servers>
42-
<server>
43-
<id>sonatype-central-portal</id>
44-
<username>$(cat "${KOKORO_KEYSTORE_DIR}/75669_functions-framework-release-sonatype-central-portal-username")</username>
45-
<password>$(cat "${KOKORO_KEYSTORE_DIR}/75669_functions-framework-release-sonatype-central-portal-password")</password>
46-
</server>
47-
</servers>
48-
</settings>" > $1
6+
cat > manifest.json <<'EOF'
7+
{
8+
"publish_all": true
499
}
50-
51-
setup_environment_secrets
52-
53-
# Pick the right package to release based on the Kokoro job name.
54-
cd ${KOKORO_ARTIFACTS_DIR}/github/functions-framework-java
55-
create_settings_xml_file "settings.xml"
56-
echo "KOKORO_JOB_NAME=${KOKORO_JOB_NAME}"
57-
if [[ $KOKORO_JOB_NAME == *"function-maven-plugin"* ]]; then
58-
cd function-maven-plugin
59-
elif [[ $KOKORO_JOB_NAME == *"functions-framework-api"* ]]; then
60-
cd functions-framework-api
61-
else
62-
cd invoker
63-
fi
64-
echo "pwd=$(pwd)"
65-
66-
# Make sure `JAVA_HOME` is set and using jdk17.
67-
JDK_VERSION=17
68-
apt-get update
69-
# Install new JDK version
70-
apt-get install -y openjdk-"${JDK_VERSION}"-jdk
71-
export JAVA_HOME="$(update-java-alternatives -l | grep "1.${JDK_VERSION}" | head -n 1 | tr -s " " | cut -d " " -f 3)"
72-
echo "JAVA_HOME=$JAVA_HOME"
73-
74-
SUPPRESS_LOGS='-q'
75-
if [[ -n "${ENABLE_LOGS}" ]]; then
76-
SUPPRESS_LOGS=''
77-
fi
78-
79-
mvn clean deploy -B ${SUPPRESS_LOGS} \
80-
-P sonatype-oss-release \
81-
--settings=../settings.xml \
82-
-Dgpg.executable=gpg \
83-
-Dgpg.passphrase=${GPG_PASSPHRASE} \
84-
-Dgpg.homedir=${GNUPGHOME}
10+
EOF

0 commit comments

Comments
 (0)