docs: updated README #92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE. | |
# | |
# To configure this workflow: | |
# | |
# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc. | |
# | |
# 2. Set up secrets in your workspace: GKE_PROJECT with the name of the project, GKE_EMAIL with the service account email, GKE_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs). | |
# | |
# 3. Change the values for the GKE_ZONE, GKE_CLUSTER, IMAGE, REGISTRY_HOSTNAME and DEPLOYMENT_NAME environment variables (below). | |
name: Build and Deploy to GKE | |
on: | |
push: | |
branches: | |
- main | |
# Environment variables available to all jobs and steps in this workflow | |
env: | |
GKE_PROJECT: ${{ secrets.GKE_PROJECT }} | |
GKE_EMAIL: ${{ secrets.GKE_EMAIL }} | |
GITHUB_SHA: ${{ github.sha }} | |
GKE_ZONE: europe-west2-a | |
REGISTRY_HOSTNAME: gcr.io | |
jobs: | |
setup-build-publish-deploy: | |
name: Setup, Build, Publish, and Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
# Setup gcloud CLI | |
- uses: google-github-actions/setup-gcloud@v0 | |
with: | |
version: "270.0.0" | |
service_account_email: ${{ secrets.GKE_EMAIL }} | |
service_account_key: ${{ secrets.GKE_KEY }} | |
# Configure docker to use the gcloud command-line tool as a credential helper | |
- run: | | |
# Set up docker to authenticate | |
# via gcloud command-line tool. | |
gcloud auth configure-docker | |
- name: Extract branch name | |
shell: bash | |
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | |
id: extract_branch | |
# Build the Docker image | |
# TODO pasar los hosts por build-arg al build | |
- name: Build | |
run: | | |
docker build --target app -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"app_${{ steps.extract_branch.outputs.branch }}":"$GITHUB_SHA" \ | |
--build-arg GITHUB_SHA="$GITHUB_SHA" ./ | |
# Push the Docker image to Google Container Registry | |
- name: Publish | |
run: | | |
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/app_${{ steps.extract_branch.outputs.branch }}:$GITHUB_SHA | |
# Set up kustomize | |
- name: Set up Kustomize | |
run: | | |
curl -o kustomize-zip --location https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.5.4/kustomize_v4.5.4_linux_amd64.tar.gz | |
tar -xvf kustomize-zip | |
chmod u+x ./kustomize | |
# Deploy the Docker image to the GKE cluster | |
- name: Deploy | |
run: | | |
gcloud container clusters get-credentials cluster-${{ steps.extract_branch.outputs.branch }} --zone $GKE_ZONE --project $GKE_PROJECT | |
(cd ./deploy && ../kustomize edit set image ENV_IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/app_${{ steps.extract_branch.outputs.branch }}:$GITHUB_SHA) | |
./kustomize build ./deploy | kubectl apply -f - | |
kubectl get deploy --output name | \ | |
timeout 3m \ | |
xargs -n1 -t \ | |
kubectl rollout status | |
kubectl get services -o wide |