Skip to content

Commit

Permalink
Create Cloud Build config
Browse files Browse the repository at this point in the history
  • Loading branch information
suphon-t committed Dec 12, 2020
1 parent 59c6acb commit ca55485
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.dockerignore
.gitignore
.prettierrc
cloudbuild.yaml
Dockerfile
k8s.yaml
README.md
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:14-alpine AS build

WORKDIR /usr/src/app

# Install dependencies
COPY ["package.json", "yarn.lock", "./"]
RUN yarn

# Build the app
COPY . .
RUN yarn build

FROM node:14-alpine

ENV NODE_ENV production
WORKDIR /usr/src/app

RUN apk add postgresql-client

COPY ["package.json", "yarn.lock", "./"]
RUN yarn

COPY --from=build /usr/src/app/dist ./dist

EXPOSE 3000
CMD yarn start:prod
16 changes: 16 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:
# build the container image
- name: 'gcr.io/kaniko-project/executor:latest'
args:
- --destination=gcr.io/rnkm63/backend:$BRANCH_NAME
- --cache=true
- --cache-ttl=336h
# deploy container image to GKE
- name: 'gcr.io/cloud-builders/gke-deploy'
args:
- run
- --filename=k8s.yaml
- --image=gcr.io/rnkm63/backend:$BRANCH_NAME
- --location=asia-southeast1-b
- --cluster=rnkm63
- --namespace=dev
41 changes: 41 additions & 0 deletions k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "rnkm63-backend"
namespace: "default"
labels:
app: "rnkm63-backend"
spec:
replicas: 1
selector:
matchLabels:
app: "rnkm63-backend"
template:
metadata:
labels:
app: "rnkm63-backend"
spec:
containers:
- name: "backend-sha256-1"
image: "gcr.io/rnkm63/backend:latest"
---
apiVersion: "autoscaling/v2beta1"
kind: "HorizontalPodAutoscaler"
metadata:
name: "rnkm63-backend-hpa-yptr"
namespace: "default"
labels:
app: "rnkm63-backend"
spec:
scaleTargetRef:
kind: "Deployment"
name: "rnkm63-backend"
apiVersion: "apps/v1"
minReplicas: 1
maxReplicas: 5
metrics:
- type: "Resource"
resource:
name: "cpu"
targetAverageUtilization: 80
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api')
await app.listen(3000);
}
bootstrap();

0 comments on commit ca55485

Please sign in to comment.