diff --git a/cloudbuild.gke.yaml b/cloudbuild.gke.yaml index f8afc1e..fccc2e2 100644 --- a/cloudbuild.gke.yaml +++ b/cloudbuild.gke.yaml @@ -50,10 +50,26 @@ steps: args: ['push', 'gcr.io/$PROJECT_ID/mysql'] waitFor: ['build db'] +- id: 'kustomize build' + name: 'gcr.io/$PROJECT_ID/kustomize:latest' + entrypoint: 'bash' + args: + - '-c' + - | + # update images in k8s config to point to project's container registry + kustomize edit set image USER-REPO/web=gcr.io/$PROJECT_ID/web:latest + kustomize edit set image USER-REPO/mysql=gcr.io/$PROJECT_ID/mysql:latest + # save output to _config.yaml + kustomize build . > _config.yaml + # print to console + cat _config.yaml + dir: 'k8s' + waitFor: ['-'] + - id: 'deploy to staging' name: 'gcr.io/cloud-builders/kubectl' - args: ['apply', '-f', 'k8s/', '--namespace=test-$BUILD_ID'] - waitFor: ['push web','push db'] + args: ['apply', '-f', 'k8s/_config.yaml', '--namespace=test-$BUILD_ID'] + waitFor: ['push web','push db', 'kustomize build'] - id: 'get endpoint' name: 'gcr.io/cloud-builders/kubectl' diff --git a/k8s/db.yaml b/k8s/db.yaml index aef979e..98b6aa6 100644 --- a/k8s/db.yaml +++ b/k8s/db.yaml @@ -33,7 +33,7 @@ spec: containers: - name: mysql # Dev TODO: add your project id here - image: gcr.io/PROJECT-ID/mysql:latest + image: USER-REPO/mysql:latest env: - name: MYSQL_ROOT_PASSWORD value: "password" diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml new file mode 100644 index 0000000..605606b --- /dev/null +++ b/k8s/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- db.yaml +- web.yaml +- db-service.yaml +- web-service.yaml \ No newline at end of file diff --git a/k8s/service-web.yaml b/k8s/web-service.yaml similarity index 100% rename from k8s/service-web.yaml rename to k8s/web-service.yaml diff --git a/k8s/web.yaml b/k8s/web.yaml index f16865b..49e2aab 100644 --- a/k8s/web.yaml +++ b/k8s/web.yaml @@ -33,7 +33,7 @@ spec: containers: - name: web # Dev TODO: add your project id here - image: gcr.io/PROJECT-ID/web:latest + image: USER-REPO/web:latest env: - name: DB_HOST value: cookieshop-db