Skip to content
68 changes: 68 additions & 0 deletions sample-app/builder/cloudbuild-canary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


steps:

### Build

- id: 'build'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker build -t gcr.io/$PROJECT_ID/gceme:${SHORT_SHA} .



### Test


### Publish
- id: 'publish'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker push gcr.io/$PROJECT_ID/gceme:${SHORT_SHA}



### Deploy
- id: 'deploy'
name: 'gcr.io/cloud-builders/gcloud'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'bash'
args:
- '-c'
- |
CLUSTER=$$(gcloud config get-value container/cluster)
PROJECT=$$(gcloud config get-value core/project)
ZONE=$$(gcloud config get-value compute/zone)

gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"


sed -i 's|gcr.io/cloud-solutions-images/gceme:.*|gcr.io/$PROJECT_ID/gceme:${SHORT_SHA}|' ./kubernetes/deployments/canary/*.yaml

kubectl apply --namespace production --recursive -f kubernetes/deployments/canary
kubectl apply --namespace production --recursive -f kubernetes/services

71 changes: 71 additions & 0 deletions sample-app/builder/cloudbuild-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:

### Build

- id: 'build'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker build -t gcr.io/$PROJECT_ID/gcme:${BRANCH_NAME}-${SHORT_SHA} .



### Test


### Publish
- id: 'publish'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker push gcr.io/$PROJECT_ID/gcme:${BRANCH_NAME}-${SHORT_SHA}



### Deploy
- id: 'deploy'
name: 'gcr.io/cloud-builders/gcloud'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'bash'
args:
- '-c'
- |
CLUSTER=$$(gcloud config get-value container/cluster)
PROJECT=$$(gcloud config get-value core/project)
ZONE=$$(gcloud config get-value compute/zone)

gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"





sed -i 's|gcr.io/cloud-solutions-images/gceme:.*|gcr.io/$PROJECT_ID/gcme:${BRANCH_NAME}-${SHORT_SHA}|' ./kubernetes/deployments/dev/*.yaml

kubectl get ns ${BRANCH_NAME} || kubectl create ns ${BRANCH_NAME}
kubectl apply --namespace ${BRANCH_NAME} --recursive -f kubernetes/deployments/dev
kubectl apply --namespace ${BRANCH_NAME} --recursive -f kubernetes/services

76 changes: 76 additions & 0 deletions sample-app/builder/cloudbuild-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Usage:
# gcloud container builds submit \
# --config cloudbuild-local.yaml \
# --substitutions=_VERSION=someversion,_USER=$(whoami),_CLOUDSDK_COMPUTE_ZONE=${ZONE},_CLOUDSDK_CONTAINER_CLUSTER=${CLUSTER} .


steps:

### Build

- id: 'build'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
echo $PROJECT_ID
docker build -t gcr.io/$PROJECT_ID/gceme:${_USER}-${_VERSION} .



### Test


### Publish
- id: 'publish'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker push gcr.io/$PROJECT_ID/gceme:${_USER}-${_VERSION}


### Deploy
- id: 'deploy'
name: 'gcr.io/cloud-builders/gcloud'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'bash'
args:
- '-c'
- |
CLUSTER=$$(gcloud config get-value container/cluster)
PROJECT=$$(gcloud config get-value core/project)
ZONE=$$(gcloud config get-value compute/zone)

gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"

sed -i 's|gcr.io/cloud-solutions-images/gceme:.*|gcr.io/$PROJECT_ID/gceme:${_USER}-${_VERSION}|' ./kubernetes/deployments/dev/*.yaml

kubectl get ns ${_USER} || kubectl create ns ${_USER}
kubectl apply --namespace ${_USER} --recursive -f kubernetes/deployments/dev
kubectl apply --namespace ${_USER} --recursive -f kubernetes/services

echo service available at http://`kubectl --namespace=${_USER} get service/gceme-frontend -o jsonpath="{.status.loadBalancer.ingress[0].ip}"`


70 changes: 70 additions & 0 deletions sample-app/builder/cloudbuild-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:

### Build

- id: 'build'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker build -t gcr.io/$PROJECT_ID/gceme:$TAG_NAME .



### Test


### Publish
- id: 'publish'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker push gcr.io/$PROJECT_ID/gceme:$TAG_NAME



### Deploy
- id: 'deploy'
name: 'gcr.io/cloud-builders/gcloud'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'bash'
args:
- '-c'
- |
CLUSTER=$$(gcloud config get-value container/cluster)
PROJECT=$$(gcloud config get-value core/project)
ZONE=$$(gcloud config get-value compute/zone)


gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"



sed -i 's|gcr.io/cloud-solutions-images/gceme:.*|gcr.io/$PROJECT_ID/gceme:$TAG_NAME|' ./kubernetes/deployments/prod/*.yaml

kubectl get ns production || kubectl create ns production
kubectl apply --namespace production --recursive -f kubernetes/deployments/prod
kubectl apply --namespace production --recursive -f kubernetes/services

71 changes: 71 additions & 0 deletions sample-app/builder/cloudbuild-prod2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:

### Build

- id: 'build'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker build -t gcr.io/$PROJECT_ID/gceme:$TAG_NAME .



### Test


### Publish
- id: 'publish'
name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker push gcr.io/$PROJECT_ID/gceme:$TAG_NAME



### Deploy
- id: 'deploy'
name: 'gcr.io/cloud-builders/gcloud'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
- 'KUBECONFIG=/kube/config'
entrypoint: 'bash'
args:
- '-c'
- |
CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}
PROJECT=$$(gcloud config get-value core/project)
ZONE=${_CLOUDSDK_COMPUTE_ZONE}

gcloud container clusters get-credentials "$${CLUSTER}" \
--project "$${PROJECT}" \
--zone "$${ZONE}"



sed -i 's|gcr.io/cloud-solutions-images/gceme:.*|gcr.io/$PROJECT_ID/gceme:$TAG_NAME|' ./k8s/production/*.yaml

kubectl get ns production || kubectl create ns production
kubectl apply --namespace production --recursive -f k8s/production
kubectl apply --namespace production --recursive -f k8s/services



Loading