Skip to content

Commit

Permalink
Merge pull request #68 from merogersdev/feature/67-cicd-to-gcp
Browse files Browse the repository at this point in the history
Feature/67 cicd to gcp
  • Loading branch information
merogersdev authored Feb 27, 2024
2 parents 4b21ae2 + ffe86e9 commit 6220e2c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 107 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
name: Build and Push Images to GCP
on:
push:
branches: [main]
jobs:
build-push-gcr:
name: Build and Push to GCP
runs-on: ubuntu-latest
env:
DATABASE_IMAGE_NAME: peace-of-mind-db
FRONTEND_IMAGE_NAME: peace-of-mind-frontend
BACKEND_IMAGE_NAME: peace-of-mind-backend
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION: ${{ secrets.GCP_REGION }}
GCP_ZONE: ${{ secrets.GCP_ZONE }}
GCP_INSTANCE_NAME: ${{ secrets.GCP_INSTANCE_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}

- name: Build Docker Images
run: |-
docker build -t $DATABASE_IMAGE_NAME:latest ./db/
docker build -t $FRONTEND_IMAGE_NAME:latest ./frontend/
docker build -t $BACKEND_IMAGE_NAME:latest ./backend/
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
gcloud auth configure-docker $GCP_REGION-docker.pkg.dev --quiet
- name: Tag and Push Images to GCP
run: |-
docker tag $DATABASE_IMAGE_NAME:latest $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$DATABASE_IMAGE_NAME:latest
docker tag $BACKEND_IMAGE_NAME:latest $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$BACKEND_IMAGE_NAME:latest
docker tag $FRONTEND_IMAGE_NAME:latest $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$FRONTEND_IMAGE_NAME:latest
docker push $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$DATABASE_IMAGE_NAME:latest
docker push $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$BACKEND_IMAGE_NAME:latest
docker push $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$FRONTEND_IMAGE_NAME:latest
deploy:
name: Deploy to GCP VM
runs-on: ubuntu-latest
needs: build-push-gcr
steps:
- name: "SSH"
uses: appleboy/ssh-action@v1.0.3
env:
GCP_REGION: ${{ secrets.GCP_REGION }}
POSTGRES_USER: "peaceofmind"
POSTGRES_PASSWORD: "${{ secrets.POSTGRES_PASSWORD }}"
POSTGRES_DB: "peaceofmind"
POSTGRES_DB_TEST: "peaceofmind_test"
POSTGRES_PORT: 5432
DATABASE_IMAGE_NAME: peace-of-mind-db
FRONTEND_IMAGE_NAME: peace-of-mind-frontend
BACKEND_IMAGE_NAME: peace-of-mind-backend
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
JWT_SECRET: "${{ secrets.JWT_SECRET }}"
API_KEY: "${{ secrets.API_KEY }}"
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_KEY }}
envs: GCP_REGION,POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB,POSTGRES_DB_TEST,POSTGRES_PORT,DATABASE_IMAGE_NAME,FRONTEND_IMAGE_NAME,BACKEND_IMAGE_NAME,PROJECT_ID,JWT_SECRET,API_KEY
script: |
gcloud auth configure-docker --quiet
gcloud auth configure-docker $GCP_REGION-docker.pkg.dev --quiet
docker stop $(docker ps -aq)
docker rm $(docker ps -aq) -f
docker network rm peace-of-mind-network -f
docker network create peace-of-mind-network
docker run -d --restart=unless-stopped --network=peace-of-mind-network -p 5432:5432 -v pgdata:/var/lib/postgresql/data -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_DB_TEST=$POSTGRES_DB_TEST --name $DATABASE_IMAGE_NAME $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$DATABASE_IMAGE_NAME
docker run -d --restart=unless-stopped --network=peace-of-mind-network -p 5000:5000 -e NODE_ENV='production' -e DB_HOST=$DATABASE_IMAGE_NAME -e DB_PORT=$POSTGRES_PORT -e DB_USER=$POSTGRES_USER -e DB_PASS=$POSTGRES_PASSWORD -e DB_DATA=$POSTGRES_DB -e DB_DATA_TEST=$POSTGRES_DB_TEST -e JWT_SECRET=$JWT_SECRET -e API_KEY=$API_KEY --name $BACKEND_IMAGE_NAME $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$BACKEND_IMAGE_NAME
docker run -d --restart=unless-stopped --network=peace-of-mind-network -p 3000:80 --name $FRONTEND_IMAGE_NAME $GCP_REGION-docker.pkg.dev/$PROJECT_ID/peace-of-mind/$FRONTEND_IMAGE_NAME
105 changes: 0 additions & 105 deletions .github/workflows/main.yml

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Quick Summary

BrainStation Web Development Bootcamp Capstone Project. Utilizes SASS/SCSS, React, JWT Tokens, Vite, Node, Express and a PostgreSQL Database. Demo is deployed to an AWS EC2 instance running Ubuntu Server.
BrainStation Web Development Bootcamp Capstone Project. Utilizes SASS/SCSS, React, JWT Tokens, Vite, Node, Express and a PostgreSQL Database. Demo is deployed to a Google Cloud VM running Ubuntu Server.

## Goal

Expand Down Expand Up @@ -69,5 +69,6 @@ Once you have cloned this repository to your computer, this application has the
![Testing-Library](https://img.shields.io/badge/-TestingLibrary-%23E33332?style=for-the-badge&logo=testing-library&logoColor=white)
![Postgres](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white)
![Ubuntu](https://img.shields.io/badge/Ubuntu-E95420?style=for-the-badge&logo=ubuntu&logoColor=white)
![AWS](https://img.shields.io/badge/AWS-%23FF9900.svg?style=for-the-badge&logo=amazon-aws&logoColor=white)
![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)
![Google Cloud](https://img.shields.io/badge/GoogleCloud-%234285F4.svg?style=for-the-badge&logo=google-cloud&logoColor=white)
![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)

0 comments on commit 6220e2c

Please sign in to comment.