From 7788477b6e4bb2a9ff86061b01541de745476fd8 Mon Sep 17 00:00:00 2001 From: Nick Kubala Date: Mon, 14 May 2018 11:01:32 -0700 Subject: [PATCH] Support cross compilation (#133) --- README.md | 21 ++++++++++++++---- cloudbuild.yaml | 29 +++++++++++++++++++++---- release_cloudbuild.yaml | 47 +++++++++++++++++++++++++++++++++++------ 3 files changed, 82 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ece1d1e1..7725a2d0 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,26 @@ in an image, as well as verify metadata and contents of the filesystem. Tests can be run either through a standalone binary, or through a Docker image. ## Installation -Download the latest binary release [here](https://storage.googleapis.com/container-structure-test/latest/container-structure-test), -or pull the image at `gcr.io/gcp-runtimes/container-structure-test`. -**At this time, only a Linux binary is published. However, an OS X binary can be built using bazel:** + +### OS X ```shell -bazel build //:container_structure_test +curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-darwin-amd64 && chmod +x container-structure-test-darwin-amd64 && sudo mv container-structure-test-darwin-amd64 /usr/local/bin/container-structure-test ``` +### Linux +```shell +curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 && chmod +x container-structure-test-linux-amd64 && sudo mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test +``` + +If you want to avoid using sudo: + +```shell +curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 && chmod +x container-structure-test-linux-amd64 && mkdir -p $HOME/bin && export PATH=$PATH:$HOME/bin && mv container-structure-test-linux-amd64 $HOME/bin/container-structure-test +``` + +Additionally, a container image for running tests through Google Cloud Builder can be found +at `gcr.io/gcp-runtimes/container-structure-test:latest`. + ## Setup To use container structure tests to validate your containers, you need the following: - The container structure test binary or docker image diff --git a/cloudbuild.yaml b/cloudbuild.yaml index d13bcefe..4ed9acb1 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -4,12 +4,33 @@ steps: args: ['run', '//:structure_test_image'] # Tag the built image - name: 'gcr.io/cloud-builders/docker' - args: ['tag', 'bazel:structure_test_image', 'gcr.io/gcp-runtimes/container-structure-test:$COMMIT_SHA'] -# Build the binary + args: [ + 'tag', 'bazel:structure_test_image', + 'gcr.io/gcp-runtimes/container-structure-test:$COMMIT_SHA' + ] + +# Build the linux binary - name: 'gcr.io/cloud-builders/bazel' args: ['build', '//:container_structure_test'] -# Upload the binary to GCS +# Upload the linux binary to GCS build tag bucket + - name: 'gcr.io/cloud-builders/gsutil' + args: [ + 'cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/builds/$COMMIT_SHA/container-structure-test-linux-amd64' + ] + +# Build the OS X binary + - name: 'gcr.io/cloud-builders/bazel' + args: [ + 'build', + '--platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64', + '//:container_structure_test' + ] +# Upload the OS X binary to GCS build tag bucket - name: 'gcr.io/cloud-builders/gsutil' - args: ['cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', 'gs://container-structure-test/builds/$COMMIT_SHA/container-structure-test'] + args: [ + 'cp', 'bazel-bin/darwin_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/builds/$COMMIT_SHA/container-structure-test-darwin-amd64' + ] images: ['gcr.io/gcp-runtimes/container-structure-test:$COMMIT_SHA'] diff --git a/release_cloudbuild.yaml b/release_cloudbuild.yaml index 777f9da4..2d3785ba 100644 --- a/release_cloudbuild.yaml +++ b/release_cloudbuild.yaml @@ -4,19 +4,52 @@ steps: args: ['run', '//:structure_test_image'] # Tag the built image - name: 'gcr.io/cloud-builders/docker' - args: ['tag', 'bazel:structure_test_image', 'gcr.io/gcp-runtimes/container-structure-test:$TAG_NAME'] + args: [ + 'tag', 'bazel:structure_test_image', + 'gcr.io/gcp-runtimes/container-structure-test:$TAG_NAME' + ] # Tag the new image as latest - name: 'gcr.io/cloud-builders/docker' - args: ['tag', 'bazel:structure_test_image', 'gcr.io/gcp-runtimes/container-structure-test:latest'] -# Build the binary + args: [ + 'tag', 'bazel:structure_test_image', + 'gcr.io/gcp-runtimes/container-structure-test:latest' + ] + +# Build the linux binary - name: 'gcr.io/cloud-builders/bazel' args: ['build', '//:container_structure_test'] -# Upload the linux binary to GCS +# Upload the linux binary to GCS release tag bucket + - name: 'gcr.io/cloud-builders/gsutil' + args: [ + 'cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/$TAG_NAME/container-structure-test-linux-amd64' + ] +# Upload the linux binary to GCS latest bucket + - name: 'gcr.io/cloud-builders/gsutil' + args: [ + 'cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/latest/container-structure-test-linux-amd64' + ] + +# Build the OS X binary + - name: 'gcr.io/cloud-builders/bazel' + args: [ + 'build', + '--platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64', + '//:container_structure_test' + ] +# Upload the OS X binary to GCS release tag bucket - name: 'gcr.io/cloud-builders/gsutil' - args: ['cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', 'gs://container-structure-test/$TAG_NAME/container-structure-test'] -# Upload the linux binary to GCS + args: [ + 'cp', 'bazel-bin/darwin_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/$TAG_NAME/container-structure-test-darwin-amd64' + ] +# Upload the OS X binary to GCS latest bucket - name: 'gcr.io/cloud-builders/gsutil' - args: ['cp', 'bazel-bin/linux_amd64_pure_stripped/container_structure_test', 'gs://container-structure-test/latest/container-structure-test'] + args: [ + 'cp', 'bazel-bin/darwin_amd64_pure_stripped/container_structure_test', + 'gs://container-structure-test/latest/container-structure-test-darwin-amd64' + ] images: [ 'gcr.io/gcp-runtimes/container-structure-test:$TAG_NAME',