Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Google Cloud CI #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
workflow_dispatch:
push:
branches:
- main

name: Delpoy to Google Cloud Run
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT }}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true # Set to true to authenticate the Cloud Run action

- name: Authorize Docker Push
run: gcloud auth configure-docker

- name: Build Server Container
run: docker build -t gcr.io/${{ env.PROJECT_ID }}/server:${{ github.sha }} server

- name: Build Client Container
run: docker build -t gcr.io/${{ env.PROJECT_ID }}/client:${{ github.sha }} client

- name: Push Server Container
run: docker push gcr.io/${{ env.PROJECT_ID }}/server:${{ github.sha }}

- name: Push Client Container
run: docker push gcr.io/${{ env.PROJECT_ID }}/client:${{ github.sha }}

- name: Deploy Server
id: deploy_server
uses: google-github-actions/[email protected]
with:
service: server
image: gcr.io/${{ env.PROJECT_ID }}/server:${{ github.sha }}

- name: Show Server Output
run: echo ${{ steps.deploy_server.outputs.url }}

- name: Deploy Client
id: deploy_client
uses: google-github-actions/[email protected]
with:
service: client
image: gcr.io/${{ env.PROJECT_ID }}/client:${{ github.sha }}

- name: Show Client Output
run: echo ${{ steps.deploy_client.outputs.url }}

3 changes: 0 additions & 3 deletions client/.env.template

This file was deleted.

10 changes: 10 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:12-alpine AS builder
WORKDIR /app
COPY . .
RUN yarn install --production
RUN yarn build

FROM nginx:alpine
COPY ./nginx.conf /etc/nginx/templates/default.conf.template
COPY --from=builder /app/build /usr/share/nginx/html

15 changes: 15 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

location /api/ {
proxy_pass ${API_SERVER_URL}/api/;
}

location / {
root /usr/share/nginx/html;
try_files $uri /index.html;
}
}

8 changes: 4 additions & 4 deletions client/src/apiBudget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export async function getBalances() {
const res = await fetch(new URL('/api/transaction/balance', process.env.REACT_APP_API_SERVER_URL));
const res = await fetch('/api/transaction/balance');
return res.json();
}

Expand All @@ -12,7 +12,7 @@ export async function createTransaction(description, amount) {
'amount': parseFloat(amount)
}

await fetch(new URL('/api/transaction', process.env.REACT_APP_API_SERVER_URL), {
await fetch('/api/transaction', {
body: JSON.stringify(transaction),
method: 'POST',
headers: {
Expand All @@ -22,8 +22,8 @@ export async function createTransaction(description, amount) {
}

export async function deleteTransaction(id) {
await fetch(new URL(`/api/transaction/${id}`, process.env.REACT_APP_API_SERVER_URL), {
await fetch(`/api/transaction/${id}`, {
method: 'DELETE'
});

}
}
10 changes: 5 additions & 5 deletions client/src/apiMember.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export async function getMembers() {
const res = await fetch(new URL('/api/member', process.env.REACT_APP_API_SERVER_URL));
const res = await fetch('/api/member');
return res.json();
}

Expand All @@ -11,7 +11,7 @@ export async function createMember(name) {
'expiryDate': dateStr
}

await fetch(new URL('/api/member', process.env.REACT_APP_API_SERVER_URL), {
await fetch('/api/member', {
body: JSON.stringify(member),
method: 'POST',
headers: {
Expand All @@ -21,14 +21,14 @@ export async function createMember(name) {
}

export async function activateMember(id) {
await fetch(new URL(`api/member/${id}`, process.env.REACT_APP_API_SERVER_URL), {
await fetch(`/api/member/${id}`, {
method: 'PUT'
});
}

export async function deleteMember(id) {
await fetch(new URL(`/api/member/${id}`, process.env.REACT_APP_API_SERVER_URL), {
await fetch(`/api/member/${id}`, {
method: 'DELETE'
});

}
}
17 changes: 17 additions & 0 deletions ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Initialize Database Schema

create table member (
id bigint not null auto_increment,
name varchar(50) not null,
expiry_date varchar(12) not null,
primary key (id)
);

create table transaction (
id bigint not null auto_increment,
date varchar(12) not null,
description varchar(50) not null,
amount double(19,4) not null,
primary key (id)
);

40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3"
services:
web:
build: ./client
ports:
- 3000:3000
environment:
PORT: 3000
API_SERVER_URL: http://backend:4000
depends_on:
- backend
backend:
build: ./server
environment:
SERVER_PORT: 4000
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/rich-neighborhoods
SPRING_DATASOURCE_USERNAME: rich-neighborhoods
SPRING_DATASOURCE_PASSWORD: weroinvoiwenr
SPRING_JPA_HIBERNATE_DDL-AUTO: update
SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT: org.hibernate.dialect.MySQL8Dialect
ports:
- 4000:4000
restart: always
depends_on:
- db
db:
image: mysql
environment:
MYSQL_USER: rich-neighborhoods
MYSQL_PASSWORD: weroinvoiwenr
MYSQL_DATABASE: rich-neighborhoods
MYSQL_RANDOM_ROOT_PASSWORD: "true"
ports:
- 3306:3306
volumes:
- dbdata:/var/lib/mysql
- ./ddl.sql:/docker-entrypoint-initdb.d/ddl.sql:ro
volumes:
dbdata:

11 changes: 11 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM gradle:7-jdk11 AS builder
WORKDIR /project
COPY . .
RUN gradle build

FROM openjdk:11
WORKDIR /jars
COPY --from=builder /project/build .

CMD java -jar /jars/**/*.jar

This file was deleted.