Skip to content

Instantly share code, notes, and snippets.

@korotkevics
Last active March 15, 2020 20:58
Show Gist options
  • Save korotkevics/7a8a304630951a78f1c2eaef87150a60 to your computer and use it in GitHub Desktop.
Save korotkevics/7a8a304630951a78f1c2eaef87150a60 to your computer and use it in GitHub Desktop.
cloudbuild.yaml - zakładamy, że $_BRANCH_NAME_LC jest zdefiniowane jako: $(echo $BRANCH_NAME | tr A-Z a-z), a $BRANCH_NAME z kolei jest istniejącą zmienną środowiskową zawierającą nazwę gałęzi. Robię taką konwersję, bo chcę utworzyć namespace o nazwie równej nazwie gałęzi z tym że musi być lowercase.
steps:
#step 1
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: [
'-c',
'docker pull gcr.io/$PROJECT_ID/clorinda-server:latest || exit 0'
]
#step 2
- name: gcr.io/cloud-builders/docker
args: [
'build',
'-t',
'gcr.io/$PROJECT_ID/clorinda-server:$BRANCH_NAME-$COMMIT_SHA',
'-t',
'gcr.io/$PROJECT_ID/clorinda-server:latest',
'.'
]
dir: 'server'
#step 3
- name: 'gcr.io/cloud-builders/kubectl'
args: ['apply', '-f', 'k8s/']
env:
- 'CLOUDSDK_COMPUTE_ZONE=europe-west6-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=clorinda'
dir: 'server'
#step 4
- name: 'gcr.io/cloud-builders/kubectl'
args: ['create', 'namespace', '$_BRANCH_NAME_LC']
env:
- 'CLOUDSDK_COMPUTE_ZONE=europe-west6-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=clorinda'
#step 5
- name: 'gcr.io/cloud-builders/kubectl'
args: [
'set',
'image',
'deployment',
'clorinda-server',
'clorinda-server=gcr.io/$PROJECT_ID/clorinda-server:$BRANCH_NAME-$COMMIT_SHA',
'--namespace',
'$_BRANCH_NAME_LC'
]
env:
- 'CLOUDSDK_COMPUTE_ZONE=europe-west6-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=clorinda'
substitutions:
_BRANCH_NAME_LC: $(echo $BRANCH_NAME | tr A-Z a-z)
# push images to Google Container Registry with tags
images: [
'gcr.io/$PROJECT_ID/clorinda-server:$BRANCH_NAME-$COMMIT_SHA',
'gcr.io/$PROJECT_ID/clorinda-server:latest'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment