Skip to content

test workflows

test workflows #2

Workflow file for this run

name: 'Initialize Deployment to GKE'
on:
push:
branches:
- 'deploy-workflow'
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
GAR_LOCATION: ${{ secrets.GAR_LOCATION }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
GKE_ZONE: ${{ secrets.GKE_ZONE }}
REPOSITORY: ${{ secrets.REPOSITORY }}
IMAGE: ${{ secrets.IMAGE }}
jobs:
setup-build-publish-deploy:
name: 'Deploy Postgres, Redis and Build Chatemo as the latest'
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'
# Configure Workload Identity Federation and generate an access token.
#
# See https://github.com/google-github-actions/auth for more options,
# including authenticating via a JSON credentials file.
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
project_id: '${{ env.PROJECT_ID }}'
workload_identity_provider: '${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}'
service_account: ${{ secrets.SERVICE_ACCOUNT }}
# Authenticate Docker to Google Cloud Artifact Registry
- name: 'Docker Auth'
uses: 'docker/login-action@v3'
with:
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.auth_token }}'
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
# Get the GKE credentials so we can deploy to the cluster
- name: 'Set up GKE credentials'
uses: 'google-github-actions/get-gke-credentials@v2'
with:
cluster_name: '${{ env.GKE_CLUSTER }}'
location: '${{ env.GKE_ZONE }}'
# Set up config map and secrets
- name: 'Apply config map and secret'
run: |-
kubectl create configmap env-config \
--from-literal=NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }} \
--from-literal=GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} \
--from-literal=AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
--from-literal=AWS_REGION=${{ secrets.AWS_REGION }} \
--from-literal=AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }} \
--dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic env-secret \
--from-literal=REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} \
--from-literal=POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} \
--from-literal=DATABASE_URL=${{ secrets.DATABASE_URL }} \
--from-literal=NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} \
--from-literal=GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} \
--from-literal=AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
--dry-run=client -o yaml | kubectl apply -f -
# Deploy Postgres
- name: 'Deploy Postgres in GKE'
run: |-
kubectl apply -f ./k8s/postgres-pvc.yml
kubectl apply -f ./k8s/postgres-deployment.yml
kubectl apply -f ./k8s/postgres-service.yml
kubectl rollout status deployment/postgres
# Deploy Redis
- name: 'Deploy Redis in GKE'
run: |-
kubectl apply -f ./k8s/redis-pvc.yml
kubectl apply -f ./k8s/redis-deployment.yml
kubectl apply -f ./k8s/redis-service.yml
kubectl rollout status deployment/redis
# Build the Docker image with latest tag
- name: 'Build and push Docker container'
id: build-image
run: |-
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://${GAR_LOCATION}-docker.pkg.dev
DOCKER_TAG="${GAR_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE}:latest"
docker build \
--tag "${DOCKER_TAG}" \
.
docker push "${DOCKER_TAG}"
echo "::set-output name=image::${DOCKER_TAG}"
# Deploy Redis
- name: 'Deploy Chatemo in GKE'
run: |-
kubectl apply -f ./k8s/chatemo-deployment.yml
kubectl apply -f ./k8s/chatemo-service.yml
kubectl rollout status deployment/chatemo
kubectl get services -o wide