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

chore: add docker image for hermetic build scripts #2493

Merged
merged 54 commits into from
Feb 26, 2024

Conversation

diegomarquezp
Copy link
Contributor

@diegomarquezp diegomarquezp commented Feb 16, 2024

Similar changes to those of #2298 by @mpeddada1

This setup uses two triggers:

  • The first one is library-generation-presubmit-sdk-platform-java, 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, 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

  • create dockerfile
  • create cloudbuild.yaml for testing
  • create cloudbuild test infra
  • create cloudbuild.yaml for releasing the image
  • create cloudbuild release infra

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Feb 16, 2024
Copy link

sonarcloud bot commented Feb 21, 2024

Quality Gate Passed Quality Gate passed for 'gapic-generator-java-root'

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@diegomarquezp
Copy link
Contributor Author

Thanks for this PR, @diegomarquezp. LGTM.

As a follow up PR, could you modify the nightly CI in google-cloud-java to use the image, rather than copying script from this repository?

@JoeWang1127 We will have to wait for it to be published when the next release PR is merged, if that's ok. Otherwise I can modify the cloud build workflow to manually create one. WDYT?

@JoeWang1127
Copy link
Collaborator

@JoeWang1127 We will have to wait for it to be published when the next release PR is merged, if that's ok. Otherwise I can modify the cloud build workflow to manually create one. WDYT?

Can we trigger a cloud build whenever there's a new commit to library_generation directory? We can use the image to test how the scripts work in google-cloud-java. We only have one release per two weeks which is slow for us to verify the scripts.

Also, could you tag the image with latest when the commit is merged, so that we don't need to change which image we are using in google-cloud-java.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since this requires a bit of docker-specific knowledge, perhaps we can add a quick comment explaining what we're trying to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment explaining why we create this volume

fi
docker volume create --name "repo" --opt "type=none" --opt "device=$(pwd)/google-cloud-java" --opt "o=bind"

image_id="gcr.io/cloud-devrel-public-resources/java-library-generation:${SHARED_DEPENDENCIES_VERSION}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we pass this in as an argument to the script? In case the image id changes in the future (or if we pick a different project), it can all be changes in a single location in the cloudbuild yaml file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I added IMAGE_ID as a passed env var

@diegomarquezp
Copy link
Contributor Author

diegomarquezp commented Feb 24, 2024

@JoeWang1127 We will have to wait for it to be published when the next release PR is merged, if that's ok. Otherwise I can modify the cloud build workflow to manually create one. WDYT?

Can we trigger a cloud build whenever there's a new commit to library_generation directory? We can use the image to test how the scripts work in google-cloud-java. We only have one release per two weeks which is slow for us to verify the scripts.

Also, could you tag the image with latest when the commit is merged, so that we don't need to change which image we are using in google-cloud-java.

@JoeWang1127 I added a special trigger to build and publish a docker image based on pushes to the main branch of sdk-platform-java

image

Both the latest tag and a tag based on the commit SHA of sdk-platform-java are applied

NOTE: I manually set the trigger to this PR branch instead of main to confirm that the image is published. I switched the trigger to main right after

Copy link

sonarcloud bot commented Feb 24, 2024

Quality Gate Passed Quality Gate passed for 'gapic-generator-java-root'

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@diegomarquezp
Copy link
Contributor Author

@suztomo do you agree with pushing the image to the cloud-devrel-public-resources registry? We can also use cloud-devrel-kokoro-resources

cc: @mpeddada1

Copy link

sonarcloud bot commented Feb 24, 2024

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@diegomarquezp
Copy link
Contributor Author

Thanks for this PR, @diegomarquezp. LGTM.

As a follow up PR, could you modify the nightly CI in google-cloud-java to use the image, rather than copying script from this repository?

I switched to use the docker image in googleapis/google-cloud-java#10435

@suztomo
Copy link
Member

suztomo commented Feb 25, 2024

Yes, cloud-devrel-public-resources is simpler. No authentication when using it.

@diegomarquezp diegomarquezp merged commit 7902a41 into main Feb 26, 2024
46 checks passed
@diegomarquezp diegomarquezp deleted the library-generation-docker-image branch February 26, 2024 15:39
lqiu96 pushed a commit that referenced this pull request Feb 26, 2024
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 <106995533+JoeWang1127@users.noreply.github.com>
lqiu96 pushed a commit that referenced this pull request Feb 28, 2024
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 <106995533+JoeWang1127@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants