Skip to content

Commit

Permalink
crane
Browse files Browse the repository at this point in the history
  • Loading branch information
dntczdx committed Nov 24, 2021
1 parent c24631c commit a8afcaa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 137 deletions.
126 changes: 16 additions & 110 deletions rollout/cli_tools_cloudbuild_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,8 @@ substitutions:

steps:
# Build daisy.
- name: 'gcr.io/go-containerregistry/crane'
args: ['--help']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/daisy:$_RELEASE', '$_PREV_RELEASE']
- name: 'docker'
dir: 'daisy/cli'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/daisy:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'daisy/cli'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/daisy:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/daisy:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'daisy/cli'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/daisy:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'golang'
dir: 'daisy/cli'
args: ['go', 'build', '-o=/workspace/linux/daisy']
Expand All @@ -56,18 +42,8 @@ steps:
- --dockerfile=daisy.Dockerfile

# Build gce_image_publish.
- name: 'docker'
dir: 'cli_tools/gce_image_publish'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_image_publish:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_image_publish'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_image_publish:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_image_publish:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_image_publish'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_image_publish:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_image_publish:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_image_publish'
args: ['go', 'build', '-o=/workspace/linux/gce_image_publish']
Expand All @@ -89,18 +65,8 @@ steps:
- --dockerfile=gce_image_publish.Dockerfile

# Build gce_export.
- name: 'docker'
dir: 'cli_tools/gce_export'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_export:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_export'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_export:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_export'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_export:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_export'
args: ['go', 'build', '-o=/workspace/linux/gce_export']
Expand Down Expand Up @@ -128,18 +94,8 @@ steps:
env: ['GOOS=windows']

# Build gce_vm_image_import.
- name: 'docker'
dir: 'cli_tools/gce_vm_image_import'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_import:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_vm_image_import'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_import:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_vm_image_import'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_import:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_vm_image_import'
args: ['go', 'build', '-o=/workspace/linux/gce_vm_image_import']
Expand All @@ -153,18 +109,8 @@ steps:
- --dockerfile=gce_vm_image_import.Dockerfile

# Build gce_onestep_image_import.
- name: 'docker'
dir: 'cli_tools/gce_onestep_image_import'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_onestep_image_import:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_onestep_image_import'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_onestep_image_import:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_onestep_image_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_onestep_image_import'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_onestep_image_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_onestep_image_import:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_onestep_image_import'
args: ['go', 'build', '-o=/workspace/linux/gce_onestep_image_import']
Expand All @@ -178,18 +124,8 @@ steps:
- --dockerfile=gce_onestep_image_import.Dockerfile

# Build gce_vm_image_export.
- name: 'docker'
dir: 'cli_tools/gce_vm_image_export'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_export:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_vm_image_export'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_export:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_vm_image_export'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_vm_image_export:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_vm_image_export'
args: ['go', 'build', '-o=/workspace/linux/gce_vm_image_export']
Expand All @@ -203,18 +139,8 @@ steps:
- --dockerfile=gce_vm_image_export.Dockerfile

# Build gce_ovf_import.
- name: 'docker'
dir: 'cli_tools/gce_ovf_import'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_import:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_ovf_import'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_import:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_ovf_import'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_import:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_import:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_ovf_import'
args: ['go', 'build', '-o=/workspace/linux/gce_ovf_import']
Expand All @@ -228,18 +154,8 @@ steps:
- --dockerfile=gce_ovf_import.Dockerfile

# Build gce_ovf_export.
- name: 'docker'
dir: 'cli_tools/gce_ovf_export'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_export:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_ovf_export'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_export:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_ovf_export'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_export:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_ovf_export:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_ovf_export'
args: ['go', 'build', '-o=/workspace/linux/gce_ovf_export']
Expand All @@ -253,18 +169,8 @@ steps:
- --dockerfile=gce_ovf_export.Dockerfile

# Build gce_windows_upgrade.
- name: 'docker'
dir: 'cli_tools/gce_windows_upgrade'
args: ['pull', 'gcr.io/$_IMAGE_PROJECT/gce_windows_upgrade:$_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_windows_upgrade'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_windows_upgrade:$_RELEASE', 'gcr.io/$_IMAGE_PROJECT/gce_windows_upgrade:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'docker'
dir: 'cli_tools/gce_windows_upgrade'
args: ['push', 'gcr.io/$_IMAGE_PROJECT/gce_windows_upgrade:$_PREV_RELEASE']
env: ['CGO_ENABLED=0']
- name: 'gcr.io/go-containerregistry/crane'
args: ['tag', 'gcr.io/$_IMAGE_PROJECT/gce_windows_upgrade:$_RELEASE', '$_PREV_RELEASE']
- name: 'golang'
dir: 'cli_tools/gce_windows_upgrade'
args: ['go', 'build', '-o=/workspace/linux/gce_windows_upgrade']
Expand Down
19 changes: 6 additions & 13 deletions rollout/cli_tools_cloudbuild_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,19 @@ steps:
REGIONS_ARR=$(echo "$_REGIONS" | tr ";" "\n")
TOOLS_ARR=$(echo "$_TOOLS" | tr ";" "\n")
for _TOOL in $$TOOLS_ARR
do
echo "----> Preparing docker images for $$_TOOL..."
docker pull gcr.io/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID || exit 1
done
for _REGION in $$REGIONS_ARR
do
for _TOOL in $$TOOLS_ARR
do
echo "--> Deploying... $$_TOOL -> $$_REGION"
docker tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:$_WORKFLOW_EXECUTION_ID || exit 1
docker tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:$COMMIT_SHA || exit 1
docker tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:release || exit 1
# Mark current "release" as "prev-release" for rollback.
crane tag $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:release prev-release
docker push $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:$_WORKFLOW_EXECUTION_ID || exit 1
docker push $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:$COMMIT_SHA || exit 1
docker push $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:release || exit 1
# Copy the new "release" from gcr.io.
crane copy gcr.io/$_IMAGE_PROJECT/$$_TOOL:release $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:release
crane tag $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:release $_WORKFLOW_EXECUTION_ID
crane tag $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:release $COMMIT_SHA
done
echo "----> Deployed all tools for $$_REGION"
done
19 changes: 5 additions & 14 deletions rollout/cli_tools_cloudbuild_deploy_rollback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ timeout: 5400s
options:

steps:
# Deploy given tools to given locations. Expect 2 vars substitutions, examples:
# Rollback given tools to given locations. Expect 2 vars substitutions, examples:
# 1. $_REGIONS="us;us-east1;us-east2"
# 2. $_TOOLS="gve_vm_image_import;gce_vm_image_export"
# The script will pull the built docker images from gcr.io (container registry),
# The script will pull the built docker images with "prev-release" tag from gcr.io (container registry),
# and then push to artifacts registry (e.g. us-east1-docker.pkg.dev/compute-image-tools/wrappers/gce_vm_image_import)
# with 3 tags: the workflow execution ID, the commit SHA, and the "release".
# 1. The workflow execution ID is used to track which workflow produced the image.
Expand All @@ -21,22 +21,13 @@ steps:
REGIONS_ARR=$(echo "$_REGIONS" | tr ";" "\n")
TOOLS_ARR=$(echo "$_TOOLS" | tr ";" "\n")
for _TOOL in $$TOOLS_ARR
do
echo "----> Preparing docker images for $$_TOOL..."
docker pull gcr.io/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID || exit 1
done
for _REGION in $$REGIONS_ARR
do
for _TOOL in $$TOOLS_ARR
do
echo "--> Deploying... $$_TOOL -> $$_REGION"
echo "--> Rollback... $$_TOOL -> $$_REGION"
gcloud container images add-tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:release $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:$_WORKFLOW_EXECUTION_ID -q
gcloud container images add-tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:release $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:$COMMIT_SHA -q
gcloud container images add-tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:release $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:release -q
crane tag $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/$$_TOOL:prev-release release -q
done
echo "----> Deployed all tools for $$_REGION"
echo "----> Rollback all tools for $$_REGION done."
done

0 comments on commit a8afcaa

Please sign in to comment.