Skip to content

Commit

Permalink
Modify Makefile to use push-cip.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerferrara committed Jun 28, 2021
1 parent f4728eb commit 88680c8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5,958 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ FROM gcloud-base as cip-variant
ENV HOME=/
ENTRYPOINT ["/bin/bash", "-c"]

# Allow the runtime argument to choose the final variant.
FROM ${variant}-variant AS final
12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,13 @@ install: ## Install

##@ Images

.PHONY: image
image: ## Build image
bazel build //:cip-docker-loadable.tar

.PHONY: image-load
image-load: image ## Build image and load it
docker load -i bazel-bin/cip-docker-loadable.tar

.PHONY: image-push
image-push: image ## Build image and push
bazel run :push-cip
./hack/push-cip.sh

.PHONY: image-push-cip-auditor-e2e
image-push-cip-auditor-e2e: ## Push image cip-auditor-e2e
./test-e2e/cip-auditor/push-cip-auditor-test.sh
./hack/push-cip.sh --audit

##@ Lints

Expand Down
78 changes: 60 additions & 18 deletions hack/push-cip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,44 @@ set -o errexit
set -o nounset
set -o pipefail

repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)

printUsage() {
echo "Usage: $0 [--audit | -a]"
}

AUDITOR=false
# Takes array of images and pushes to their tagged registry location.
pushImages() {
for img in "$@"; do
echo $img
docker push "$img"
done
}

# Builds either auditor or cip container image from repo_root. Also adds
# tags, given by an array of tags.
buildImage() {
# Add build variant argument.
variant=$1
cmd="docker build --build-arg variant=$variant "
# Concatenate tags.
tags="${*:2}"
for tag in $tags; do
cmd+="-t $tag "
done
# Specify Dockerfile location.
cmd+="$repo_root"
# Build the container.
echo "Executing: $cmd"
$cmd
}

# Detect which container variant to build.
build_variant="cip"

if [[ $# == 1 ]]; then
if [ "$1" == --audit ] || [ "$1" == -a ]; then
AUDITOR=true
build_variant="auditor"
else
>&2 echo "ERROR: Unknown flag provided."
printUsage
Expand All @@ -41,25 +70,38 @@ elif [[ $# -gt 1 ]]; then
exit 1
fi

repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
# Inject workspace variables.
source <("${repo_root}"/workspace_status.sh inject)

if [ "$AUDITOR" == true ]; then
# Asesmble image names.
latest="${STABLE_TEST_AUDIT_STAGING_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor-test:latest"
stable="${STABLE_TEST_AUDIT_STAGING_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor-test:${STABLE_IMG_TAG}"
# Build docker container from Dockerfile (with tag names).
docker build -t "$latest" -t "$stable" --build-arg variant=auditor "$repo_root"
# Push images.
docker push "$latest"
docker push "$stable"
else
${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}:latest": "//:cip-with-gcloud",
${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}:${STABLE_IMG_TAG}": "//:cip-with-gcloud",

${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor:latest": "//:cip-auditor",
${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor:${STABLE_IMG_TAG}": "//:cip-auditor",
# Define tags for the auditor.
# NOTE: Both cip and auditor variants build an auditor image. Although they are named differently,
# the iamge contents are the exact same. Defaults to cip variant.
audit_tags=(
"${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor:latest"
"${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor:${STABLE_IMG_TAG}"
)
if [ "$build_variant" == auditor ]; then
audit_tags=(
"${STABLE_TEST_AUDIT_STAGING_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor-test:latest"
"${STABLE_TEST_AUDIT_STAGING_IMG_REPOSITORY}/${STABLE_IMG_NAME}-auditor-test:${STABLE_IMG_TAG}"
)
fi

# Build and tag the auditor image.
buildImage "auditor" "${audit_tags[@]}"
# Push auditor images.
pushImages "${audit_tags[@]}"

if [ "$build_variant" == cip ]; then
# Define tags for the cip tool.
cip_tags=(
"${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}:latest"
"${STABLE_IMG_REGISTRY}/${STABLE_IMG_REPOSITORY}/${STABLE_IMG_NAME}:${STABLE_IMG_TAG}"
)
# Build and tag the cip image.
buildImage "cip" "${cip_tags[@]}"
# Push cip images.
pushImages "${cip_tags[@]}"
fi

echo "$0" finished.
1 change: 1 addition & 0 deletions test-e2e/cip-auditor/cip-auditor-e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
func main() {
// NOTE: We can't run the tests in parallel because we only have 1 pair of
// staging/prod GCRs.

testsPtr := flag.String(
"tests", "", "the e2e tests file (YAML) to load (REQUIRED)")
repoRootPtr := flag.String(
Expand Down
Loading

0 comments on commit 88680c8

Please sign in to comment.