Skip to content

Commit 15a1cb4

Browse files
author
Komal Yadav
committed
Implemented exit gate
1 parent 760d9bf commit 15a1cb4

File tree

3 files changed

+230
-78
lines changed

3 files changed

+230
-78
lines changed

.github/workflows/build-and-unit-test.yml

Lines changed: 44 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2022 Cask Data, Inc.
1+
# Copyright © 2025 Cask Data, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
33
# use this file except in compliance with the License. You may obtain a copy of
44
# the License at
@@ -85,10 +85,8 @@ jobs:
8585
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
8686
with:
8787
secrets: |-
88-
CDAP_OSSRH_USERNAME:cdapio-github-builds/CDAP_OSSRH_USERNAME
89-
CDAP_OSSRH_PASSWORD:cdapio-github-builds/CDAP_OSSRH_PASSWORD
90-
CDAP_GPG_PASSPHRASE:cdapio-github-builds/CDAP_GPG_PASSPHRASE
91-
CDAP_GPG_PRIVATE_KEY:cdapio-github-builds/CDAP_GPG_PRIVATE_KEY
88+
artifacts_bucket:cdapio-github-builds/artifacts_bucket
89+
secure_publish_bucket:cdapio-github-builds/publish_bucket
9290
9391
- name: Recursively Checkout Repository
9492
uses: actions/checkout@v4
@@ -151,18 +149,6 @@ jobs:
151149
commit: ${{ github.sha }}
152150
check_name: Test Report - ${{ env.ARTIFACT_NAME }}
153151

154-
- name: Build Standalone
155-
# Pinned version 2.8.2
156-
uses: nick-fields/retry@3e91a01664abd3c5cd539100d10d33b9c5b68482
157-
with:
158-
timeout_minutes: 60
159-
max_attempts: 3
160-
retry_on: error
161-
on_retry_command: echo "Build Standalone failed in this attempt, retrying ..."
162-
command: |
163-
cd cdap-build
164-
MAVEN_OPTS="-Xmx12G" mvn -e -T2 clean package -Dgpg.skip -DskipTests -Ddocker.skip=true -nsu -am -amd -P templates,dist,release -Dadditional.artifacts.dir=$(pwd)/app-artifacts -Dsecurity.extensions.dir=$(pwd)/security-extensions -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.wagon.httpconnectionManager.ttlSeconds=30
165-
166152
- name: Find Build Version
167153
working-directory: cdap-build/cdap
168154
run: |
@@ -180,74 +166,43 @@ jobs:
180166
echo "Release will be overwritten if exists."
181167
fi
182168
183-
- name: Upload CDAP Standalone
184-
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
185-
uses: actions/upload-artifact@v4 # https://github.com/actions/upload-artifact#zipped-artifact-downloads
186-
with:
187-
name: cdap-sandbox-${{env.CDAP_VERSION}}.zip
188-
path: cdap-build/cdap/cdap-standalone/target/cdap-sandbox-${{env.CDAP_VERSION}}.zip
189-
190-
- name: Set up GPG conf
191-
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
169+
- name: Submit Build to GCB
170+
id: gcb
171+
working-directory: cdap-build
192172
run: |
193-
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
194-
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
173+
BUILD_OUTPUT=$(gcloud builds submit . \
174+
--config=cloudbuild-release.yaml \
175+
--project='${{ env.GCP_PROJECT_ID }}' \
176+
--substitutions="_ARTIFACT_ID=cdap-build,_SECURE_PUBLISH_BUCKET_NAME=${{ steps.gcp_secrets.outputs.secure_publish_bucket }},_CDAP_VERSION=${{ env.CDAP_VERSION }}" 2>&1)
177+
echo "$BUILD_OUTPUT"
178+
BUILD_ID=$(echo "$BUILD_OUTPUT" | grep -oP 'ID: \K[a-f0-9-]+' | head -n 1)
179+
if [ -z "$BUILD_ID" ]; then
180+
echo "Failed to extract BUILD_ID from gcloud output." >&2
181+
# Fallback: Get the last build submitted by this service account.
182+
# This assumes no other concurrent builds are started by this SA.
183+
BUILD_ID=$(gcloud builds list --project='${{ env.GCP_PROJECT_ID }}' --limit=1 --format='value(ID)' --filter="buildTriggerId='' AND status!=WORKING AND status!=QUEUED" --sort-by=~CREATE_TIME)
184+
if [ -z "$BUILD_ID" ]; then
185+
echo "Fallback failed to get BUILD_ID." >&2
186+
exit 1
187+
fi
188+
echo "Fallback BUILD_ID: $BUILD_ID"
189+
fi
190+
echo "build_id=$BUILD_ID" >> $GITHUB_OUTPUT
191+
echo "GCB Build ID: $BUILD_ID"
195192
196-
- name: Import GPG key
193+
- name: Create Download Directory
197194
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
198-
run: |
199-
echo "$GPG_PRIVATE_KEY" > private.key
200-
gpg --import --batch private.key
201-
env:
202-
GPG_PRIVATE_KEY: ${{ steps.secrets.outputs.CDAP_GPG_PRIVATE_KEY }}
195+
run: mkdir -p downloads
203196

