Skip to content

Commit

Permalink
Move Cloud Build test and release to Makefile (#312)
Browse files Browse the repository at this point in the history
This moves the test and release cloudbuild.yaml over to using the
`./build/Makefile`, so that it runs the same tooling as developers have
locally!

There are a few extra fixes/small features in here as well:
- Makefile tasks would fail if the user didn't have cargo installed
  locally, or weren't using Linux. (this also solved the need to copy
  cargo binaries from image to host on release/cloudbuild.yaml).
- cloudbuild.yaml now use git submodules to pull in external protos
- Added a handy `make shell` command to get an interactive shell in the
  build image.
  • Loading branch information
markmandel authored Jul 3, 2021
1 parent 131f51c commit b212b16
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 238 deletions.
2 changes: 2 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
#

.*
!.git
!.dockerignore
target
quilkin-*.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
license.html
license.csv
dependencies-src.zip
quilkin-*.zip

/quilkin.yaml

Expand Down
26 changes: 20 additions & 6 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rust_toolchain := $(shell grep channel $(project_path)/rust-toolchain.toml | awk
package_version := $(shell grep version -m 1 $(project_path)/Cargo.toml | awk '{print $$3}')

common_rust_args := -v $(project_path):/workspace -w /workspace \
-v $(CARGO_HOME):/cargo --env CARGO_HOME=/cargo
-v $(CARGO_HOME)/registry:/usr/local/cargo/registry
docker_in_docker := -v /var/run/docker.sock:/var/run/docker.sock

# _____ _
Expand All @@ -56,8 +56,13 @@ test: ensure-build-image
# Build all binaries, images and related artifacts
build: binary-archive build-image

# Build all binaries and images
build: ensure-build-image build-linux-binary build-windows-binary build-macos-binary build-image
# Build all debug and release binaries
build-all-binaries: ensure-build-image build-linux-binary build-windows-binary build-macos-binary

# Build an archive all debug and release binaries
binary-archive: ensure-build-image build-all-binaries
docker run --rm $(common_rust_args) \
--entrypoint=bash $(BUILD_IMAGE_TAG) -c 'zip quilkin-$(package_version).zip ./target/*/*/quilkin ./target/*/*/quilkin.exe'

# Build release and debug binaries for x86_64-unknown-linux-gnu
build-linux-binary: ensure-build-image
Expand All @@ -83,7 +88,7 @@ build-macos-binary:
# Build release and debug container images.
# Use IMAGE_NAME argument to specify the container registry and image name. Defaults to 'quilkin'.
build-image: ensure-build-image build-linux-binary
build-image: IMAGE_NAME ?= quilkin
build-image: IMAGE_NAME := quilkin
build-image:
docker run --rm $(common_rust_args) \
--entrypoint=bash $(BUILD_IMAGE_TAG) -c 'cargo about generate license.html.hbs > license.html'
Expand All @@ -92,5 +97,14 @@ build-image:
docker build -t $(IMAGE_NAME):$(package_version)-debug --build-arg PROFILE=debug -f $(project_path)/image/Dockerfile $(project_path)
docker build -t $(IMAGE_NAME):$(package_version) --build-arg PROFILE=release -f $(project_path)/image/Dockerfile $(project_path)

ensure-build-image:
docker build --build-arg RUST_TOOLCHAIN=$(rust_toolchain) --tag=$(BUILD_IMAGE_TAG) $(build_path)/build-image/
# Start an interactive shell inside the build image
# Useful for testing, or adhoc cargo commands
shell: ensure-build-image
docker run --rm -it $(common_rust_args) \
--entrypoint=bash $(BUILD_IMAGE_TAG)

ensure-build-image: ensure-cargo-registry
docker build $(BUILD_IMAGE_ARG) --build-arg RUST_TOOLCHAIN=$(rust_toolchain) --tag=$(BUILD_IMAGE_TAG) $(build_path)/build-image/

ensure-cargo-registry:
-mkdir -p $(CARGO_HOME)/registry
37 changes: 0 additions & 37 deletions build/release/Dockerfile.builder

This file was deleted.

31 changes: 0 additions & 31 deletions build/release/Dockerfile.release

This file was deleted.

3 changes: 1 addition & 2 deletions build/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
Run `make` to submit the `cloudbuild.yaml` to [Google Cloud Build](https://cloud.google.com/build) and build the
release:

* Linux executable for both release and debug.
* Windows executable for both release and debug.
* Linux, Windows and macOS executable for both release and debug.
* Docker images for both release and debug.

If you need to pass extra arguments to the `make` target, the target comes with an `$(ARGS)` parameter than can be
Expand Down
40 changes: 0 additions & 40 deletions build/release/archive_dependencies.sh

This file was deleted.

87 changes: 17 additions & 70 deletions build/release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,26 @@
# limitations under the License.

steps:
- name: gcr.io/cloud-builders/git
args: [ submodule, update, --init, --recursive ]
id: fetch-git-submodules
- name: gcr.io/cloud-builders/gsutil
id: create-bucket
entrypoint: bash
args:
- '-c'
- 'gsutil mb $_STORAGE || true'
id: create-bucket
- name: gcr.io/cloud-builders/docker
id: build-builder
args: [ 'build', '-f', 'Dockerfile.builder', '-t', 'builder', '.' ] # make sure we always have the latest docker with rust, cargo and cross
dir: ./build/release
- name: builder
id: copy-rust-tooling
entrypoint: bash
args:
- -c
- 'cp -r /usr/local/cargo $$CARGO_HOME'
- name: builder
id: capture-version
entrypoint: bash
args: ['-c', "grep version -m 1 Cargo.toml | awk '{ print $3 }' | sed s/\\\"//g > version"]
- name: builder
id: echo-version
entrypoint: cat
args: ['./version']
- name: builder
id: cross-version
entrypoint: cross
args: ['--version']
- name: builder
id: cargo-about
entrypoint: bash
args: [ pull, "${_BUILD_IMAGE_TAG}" ]
id: pull-build-image
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- '-c'
- 'cargo about generate license.html.hbs > license.html'
- name: builder
id: dependencies-src.zip
entrypoint: bash
args:
- '-c'
- './build/release/archive_dependencies.sh'
- name: builder
id: x86_64-unknown-linux-gnu-debug
entrypoint: cross
args: ['build', '--target', 'x86_64-unknown-linux-gnu']
- name: builder
id: x86_64-unknown-linux-gnu-release
entrypoint: cross
args: ['build', '--target', 'x86_64-unknown-linux-gnu', '--release']
- name: builder
id: docker-linux-debug
entrypoint: bash
args:
- '-c'
- 'docker build -t $_LOCATION-docker.pkg.dev/$PROJECT_ID/$_REPOSITORY/quilkin:$(cat ./version)-debug --build-arg PROFILE=debug -f ./build/release/Dockerfile.release .'
- name: builder
id: docker-linux-release
entrypoint: bash
args:
- '-c'
- 'docker build -t $_LOCATION-docker.pkg.dev/$PROJECT_ID/$_REPOSITORY/quilkin:$(cat ./version) --build-arg PROFILE=release -f ./build/release/Dockerfile.release .'
- name: builder
id: x86_64-pc-windows-gnu-debug
entrypoint: cross
args: ['build', '--target', 'x86_64-pc-windows-gnu']
- name: builder
id: x86_64-pc-windows-gnu-release
entrypoint: cross
args: ['build', '--target', 'x86_64-pc-windows-gnu', '--release']
- name: builder
entrypoint: bash
args:
- '-c'
- 'zip quilkin-$(cat ./version).zip target/x86_64-unknown-linux-gnu/debug/quilkin ./target/x86_64-unknown-linux-gnu/release/quilkin ./target/x86_64-pc-windows-gnu/debug/quilkin.exe ./target/x86_64-pc-windows-gnu/release/quilkin.exe'
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- IMAGE_NAME=${_IMAGE_TAG}
- build
id: build
- name: ferrarimarco/github-changelog-generator:1.15.2
id: changelog
entrypoint: sh
Expand All @@ -102,17 +49,17 @@ artifacts:
- 'license.html'
- 'CHANGELOG.md'
images:
- $_LOCATION-docker.pkg.dev/$PROJECT_ID/$_REPOSITORY/quilkin
- $_IMAGE_TAG
options:
env:
- "CARGO_HOME=/workspace/.cargo"
- "RUST_BACKTRACE=1"
machineType: N1_HIGHCPU_8
machineType: E2_HIGHCPU_32
dynamic_substitutions: true
substitutions:
_BUILD_IMAGE_TAG: us-docker.pkg.dev/${PROJECT_ID}/ci/build-image
_IMAGE_TAG: us-docker.pkg.dev/${PROJECT_ID}/release/quilkin
_STORAGE: gs://${PROJECT_ID}-quilkin-releases
_LOCATION: us
_REPOSITORY: release
availableSecrets:
secretManager:
- versionName: projects/${PROJECT_ID}/secrets/release-github-token/versions/latest
Expand Down
20 changes: 0 additions & 20 deletions build/release/quilkin.yaml

This file was deleted.

47 changes: 15 additions & 32 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,24 @@

steps:
- name: gcr.io/cloud-builders/git
entrypoint: '/bin/sh'
args:
- '-c'
- |
git clone --depth 1000 https://github.com/envoyproxy/data-plane-api.git proto/data-plane-api
git -C proto/data-plane-api checkout c5f1620aa47b4dfdefebb5271c3135ef33029a0e
git clone --depth 1000 https://github.com/cncf/udpa.git proto/udpa
git -C proto/udpa checkout bff43e8824d093cb64afdc901266cfab5a9777f0
git clone --depth 1000 https://github.com/envoyproxy/protoc-gen-validate.git proto/protoc-gen-validate
git -C proto/protoc-gen-validate checkout 12afc6dcd71f00ea08deee4df84173aed4cc7f97
git clone --depth 1000 https://github.com/googleapis/googleapis.git proto/googleapis
git -C proto/googleapis checkout a0d282daa691e95ec51131c81c3777fc95abf7f8
args: [ submodule, update, --init, --recursive ]
id: fetch-git-submodules
- name: us-docker.pkg.dev/$PROJECT_ID/ci/cargo
entrypoint: rustc
args: ["--version", "--verbose"]
id: version
# clippy tends to rely on cached results from other cargo sub-commands so
# that it skips checking some files that were built previously. As a result
# we run it before other cargo sub-commands to ensure that it checks all files.
- name: us-docker.pkg.dev/$PROJECT_ID/ci/cargo
args: ["clippy", "--tests", "--", "-D", "warnings"]
id: clippy
- name: us-docker.pkg.dev/$PROJECT_ID/ci/cargo
args: ["fmt", "--", "--check"]
id: fmt-check
- name: us-docker.pkg.dev/$PROJECT_ID/ci/cargo
args: ["test", "--tests"]
- name: gcr.io/cloud-builders/docker
args: [ pull, "${_BUILD_IMAGE_TAG}" ]
id: pull-build-image
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- test
id: test
- name: us-docker.pkg.dev/$PROJECT_ID/ci/cargo
args: ["+nightly", "test", "--doc"]
id: external-doc-test
options:
env:
- "CARGO_HOME=/workspace/.cargo"
machineType: N1_HIGHCPU_8
timeout: 30m
machineType: E2_HIGHCPU_8
dynamic_substitutions: true
timeout: 1800s
substitutions:
_BUILD_IMAGE_TAG: us-docker.pkg.dev/${PROJECT_ID}/ci/build-image
logsBucket: "gs://quilkin-build-logs"

0 comments on commit b212b16

Please sign in to comment.