Skip to content

Commit 36c1bed

Browse files
authored
Merge pull request #22 from cupofpython/refactor
Refactor
2 parents 458cfad + 5bb08c4 commit 36c1bed

22 files changed

+170
-108
lines changed

.github/workflows/build-and-push.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and deploy image
1+
name: Build and deploy images
22

33
on:
44
workflow_call:
@@ -12,7 +12,8 @@ on:
1212

1313
env:
1414
REGISTRY: samanthamorris684
15-
IMAGE_NAME: catbot
15+
FRONTEND_IMAGE_NAME: catbot-frontend
16+
BACKEND_IMAGE_NAME: catbot-backend
1617
USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
1718
PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
1819

@@ -36,12 +37,21 @@ jobs:
3637
endpoint: "demonstrationorg/default"
3738
install: true
3839

39-
- name: Build and push
40+
- name: Build and push frontend
4041
uses: docker/build-push-action@v6
4142
with:
4243
push: true
44+
file: Dockerfile.frontend
4345
platforms: linux/amd64
44-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}
46+
tags: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}
47+
48+
- name: Build and push backend
49+
uses: docker/build-push-action@v6
50+
with:
51+
push: true
52+
file: Dockerfile.backend
53+
platforms: linux/amd64
54+
tags: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}
4555

4656

4757

.github/workflows/deploy-to-eks.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ on:
1212

1313
env:
1414
REGISTRY: samanthamorris684
15-
IMAGE_NAME: catbot
15+
FRONTEND_IMAGE_NAME: catbot-frontend
16+
BACKEND_IMAGE_NAME: catbot-backend
1617
EKS_CLUSTER_NAME: catbot-cluster
1718
NAMESPACE: cat-chatbot
1819
AWS_REGION: us-east-1
@@ -35,5 +36,7 @@ jobs:
3536
- name: Deploy to EKS
3637
run: |
3738
aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }}
38-
kubectl set image deployment/server server=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.IMAGE_TAG }} -n ${{ env.NAMESPACE }}
39-
kubectl rollout status deployment/server -n ${{ env.NAMESPACE }}
39+
kubectl set image deployment/frontend frontend=${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ inputs.IMAGE_TAG }} -n ${{ env.NAMESPACE }}
40+
kubectl rollout status deployment/frontend -n ${{ env.NAMESPACE }}
41+
kubectl set image deployment/backend backend=${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ inputs.IMAGE_TAG }} -n ${{ env.NAMESPACE }}
42+
kubectl rollout status deployment/backend -n ${{ env.NAMESPACE }}

.github/workflows/scout.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
env:
1313
REGISTRY: samanthamorris684
14-
IMAGE_NAME: catbot
14+
FRONTEND_IMAGE_NAME: catbot-frontend
1515
# Change from latest
1616
COMPARE_TAG: latest
1717
USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
@@ -27,13 +27,13 @@ jobs:
2727
username: ${{ env.USERNAME }}
2828
password: ${{ env.PASSWORD }}
2929

30-
- name: Docker Scout
30+
- name: Docker Scout (Frontend)
3131
id: docker-scout
3232
uses: docker/scout-action@v1
3333
with:
3434
command: compare
35-
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}
36-
to: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.COMPARE_TAG }}
35+
image: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ inputs.IMAGE_TAG }}
36+
to: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ env.COMPARE_TAG }}
3737
ignore-unchanged: true
3838
only-severities: critical,high
3939
write-comment: true

Dockerfile

Lines changed: 0 additions & 37 deletions
This file was deleted.

Dockerfile.backend

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build stage
4+
ARG NODE_VERSION=23.10.0
5+
FROM node:${NODE_VERSION}-alpine AS builder
6+
7+
WORKDIR /usr/src/app
8+
9+
COPY package.json package-lock.json ./
10+
11+
# Install production dependencies only
12+
RUN npm ci --only=production
13+
14+
# Copy app code
15+
COPY server.js ./
16+
17+
# Runtime stage: new clean container
18+
FROM node:${NODE_VERSION}-alpine
19+
20+
WORKDIR /usr/src/app
21+
22+
# Copy production node_modules and server.js
23+
COPY --from=builder /usr/src/app/node_modules ./node_modules
24+
COPY --from=builder /usr/src/app/server.js ./server.js
25+
26+
# Expose backend ports
27+
EXPOSE 5001
28+
EXPOSE 5002
29+
30+
# Start the backend
31+
CMD ["node", "server.js"]

Dockerfile.frontend

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build Stage
4+
ARG NODE_VERSION=23.10.0
5+
FROM node:${NODE_VERSION}-alpine AS builder
6+
7+
WORKDIR /usr/src/app
8+
9+
# Copy package files first (cache layer)
10+
COPY package.json package-lock.json ./
11+
12+
# Install all dependencies
13+
RUN npm ci
14+
15+
# Copy source files
16+
COPY src/ ./src
17+
COPY public/ ./public
18+
19+
# Runtime Stage
20+
FROM node:${NODE_VERSION}-alpine
21+
22+
WORKDIR /usr/src/app
23+
24+
# Copy node_modules from builder
25+
COPY --from=builder /usr/src/app/node_modules ./node_modules
26+
27+
# Copy app source
28+
COPY src/ ./src
29+
COPY public/ ./public
30+
COPY package.json package-lock.json ./
31+
32+
# Expose the port that the app listens on
33+
EXPOSE 3000
34+
35+
# Run the application
36+
CMD ["npm", "start"]

compose.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@
88
# database or a cache. For examples, see the Awesome Compose repository:
99
# https://github.com/docker/awesome-compose
1010
services:
11-
server:
12-
container_name: server
13-
command: npm run start:dev
11+
frontend:
12+
container_name: frontend
1413
depends_on:
15-
- model
14+
- backend
1615
build:
1716
context: .
17+
dockerfile: Dockerfile.frontend
1818
volumes:
1919
- ./:/usr/src/app
2020
env_file:
2121
- .env.compose
2222
ports:
2323
- 3000:3000
24+
backend:
25+
container_name: backend
26+
depends_on:
27+
- model
28+
build:
29+
context: .
30+
dockerfile: Dockerfile.backend
31+
volumes:
32+
- ./:/usr/src/app
33+
env_file:
34+
- .env.compose
35+
ports:
2436
- 5002:5002
2537
model:
2638
container_name: model
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,34 @@
33
apiVersion: apps/v1
44
kind: Deployment
55
metadata:
6-
name: server
6+
name: backend
77
namespace: cat-chatbot
88
labels:
99
com.docker.compose.project: cat-chatbot
10-
com.docker.compose.service: server
10+
com.docker.compose.service: backend-service
1111
spec:
1212
replicas: 2
1313
selector:
1414
matchLabels:
1515
com.docker.compose.project: cat-chatbot
16-
com.docker.compose.service: server
16+
com.docker.compose.service: backend-service
1717
strategy:
1818
type: Recreate
1919
template:
2020
metadata:
2121
labels:
2222
com.docker.compose.project: cat-chatbot
23-
com.docker.compose.service: server
23+
com.docker.compose.service: backend-service
2424
com.docker.compose.network.default: "true"
2525
spec:
2626
containers:
27-
- name: server
28-
image: samanthamorris684/catbot:latest
27+
- name: backend
28+
image: samanthamorris684/catbot-backend:latest
2929
imagePullPolicy: Always
3030
env:
3131
- name: NODE_ENV
3232
value: "production"
3333
ports:
34-
- name: app-3000
35-
containerPort: 3000
3634
- name: server-5001
3735
containerPort: 5001
3836
resources:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: server-backend
4+
name: backend-service
55
namespace: cat-chatbot
66
spec:
77
selector:
88
com.docker.compose.project: cat-chatbot
9-
com.docker.compose.service: server
9+
com.docker.compose.service: backend-service
1010
ports:
1111
- name: api
1212
port: 5001

out/base/frontend-deployment.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! server-deployment.yaml
2+
# Generated code, do not edit
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: frontend
7+
namespace: cat-chatbot
8+
labels:
9+
com.docker.compose.project: cat-chatbot
10+
com.docker.compose.service: frontend-service
11+
spec:
12+
replicas: 2
13+
selector:
14+
matchLabels:
15+
com.docker.compose.project: cat-chatbot
16+
com.docker.compose.service: frontend-service
17+
strategy:
18+
type: Recreate
19+
template:
20+
metadata:
21+
labels:
22+
com.docker.compose.project: cat-chatbot
23+
com.docker.compose.service: frontend-service
24+
com.docker.compose.network.default: "true"
25+
spec:
26+
containers:
27+
- name: frontend
28+
image: samanthamorris684/catbot-frontend:latest
29+
imagePullPolicy: Always
30+
env:
31+
- name: NODE_ENV
32+
value: "production"
33+
ports:
34+
- name: app-3000
35+
containerPort: 3000
36+
resources:
37+
requests:
38+
cpu: "250m"
39+
memory: "1Gi"
40+
imagePullSecrets:
41+
- name: regcred

0 commit comments

Comments
 (0)