204-
- name: Maven Deploy
197+
- name: Download CDAP Standalone from GCS
198+
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
205199
run: |
206-
cd cdap-build
207-
if [[ (${{ matrix.branch }} == "develop") || (${{ matrix.branch }} == release/*) ]];
208-
then
209-
retry_count=0
210-
failed_module=""
211-
while [ $retry_count -lt 3 ]; do
212-
if [ -n "$failed_module" ];
213-
then
214-
build_output=$(mvn deploy -B -V -DskipTests -DskipLocalStaging=true -Ddocker.skip=true -P templates,dist,release,rpm-prepare,rpm,deb-prepare,deb,tgz,unit-tests -Dadditional.artifacts.dir=$(pwd)/app-artifacts -Dsecurity.extensions.dir=$(pwd)/security-extensions -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.wagon.httpconnectionManager.ttlSeconds=30 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true -Dgpg.passphrase=$CDAP_GPG_PASSPHRASE -rf :"$failed_module" 2>&1 || true)
215-
else
216-
build_output=$(mvn deploy -B -V -DskipTests -DskipLocalStaging=true -Ddocker.skip=true -P templates,dist,release,rpm-prepare,rpm,deb-prepare,deb,tgz,unit-tests -Dadditional.artifacts.dir=$(pwd)/app-artifacts -Dsecurity.extensions.dir=$(pwd)/security-extensions -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.wagon.httpconnectionManager.ttlSeconds=30 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true -Dgpg.passphrase=$CDAP_GPG_PASSPHRASE 2>&1 || true)
217-
fi
218-
echo "$build_output"
219-
if [ $(echo "$build_output" | grep -c "BUILD FAILURE") -gt 0 ];
220-
then
221-
echo "[WARNING] Deployment failed, retrying..."
222-
failed_module=$(echo "$build_output" | grep -e 'mvn <args> -rf' | sed -n 's/.*mvn <args> -rf ://p')
223-
echo "[INFO] FAILED MODULE = $failed_module"
224-
retry_count=$((retry_count + 1))
225-
else
226-
echo "[INFO] Deployment successful"
227-
break
228-
fi
229-
done
230-
if [ $retry_count -ge 3 ];
231-
then
232-
echo "[ERROR] Max retries reached..., deployment failed"
233-
exit 1
234-
fi
235-
else
236-
mvn verify -B -V -T2 -DskipTests -Dgpg.skip -Ddocker.skip=true -P templates,dist,release,rpm-prepare,rpm,deb-prepare,deb,tgz,unit-tests -Dadditional.artifacts.dir=$(pwd)/app-artifacts -Dsecurity.extensions.dir=$(pwd)/security-extensions -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.wagon.httpconnectionManager.ttlSeconds=30 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true
237-
fi
238-
env:
239-
CDAP_OSSRH_USERNAME: ${{ steps.secrets.outputs.CDAP_OSSRH_USERNAME }}
240-
CDAP_OSSRH_PASSWORD: ${{ steps.secrets.outputs.CDAP_OSSRH_PASSWORD }}
241-
CDAP_GPG_PASSPHRASE: ${{ steps.secrets.outputs.CDAP_GPG_PASSPHRASE }}
242-
MAVEN_OPTS: "-Xmx12G"
200+
gsutil cp gs://${{ steps.gcp_secrets.outputs.secure_publish_bucket }}/cdap/cdap/${{ steps.gcb.outputs.build_id }}/cdap-sandbox-${{ env.CDAP_VERSION }}.zip downloads/
243201
244-
- name: Build DEB Bundle
245-
working-directory: cdap-build/cdap
202+
- name: Download CDAP DEB Bundle from GCS
203+
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
246204
run: |
247-
mkdir -p cdap-distributions/target/deb-bundle-tmp
248-
cd cdap-distributions/target/deb-bundle-tmp
249-
cp ../../../*/target/*.deb .
250-
tar zcf ../cdap-distributed-deb-bundle-${{env.CDAP_VERSION}}.tgz *.deb
205+
gsutil cp gs://${{ steps.gcp_secrets.outputs.secure_publish_bucket }}/cdap/cdap/${{ steps.gcb.outputs.build_id }}/cdap-distributed-deb-bundle-${{ env.CDAP_VERSION }}.tgz downloads/
251206
252207
- name: Set Up Tag
253208
working-directory: cdap-build
@@ -270,6 +225,17 @@ jobs:
270225
git push -f origin refs/tags/${{ env.TAG_NAME }}:refs/tags/${{ env.TAG_NAME }}
271226
fi
272227
228+
- name: 'Download Artifacts from Cloud Storage'
229+
if: ${{ matrix.branch == 'develop' || startsWith(matrix.branch, 'release/') }}
230+
working-directory: cdap-build
231+
run: |
232+
GCS_STAGING_PATH="${{ env.ARTIFACTS_BUCKET }}"
233+
CDAP_VERSION="${{ env.CDAP_VERSION }}"
234+
mkdir -p cdap/cdap-standalone/target
235+
mkdir -p cdap/cdap-distributions/target
236+
gsutil cp "${GCS_STAGING_PATH}/cdap-sandbox-${CDAP_VERSION}.zip" cdap/cdap-standalone/target/
237+
gsutil cp "${GCS_STAGING_PATH}/cdap-distributed-deb-bundle-${CDAP_VERSION}.tgz" cdap/cdap-distributions/target/
238+
273239
- name: Upload CDAP Standalone and CDAP DEB Bundle
274240
# Pinned 1.14.0 version
275241
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5

.github/workflows/cloudbuild.yaml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Copyright © 2025 Cask Data, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
15+
steps:
16+
- name: 'gcr.io/cdapio-github-builds/runner'
17+
id: build-standalone
18+
entrypoint: 'bash'
19+
env:
20+
- 'MAVEN_OPTS=-Xmx12G'
21+
args:
22+
- '-c'
23+
- |
24+
set -ex
25+
26+
yarn global add node-gyp
27+
28+
echo ">>> Running Maven build..."
29+
MVN_CMD="mvn -e -T2 -U clean package \
30+
-Dgpg.skip=true \
31+
-DskipTests=true \
32+
-Ddocker.skip=true \
33+
-Dadditional.artifacts.dir=/workspace/app-artifacts \
34+
-Dsecurity.extensions.dir=/workspace/security-extensions \
35+
-nsu -am -amd \
36+
-Ptemplates,dist,release \
37+
-Dmaven.wagon.http.retryHandler.count=5 \
38+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=30"
39+
$$MVN_CMD
40+
41+
42+
- name: 'gcr.io/cdapio-github-builds/runner'
43+
id: build-distributions
44+
entrypoint: 'bash'
45+
args:
46+
- '-c'
47+
- |
48+
set -ex
49+
echo ">>> Building Distribution Artifacts (DEB, RPM, TGZ)..."
50+
# Run package on the distributions module, 'package' phase without 'clean'
51+
# Assumes dependencies are available from the previous build-standalone step
52+
MAVEN_OPTS="-Xmx12G" mvn -B -V -e -U package \
53+
-DskipTests=true -Dgpg.skip=true -Ddocker.skip=true -nsu \
54+
-P templates,dist,release,rpm-prepare,rpm,deb-prepare,deb,tgz \
55+
-Dadditional.artifacts.dir=/workspace/app-artifacts \
56+
-Dsecurity.extensions.dir=/workspace/security-extensions
57+
echo ">>> Distribution Builds Complete."
58+
waitFor: [ 'build-standalone' ]
59+
60+
- name: 'bash'
61+
id: create-deb-bundle
62+
entrypoint: 'bash'
63+
args:
64+
- '-c'
65+
- |
66+
set -e
67+
VERSION=${_CDAP_VERSION}
68+
echo "Packaging DEB bundle for version $$VERSION"
69+
mkdir -p cdap/cdap-distributions/target/deb-bundle-tmp
70+
cd cdap/cdap-distributions/target/deb-bundle-tmp
71+
find /workspace/cdap -name "*.deb" -exec cp {} . \;
72+
if [ -z "$(ls -A *.deb 2>/dev/null)" ]; then
73+
echo "ERROR: No .deb files found to bundle!"
74+
exit 1
75+
fi
76+
tar zcf ../cdap-distributed-deb-bundle-$${VERSION}.tgz *.deb
77+
echo "Created DEB bundle: $(pwd)/../cdap-distributed-deb-bundle-$${VERSION}.tgz"
78+
cd /workspace
79+
waitFor: [ 'build-distributions' ]
80+
81+
- name: 'anchore/syft:v1.5.0'
82+
id: generate-sbom
83+
args:
84+
- 'packages'
85+
- '-o'
86+
- 'spdx-json=/workspace/attestations/project-sbom.spdx.json'
87+
- '.'
88+
waitFor: [ 'build-distributions' ]
89+
90+
- name: 'bash'
91+
id: stage-artifacts
92+
entrypoint: 'bash'
93+
args:
94+
- '-c'
95+
- |
96+
set -e
97+
mkdir -p /workspace/staging
98+
mkdir -p /workspace/attestations
99+
VERSION=${_CDAP_VERSION}
100+
101+
echo "Copying Maven artifacts..."
102+
find . -type f \( -name "*.jar" -o -name "*.pom" -o -name "*.war" \) \
103+
! -name "original-*.jar" ! -name "*-tests.jar" \
104+
! -path "*/target/site/*" ! -path "*/target/apidocs/*" \
105+
! -path "*/target/dependency-cache/*" ! -path "*/target/maven-archiver/*" \
106+
! -path "*/target/generated-sources/*" ! -path "*/target/maven-status/*" \
107+
-exec cp --parents {} /workspace/staging/ \;
108+
109+
echo "Copying Standalone ZIP..."
110+
cp cdap/cdap-standalone/target/cdap-sandbox-$${VERSION}.zip /workspace/staging/
111+
112+
echo "Copying DEB bundle..."
113+
cp cdap/cdap-distributions/target/cdap-distributed-deb-bundle-$${VERSION}.tgz /workspace/staging/
114+
115+
echo "Copying SBOM..."
116+
cp /workspace/attestations/project-sbom.spdx.json /workspace/staging/
117+
118+
echo "Staged files (top level):"
119+
ls -l /workspace/staging
120+
waitFor: [ 'create-deb-bundle', 'generate-sbom' ]
121+
122+
- name: 'bash'
123+
id: create-manifest
124+
entrypoint: 'bash'
125+
args:
126+
- '-c'
127+
- |
128+
set -e
129+
echo "Creating manifest.json..."
130+
cd /workspace/staging
131+
printf '{\n "artifacts": [\n' > manifest.json
132+
find . -type f ! -name "manifest.json" | sed 's|./||' | sort | sed 's/.*/ "&",/' >> manifest.json
133+
sed -i '$ s/,$//' manifest.json
134+
printf '\n ]\n}\n' >> manifest.json
135+
echo "Generated manifest.json:"
136+
cat manifest.json
137+
cd /workspace
138+
waitFor: [ 'stage-artifacts' ]
139+
140+
- name: 'gcr.io/cloud-builders/gsutil'
141+
id: upload-to-staging-bucket
142+
args:
143+
- '-m'
144+
- 'cp'
145+
- '-r'
146+
- '/workspace/staging/*'
147+
- 'gs://${_SECURE_PUBLISH_BUCKET_NAME}/${_ARTIFACT_ID}/${BUILD_ID}/'
148+
waitFor: [ 'create-manifest' ]
149+
150+
options:
151+
requestedVerifyOption: VERIFIED
152+
machineType: 'E2_HIGHCPU_32'

pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@
5353
<tag>HEAD</tag>
5454
</scm>
5555

56+
<distributionManagement>
57+
<snapshotRepository>
58+
<id>artifact-registry</id>
59+
<url>artifactregistry://us-maven.pkg.dev/oss-exit-gate-prod/cloud-data-fusion--mavencentral</url>
60+
</snapshotRepository>
61+
<repository>
62+
<id>artifact-registry</id>
63+
<url>artifactregistry://us-maven.pkg.dev/oss-exit-gate-prod/cloud-data-fusion--mavencentral</url>
64+
</repository>
65+
</distributionManagement>
66+
67+
<repositories>
68+
<repository>
69+
<id>artifact-registry</id>
70+
<url>artifactregistry:us-maven.pkg.dev/oss-exit-gate-prod/cloud-data-fusion--mavencentral</url>
71+
<releases>
72+
<enabled>true</enabled>
73+
</releases>
74+
<snapshots>
75+
<enabled>true</enabled>
76+
</snapshots>
77+
</repository>
78+
</repositories>
79+
5680
<modules>
5781
<module>app-artifacts/bigquery-delta-plugins</module>
5882
<module>app-artifacts/database-delta-plugins</module>
@@ -72,6 +96,16 @@
7296
<module>cdap</module>
7397
</modules>
7498

99+
<build>
100+
<extensions>
101+
<extension>
102+
<groupId>com.google.cloud.artifactregistry</groupId>
103+
<artifactId>artifactregistry-maven-wagon</artifactId>
104+
<version>2.2.5</version>
105+
</extension>
106+
</extensions>
107+
</build>
108+
75109
<profiles>
76110
<profile>
77111
<id>release</id>

0 commit comments

Comments
 (0)