-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76d03fb
commit 8da6e47
Showing
15 changed files
with
375 additions
and
33 deletions.
There are no files selected for viewing
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: 'Initialize Deployment to GKE' | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: chatemo | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: chatemo | ||
template: | ||
metadata: | ||
labels: | ||
app: chatemo | ||
spec: | ||
restartPolicy: Always | ||
containers: | ||
- name: chatemo | ||
image: australia-southeast1-docker.pkg.dev/chatemo/francizhong/chatemo:latest | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 3000 | ||
resources: | ||
requests: | ||
memory: '512Mi' | ||
cpu: '500m' | ||
limits: | ||
memory: '1Gi' | ||
cpu: '1' | ||
env: | ||
- name: DATABASE_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: DATABASE_URL | ||
- name: REDIS_HOST | ||
value: 'redis' | ||
- name: REDIS_PORT | ||
value: '6379' | ||
- name: REDIS_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: REDIS_PASSWORD | ||
- name: NEXTAUTH_URL | ||
valueFrom: | ||
configMapKeyRef: | ||
name: env-config | ||
key: NEXTAUTH_URL | ||
- name: NEXTAUTH_SECRET | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: NEXTAUTH_SECRET | ||
- name: GOOGLE_CLIENT_ID | ||
valueFrom: | ||
configMapKeyRef: | ||
name: env-config | ||
key: GOOGLE_CLIENT_ID | ||
- name: GOOGLE_CLIENT_SECRET | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: GOOGLE_CLIENT_SECRET | ||
- name: AWS_ACCESS_KEY_ID | ||
valueFrom: | ||
configMapKeyRef: | ||
name: env-config | ||
key: AWS_ACCESS_KEY_ID | ||
- name: AWS_SECRET_ACCESS_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: AWS_SECRET_ACCESS_KEY | ||
- name: AWS_REGION | ||
valueFrom: | ||
configMapKeyRef: | ||
name: env-config | ||
key: AWS_REGION | ||
- name: AWS_S3_BUCKET_NAME | ||
valueFrom: | ||
configMapKeyRef: | ||
name: env-config | ||
key: AWS_S3_BUCKET_NAME |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: chatemo | ||
spec: | ||
type: LoadBalancer | ||
selector: | ||
app: chatemo | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 3000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: postgres | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: postgres | ||
template: | ||
metadata: | ||
labels: | ||
app: postgres | ||
spec: | ||
restartPolicy: Always | ||
containers: | ||
- name: postgres | ||
image: postgres:17-alpine | ||
ports: | ||
- containerPort: 5432 | ||
resources: | ||
requests: | ||
memory: '512Mi' | ||
cpu: '500m' | ||
limits: | ||
memory: '1Gi' | ||
cpu: '1' | ||
env: | ||
- name: POSTGRES_DB | ||
value: 'chatemo' | ||
- name: POSTGRES_USER | ||
value: 'postgres' | ||
- name: POSTGRES_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: env-secret | ||
key: POSTGRES_PASSWORD | ||
volumeMounts: | ||
- mountPath: /var/lib/postgresql/data | ||
name: postgres-storage | ||
subPath: chatemo-data | ||
volumes: | ||
- name: postgres-storage | ||
persistentVolumeClaim: | ||
claimName: postgres-pvc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: postgres-pvc | ||
spec: | ||
storageClassName: standard | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 20Gi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: postgres | ||
spec: | ||
type: LoadBalancer | ||
selector: | ||
app: postgres | ||
ports: | ||
- protocol: TCP | ||
port: 5432 | ||
targetPort: 5432 |
Oops, something went wrong.