-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add docker image for hermetic build scripts (#2493)
Similar changes to those of #2298 by @mpeddada1 This setup uses two triggers: - The first one is [library-generation-presubmit-sdk-platform-java](https://pantheon.corp.google.com/cloud-build/triggers;region=global/edit/5783744f-0820-419f-bc5e-abbbece4be0b?e=13803378&mods=monitoring_api_prod&project=cloud-devrel-kokoro-resources), which runs on each pull request. It builds a docker image with the contents of `library_generation` at HEAD and runs `library_generation/integration_tests.py` with such image - The second one is [library-generation-sdk-platform-java](https://pantheon.corp.google.com/cloud-build/triggers;region=global/edit/e3373892-82a2-4eac-a1f2-95523966df70?e=13803378&mods=monitoring_api_prod&project=cloud-devrel-kokoro-resources), which: - is triggered upon a commit pushed to the `main` branch, then - builds a docker image with two tags - `latest`, which will be constantly updated to match the latest build - a tag based on the branch `${COMMIT_SHA}` - then the image is pushed with both tags ### tasks - [x] create dockerfile - [x] create cloudbuild.yaml for testing - [x] create cloudbuild test infra - [x] create cloudbuild.yaml for releasing the image - [x] create cloudbuild release infra --------- Co-authored-by: Joe Wang <[email protected]>
- Loading branch information
1 parent
dedc40f
commit 7902a41
Showing
9 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2024 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 | ||
# | ||
# http://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. | ||
|
||
timeout: 7200s # 2 hours | ||
substitutions: | ||
_IMAGE_NAME: "gcr.io/cloud-devrel-public-resources/java-library-generation" | ||
_SHA_IMAGE_ID: "${_IMAGE_NAME}:${COMMIT_SHA}" | ||
_LATEST_IMAGE_ID: "${_IMAGE_NAME}:latest" | ||
steps: | ||
# Library generation build | ||
- name: gcr.io/cloud-builders/docker | ||
args: [ | ||
"build", | ||
"-t", "${_SHA_IMAGE_ID}", | ||
"-t", "${_LATEST_IMAGE_ID}", | ||
"--file", ".cloudbuild/library_generation.Dockerfile", "."] | ||
id: library-generation-build | ||
waitFor: ["-"] | ||
|
||
images: | ||
- ${_SHA_IMAGE_ID} | ||
- ${_LATEST_IMAGE_ID} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 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 | ||
# | ||
# http://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. | ||
|
||
timeout: 7200s # 2 hours | ||
substitutions: | ||
_TEST_IMAGE_ID: 'gcr.io/cloud-devrel-public-resources/java-library-generation:${COMMIT_SHA}' | ||
|
||
steps: | ||
# Library generation build | ||
- name: gcr.io/cloud-builders/docker | ||
args: ["build", "-t", "${_TEST_IMAGE_ID}", "--file", ".cloudbuild/library_generation.Dockerfile", "."] | ||
id: library-generation-build | ||
waitFor: ["-"] | ||
- name: ${_TEST_IMAGE_ID} | ||
entrypoint: bash | ||
args: [ './library_generation/test/container_integration_tests.sh' ] | ||
waitFor: [ "library-generation-build" ] | ||
env: | ||
- 'TEST_IMAGE_ID=${_TEST_IMAGE_ID}' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2024 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. | ||
|
||
# build from the root of this repo: | ||
FROM gcr.io/cloud-devrel-public-resources/python | ||
|
||
# install tools | ||
RUN apt-get update && apt-get install -y \ | ||
unzip openjdk-17-jdk rsync maven \ | ||
&& apt-get clean | ||
|
||
COPY library_generation /src | ||
|
||
RUN rm $(which python3) | ||
RUN ln -s $(which python3.11) /usr/local/bin/python | ||
RUN ln -s $(which python3.11) /usr/local/bin/python3 | ||
RUN python -m pip install --upgrade pip | ||
RUN cd /src && python -m pip install -r requirements.in | ||
RUN cd /src && python -m pip install . | ||
|
||
# set dummy git credentials for empty commit used in postprocessing | ||
RUN git config --global user.email "[email protected]" | ||
RUN git config --global user.name "Cloud Java Bot" | ||
|
||
WORKDIR /workspace | ||
RUN chmod 750 /workspace | ||
RUN chmod 750 /src/generate_repo.py | ||
|
||
CMD [ "/src/generate_repo.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
README.md | ||
**/__pycache__/ | ||
**/*.egg-info/ | ||
**/output/ | ||
**/build/ | ||
**/google-cloud-java/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
# This is a wrapper of integration_tests.py that sets up the environment to run | ||
# the script in a docker container | ||
|
||
set -xe | ||
if [[ -z "${TEST_IMAGE_ID}" ]]; then | ||
echo "required environemnt variable TEST_IMAGE_ID is not set" | ||
exit 1 | ||
fi | ||
|
||
if [[ ! -d google-cloud-java ]]; then | ||
git clone https://github.com/googleapis/google-cloud-java | ||
fi | ||
pushd google-cloud-java | ||
git reset --hard main | ||
popd | ||
|
||
# We use a volume to hold the google-cloud-java repository used in the | ||
# integration tests. This is because the test container creates a child | ||
# container using the host machine's docker socket, meaning that we can only | ||
# reference volumes created from within the host machine (i.e. the machine | ||
# running this script) | ||
# | ||
# To summarize, we create a special volume that can be referenced both in the | ||
# main container and in any child containers created by this one. | ||
if [[ $(docker volume inspect repo) != '[]' ]]; then | ||
docker volume rm repo | ||
fi | ||
docker volume create --name "repo" --opt "type=none" --opt "device=$(pwd)/google-cloud-java" --opt "o=bind" | ||
|
||
docker run --rm \ | ||
-v repo:/workspace \ | ||
-v /tmp:/tmp \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-e "RUNNING_IN_DOCKER=true" \ | ||
-e "REPO_BINDING_VOLUME=repo" \ | ||
-w "/src" \ | ||
"${TEST_IMAGE_ID}" \ | ||
python -m unittest /src/test/integration_tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters