Created
August 21, 2020 03:52
Google Cloud Build config for push to develop branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
# Build image and push to GCR | |
- name: 'gcr.io/cloud-builders/docker' | |
id: Build | |
args: | |
- 'build' | |
- '-t' | |
- 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$SHORT_SHA' | |
- '.' | |
# TODO: look into [images] | |
- name: 'gcr.io/cloud-builders/docker' | |
id: Push | |
args: | |
- 'push' | |
- 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$SHORT_SHA' | |
# Access the id_github file from Secret Manager | |
- name: gcr.io/cloud-builders/gcloud | |
entrypoint: 'bash' | |
args: [ '-c', 'gcloud secrets versions access latest --secret=github-ssh-key > /root/.ssh/id_github' ] | |
volumes: | |
- name: 'ssh' | |
path: /root/.ssh | |
# Set up git with key and domain | |
- name: 'gcr.io/cloud-builders/git' | |
entrypoint: 'bash' | |
args: | |
- '-c' | |
- | | |
chmod 600 /root/.ssh/id_github | |
cat <<EOF >/root/.ssh/config | |
Hostname github.com | |
IdentityFile /root/.ssh/id_github | |
EOF | |
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts | |
volumes: | |
- name: 'ssh' | |
path: /root/.ssh | |
# Edit Kustomize layer in config repo and push changes | |
- name: gcr.io/cloud-builders/git | |
entrypoint: 'bash' | |
args: | |
- '-c' | |
- | | |
echo "Cloning repo ..." | |
git clone --depth 1 git@github.com:mikesparr/gcp-cicd-demo-config | |
echo "Updating image tag version ..." | |
cd gcp-cicd-demo-config | |
ls | |
sed -i "s|newTag: .*|newTag: $SHORT_SHA|" demo-app/overlays/develop/kustomization.yaml | |
echo "Pushing changes to git config repo ..." | |
git config --global user.name mikesparr | |
git config --global user.email msparr@gmail.com | |
git add -A | |
git commit -m "Updated with build ${BUILD_ID} from ${REPO_NAME} commit ${COMMIT_SHA}" | |
git push origin master | |
volumes: | |
- name: 'ssh' | |
path: /root/.ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you!