Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bitbucket Pipelines deployment to a Google Container Engine configuration
options:
docker: true
pipelines:
branches:
master:
- step:
image: google/cloud-sdk:latest
name: Deploy to production
deployment: production
caches:
- docker
script:
# SETUP
- export IMAGE_NAME=us.gcr.io/$GCLOUD_PROJECT/$BITBUCKET_REPO_SLUG:$BITBUCKET_COMMIT
- export ENVIRONMENT=production
- echo $GCLOUD_API_KEYFILE | base64 -d > ~/.gcloud-api-key.json
- gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json
- gcloud config set project $GCLOUD_PROJECT
- gcloud container clusters get-credentials $GCLOUD_CLUSTER --zone=$GCLOUD_ZONE --project $GCLOUD_PROJECT
- gcloud auth configure-docker --quiet
# BUILD IMAGE
- docker build . -t $IMAGE_NAME
# PUBLISH IMAGE
- docker push $IMAGE_NAME
# DEPLOYMENT
- kubectl set image deployment $BITBUCKET_REPO_SLUG-$ENVIRONMENT $BITBUCKET_REPO_SLUG=$IMAGE_NAME --record --namespace=$K8S_NAMESPACE
@loooping

This comment has been minimized.

Copy link

@loooping loooping commented Oct 24, 2017

Fala Adilson, tranquilo? Cara, você já fez deploy dessa forma com alguma aplicação Laravel lá no GCE?

@brandoncollins7

This comment has been minimized.

Copy link

@brandoncollins7 brandoncollins7 commented Jun 10, 2018

How can you cache these components so gcloud and kubectl don't need to waste your minutes installing every time?

@adilsoncarvalho

This comment has been minimized.

Copy link
Owner Author

@adilsoncarvalho adilsoncarvalho commented Jul 30, 2018

@brandoncollins7 I updated my gist. A long time ago I started to use the Google SDK image. It has all we need. Another good thing that happened since was that Bitbucket Pipelines started to cache Docker as well. The docker image build based pipeline got really fast with those two things.

@adilsoncarvalho

This comment has been minimized.

Copy link
Owner Author

@adilsoncarvalho adilsoncarvalho commented Jul 30, 2018

@loooping Laravel nunca, mas já fiz deploys assim para Yii. Não tem nada de mais no processo. É bem tranquilo.

@Lucifer017

This comment has been minimized.

Copy link

@Lucifer017 Lucifer017 commented Mar 18, 2019

I have service account key, but it gave me ann error like this "Unable to read file [/root/gcloud/mct-deployments.json]". Where are you put the key? -> gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json

@hidekuro

This comment has been minimized.

Copy link

@hidekuro hidekuro commented Apr 15, 2019

@Lucifer017
Line16

- echo $GCLOUD_API_KEYFILE | base64 -d > ~/.gcloud-api-key.json

$GCLOUD_API_KEYFILE seems pre-provided base64 encoded keyfile with env vars in bitbucket repos or accounts.
see also: https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html

you can make base64 encoded keyfile text on your local-machine like below

cat /PATH/TO/KEYFILE | base64 | tr -d '\n'

and to set shown text your repos or accounts env vars to use to pipeline.

@martinyung

This comment has been minimized.

Copy link

@martinyung martinyung commented Apr 30, 2019

I change line 16 to:
echo $GCLOUD_API_KEYFILE > ~/.gcloud-api-key.json and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.