Skip to content

Instantly share code, notes, and snippets.

@jeremyepling
Created August 21, 2019 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyepling/2223d10d0e58d772fe441a167e848ff5 to your computer and use it in GitHub Desktop.
Save jeremyepling/2223d10d0e58d772fe441a167e848ff5 to your computer and use it in GitHub Desktop.
Build and deploy to gcloud
name: Build and deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
container: google/cloud-sdk:latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Set up gcloud
env:
GCLOUD_PROJECT: bbi-core
GCLOUD_ZONE: asia-east1-a
GCLOUD_CLUSTER: kluster-01-asia-east1-a
ENVIRONMENT: production
APPLICATION_NAME: <app name>
GCLOUD_API_KEYFILE: ${{ secrets.GCLOUD_API_KEY }}
run: |
export IMAGE_NAME=gcr.io/$GCLOUD_PROJECT/$APPLICATION_NAME
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 config set compute/zone $GCLOUD_ZONE
gcloud container clusters get-credentials $GCLOUD_CLUSTER
gcloud auth configure-docker --quiet
- name: Build and push
env:
IMAGE_NAME: gcr.io/bbi-core/app
ENVIRONMENT: production
run: |
# BUILD IMAGE
docker build . -t $IMAGE_NAME -t $IMAGE_NAME:$GITHUB_SHA -t $IMAGE_NAME:$ENVIRONMENT
# PUBLISH IMAGE
docker push $IMAGE_NAME
- name: Deploy
env:
CONFIG_MAP: Applicaiton-Production
ENVIRONMENT: Production
IMAGE_NAME: gcr.io/bbi-core/app
run: |
# CREATE and FLUSH / UPDATE CONFIGS
set +e
kubectl create configmap $CONFIG_MAP --from-env-file=.env-$ENVIRONMENT
kubectl create configmap $CONFIG_MAP --from-env-file=.env-$ENVIRONMENT --dry-run -o yaml | kubectl replace -f -
set -e
# DEPLOYMENT
kubectl apply -f deployment-$ENVIRONMENT.yml
kubectl set image deployment $CONFIG_MAP wordpress=$IMAGE_NAME:$GITHUB_SHA
# EXPOSE
kubectl apply -f loadbalancer-$ENVIRONMENT.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment