|
| 1 | +# Google Cloud Build - Spanner PG Starter Release Pipeline |
| 2 | +# Automates compiling the starter code, JRE stripping, packaging, and deploying to GCS. |
| 3 | + |
| 4 | +substitutions: |
| 5 | + _VERSION: '0.0.0' |
| 6 | + _AR_LOCATION: 'us-central1' |
| 7 | + _AR_REPOSITORY: 'spanner-pg-starter' |
| 8 | + |
| 9 | +steps: |
| 10 | + # Step 1: Compile and package the fat JAR using the shade-starter profile (JDK 25) |
| 11 | + - name: 'mirror.gcr.io/library/maven:3.9-eclipse-temurin-25' |
| 12 | + id: 'build-jar' |
| 13 | + entrypoint: 'mvn' |
| 14 | + args: ['-Pshade-starter', '-DskipTests', '-Dfmt.skip', 'clean', 'package'] |
| 15 | + |
| 16 | + # Step 2: Assemble the minimal platform-specific JREs via jlink cross-linking (JDK 25) |
| 17 | + - name: 'mirror.gcr.io/library/eclipse-temurin:25' |
| 18 | + id: 'link-jre' |
| 19 | + entrypoint: 'sh' |
| 20 | + args: |
| 21 | + - '-c' |
| 22 | + - | |
| 23 | + set -e |
| 24 | + apt-get update && apt-get install -y unzip curl |
| 25 | + |
| 26 | + JDK_VER="jdk-25.0.3+9" |
| 27 | + |
| 28 | + mkdir -p /tmp/downloads /tmp/jmods |
| 29 | + |
| 30 | + # Download target JMOD packages directly from Adoptium APIs |
| 31 | + curl -fsSL -o /tmp/downloads/linux-x64.tar.gz "https://api.adoptium.net/v3/binary/latest/25/ga/linux/x64/jmods/hotspot/normal/eclipse" |
| 32 | + curl -fsSL -o /tmp/downloads/mac-aarch64.tar.gz "https://api.adoptium.net/v3/binary/latest/25/ga/mac/aarch64/jmods/hotspot/normal/eclipse" |
| 33 | + curl -fsSL -o /tmp/downloads/mac-x64.tar.gz "https://api.adoptium.net/v3/binary/latest/25/ga/mac/x64/jmods/hotspot/normal/eclipse" |
| 34 | + curl -fsSL -o /tmp/downloads/windows-x64.zip "https://api.adoptium.net/v3/binary/latest/25/ga/windows/x64/jmods/hotspot/normal/eclipse" |
| 35 | + |
| 36 | + # Extract target JMOD directories |
| 37 | + tar -xzf /tmp/downloads/linux-x64.tar.gz -C /tmp/ |
| 38 | + mv "/tmp/$${JDK_VER}-jmods" /tmp/jmods/linux-x64 |
| 39 | + |
| 40 | + tar -xzf /tmp/downloads/mac-aarch64.tar.gz -C /tmp/ |
| 41 | + mv "/tmp/$${JDK_VER}-jmods" /tmp/jmods/mac-aarch64 |
| 42 | + |
| 43 | + tar -xzf /tmp/downloads/mac-x64.tar.gz -C /tmp/ |
| 44 | + mv "/tmp/$${JDK_VER}-jmods" /tmp/jmods/mac-x64 |
| 45 | + |
| 46 | + unzip -q /tmp/downloads/windows-x64.zip -d /tmp/ |
| 47 | + mv "/tmp/$${JDK_VER}-jmods" /tmp/jmods/windows-x64 |
| 48 | + |
| 49 | + # Strip JRE to the bare minimum required for PGAdapter and Spanner Clients |
| 50 | + # Excludes unused desktop/GUI, RMI, scripting, and compiler modules |
| 51 | + MODULES="java.base,java.management,java.naming,java.security.jgss,java.sql,jdk.unsupported,jdk.crypto.cryptoki,jdk.crypto.ec" |
| 52 | + |
| 53 | + # Execute cross-linking using the host JVM's native jlink command |
| 54 | + jlink --module-path /tmp/jmods/linux-x64 --add-modules $${MODULES} --strip-debug --no-man-pages --no-header-files --compress=zip-9 --output target/custom-jres/linux-x64 |
| 55 | + jlink --module-path /tmp/jmods/mac-aarch64 --add-modules $${MODULES} --strip-debug --no-man-pages --no-header-files --compress=zip-9 --output target/custom-jres/mac-aarch64 |
| 56 | + jlink --module-path /tmp/jmods/mac-x64 --add-modules $${MODULES} --strip-debug --no-man-pages --no-header-files --compress=zip-9 --output target/custom-jres/mac-x64 |
| 57 | + jlink --module-path /tmp/jmods/windows-x64 --add-modules $${MODULES} --strip-debug --no-man-pages --no-header-files --compress=zip-9 --output target/custom-jres/windows-x64 |
| 58 | +
|
| 59 | + # Step 3: Bundle assets into target platform packages |
| 60 | + - name: 'mirror.gcr.io/library/alpine:3.20' |
| 61 | + id: 'package-bundle' |
| 62 | + entrypoint: 'sh' |
| 63 | + args: |
| 64 | + - '-c' |
| 65 | + - | |
| 66 | + apk add --no-cache zip |
| 67 | + |
| 68 | + mkdir -p target/release/versioned-package target/release/latest-assets |
| 69 | + |
| 70 | + # Linux x64 |
| 71 | + mkdir -p target/dist/linux-x64 |
| 72 | + cp target/pgadapter.jar target/dist/linux-x64/ |
| 73 | + cp -r target/custom-jres/linux-x64 target/dist/linux-x64/custom-jre |
| 74 | + cp starter/spanner-pg-starter target/dist/linux-x64/ |
| 75 | + tar -czf target/release/versioned-package/spanner-pg-starter-linux-x64.tar.gz -C target/dist/linux-x64 spanner-pg-starter pgadapter.jar custom-jre/ |
| 76 | + |
| 77 | + # macOS aarch64 |
| 78 | + mkdir -p target/dist/mac-aarch64 |
| 79 | + cp target/pgadapter.jar target/dist/mac-aarch64/ |
| 80 | + cp -r target/custom-jres/mac-aarch64 target/dist/mac-aarch64/custom-jre |
| 81 | + cp starter/spanner-pg-starter target/dist/mac-aarch64/ |
| 82 | + tar -czf target/release/versioned-package/spanner-pg-starter-mac-aarch64.tar.gz -C target/dist/mac-aarch64 spanner-pg-starter pgadapter.jar custom-jre/ |
| 83 | + |
| 84 | + # macOS x64 |
| 85 | + mkdir -p target/dist/mac-x64 |
| 86 | + cp target/pgadapter.jar target/dist/mac-x64/ |
| 87 | + cp -r target/custom-jres/mac-x64 target/dist/mac-x64/custom-jre |
| 88 | + cp starter/spanner-pg-starter target/dist/mac-x64/ |
| 89 | + tar -czf target/release/versioned-package/spanner-pg-starter-mac-x64.tar.gz -C target/dist/mac-x64 spanner-pg-starter pgadapter.jar custom-jre/ |
| 90 | + |
| 91 | + # Windows x64 |
| 92 | + mkdir -p target/dist/windows-x64 |
| 93 | + cp target/pgadapter.jar target/dist/windows-x64/ |
| 94 | + cp -r target/custom-jres/windows-x64 target/dist/windows-x64/custom-jre |
| 95 | + cp starter/spanner-pg-starter.cmd target/dist/windows-x64/ |
| 96 | + cd target/dist/windows-x64 |
| 97 | + zip -q -r ../../release/versioned-package/spanner-pg-starter-windows-x64.zip spanner-pg-starter.cmd pgadapter.jar custom-jre/ |
| 98 | + cd ../../.. |
| 99 | +
|
| 100 | +
|
| 101 | +options: |
| 102 | + requestedVerifyOption: VERIFIED |
| 103 | + logging: CLOUD_LOGGING_ONLY |
| 104 | + |
| 105 | +artifacts: |
| 106 | + generic_artifacts: |
| 107 | + - registry_path: 'projects/${PROJECT_ID}/locations/${_AR_LOCATION}/repositories/${_AR_REPOSITORY}/packages/spanner-pg-starter/versions/${_VERSION}' |
| 108 | + folder: 'target/release/versioned-package' |
| 109 | + |
0 commit comments