Skip to content

Commit e9a1030

Browse files
git commit -m 'all documentation for assignment 2'
1 parent 78cedba commit e9a1030

File tree

6 files changed

+231
-24
lines changed

6 files changed

+231
-24
lines changed

.github/workflows/autodeploy.yml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
CI-PIPELINE:
88
runs-on: ubuntu-latest
99

10-
# Installs needed dependencies
1110
steps:
11+
# Step 1: Installs needed dependencies to set up our code
1212
- name: Checkout Code
1313
uses: actions/checkout@v3
1414

@@ -17,17 +17,17 @@ jobs:
1717
with:
1818
node-version: 18
1919

20-
# Tests code too ensure it passes all tests
20+
# Step 2: Tests code too ensure it passes all tests
2121
- name: Run frontend tests
2222
run: cd course-matrix/frontend && npm install && npm run test
2323
- name: Run backend tests
2424
run: cd course-matrix/backend && npm install && npm run test
2525

26-
# Set up Docker Buildx
26+
# Step 3: Set up Docker Buildx
2727
- name: Set up Docker Buildx
2828
uses: docker/setup-buildx-action@v2
2929

30-
# Sets our our application's environment
30+
# Step 4: Sets our our application's environment
3131
- name: setup application env
3232
run: |
3333
cd course-matrix
@@ -54,42 +54,42 @@ jobs:
5454

5555
cd ../
5656

57-
# Logging in to dockerhub
57+
# Step 5: Logging in to dockerhub
5858
- name: Log in to Docker Hub
5959
uses: docker/login-action@v3
6060
with:
6161
username: ${{ secrets.DOCKERHUB_USERNAME }}
6262
password: ${{ secrets.DOCKERHUB_TOKEN }}
6363

64-
# Build all required doccker images
64+
# Step 6: Build all required doccker images
6565
- name: Build Docker Image
6666
run: |
6767
cd course-matrix
6868
docker compose build
6969
70-
# Check if images exist before tagging
70+
# Step 7: Check if images exist before tagging
7171
- name: List Docker Images (Debugging)
7272
run: docker images
7373

74-
# Tags created images with version using github commit tags
74+
# Step 8: Tags created images with version using github commit tags
7575
- name: Tag Images With Version
7676
run: |
7777
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
7878
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}
7979
80-
# Push Docker images version to Docker Hub
80+
# Step 9: Push Docker images version to Docker Hub
8181
- name: Push Docker images version to Docker Hub
8282
run: |
8383
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
8484
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}
8585
86-
# Tags created images for the master branch
86+
# Step 10: Tags created images for the master branch
8787
- name: Tag Images for Master Branch
8888
run: |
8989
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
9090
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
9191
92-
# Push Docker images to Docker Hub master branch
92+
# Step 11: Push Docker images to Docker Hub master branch
9393
- name: Push images to Master Branch
9494
run: |
9595
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
@@ -102,7 +102,8 @@ jobs:
102102
steps:
103103
- name: Checkout Code
104104
uses: actions/checkout@v3
105-
105+
106+
# Step 12: Connect to virtual machine
106107
- name: Setup SSH Connection
107108
run: |
108109
echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > private_key
@@ -113,30 +114,22 @@ jobs:
113114
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_VM_IP }} << 'EOF'
114115
cd /home/masahisasekita/term-group-project-c01w25-project-course-matrix || { echo "Error: Directory /root/myapp does not exist!"; exit 1; }
115116
116-
# Clears deployment environment
117+
# Step 13: Clears deployment environment
117118
sudo docker rmi -f $(sudo docker images -q)
118119
sudo docker system prune -a --volumes -f
119120
120-
# Pull the latest images
121+
# Step 14: Pull the latest images
121122
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
122123
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
123124
124-
# Run the frontend container
125+
# Step 15: Run the docker containers
125126
docker run -d -p 5173:5173 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
126-
127-
# Run the backend container
128127
docker run -d -p 8081:8081 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
129128
130-
# Stop and remove existing containers
129+
# Step 16: Run post deployment tests
131130
docker compose down
132-
133-
# Start new containers with the latest images
134131
docker compose up -d --pull always
135-
136-
# Confirm running containers
137132
docker ps
138-
139-
# Run post deployment tests
140133
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master npm test
141134
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master npm test
142135
EOF

CICD/Dockerfile(backend)

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use an official Node.js image
2+
FROM node:18
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application files
14+
COPY . .
15+
16+
# Expose the backend port
17+
EXPOSE 8081
18+
19+
# Start the application
20+
CMD ["npm", "run", "dev"]

CICD/Dockerfile(frontend)

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use an official Node.js image
2+
FROM node:18
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application files
14+
COPY . .
15+
16+
# Expose the frontend port
17+
EXPOSE 8081
18+
EXPOSE 5173
19+
20+
# Start the application
21+
CMD ["npm", "run", "dev"]

CICD/ReadME.pdf

159 KB
Binary file not shown.

CICD/autodeploy.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: develop
6+
jobs:
7+
CI-PIPELINE:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
# Step 1: Installs needed dependencies to set up our code
12+
- name: Checkout Code
13+
uses: actions/checkout@v3
14+
15+
- name: Install Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
20+
# Step 2: Tests code too ensure it passes all tests
21+
- name: Run frontend tests
22+
run: cd course-matrix/frontend && npm install && npm run test
23+
- name: Run backend tests
24+
run: cd course-matrix/backend && npm install && npm run test
25+
26+
# Step 3: Set up Docker Buildx
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
30+
# Step 4: Sets our our application's environment
31+
- name: setup application env
32+
run: |
33+
cd course-matrix
34+
35+
# Update frontend .env
36+
cd frontend
37+
echo "VITE_SERVER_URL=\"http://34.130.253.243:8081\"" > .env && \
38+
echo "VITE_PUBLIC_ASSISTANT_BASE_URL=\"${{ secrets.VITE_PUBLIC_ASSISTANT_BASE_URL }}\"" >> .env && \
39+
echo "VITE_ASSISTANT_UI_KEY=\"${{ secrets.VITE_ASSISTANT_UI_KEY }}\"" >> .env
40+
41+
# Update backend .env
42+
cd ../backend
43+
echo "NODE_ENV=\"development\"" > .env && \
44+
echo "PORT=8081" >> .env && \
45+
echo "CLIENT_APP_URL=\"http://34.130.253.243:5173\"" >> .env && \
46+
echo "DATABASE_URL=\"${{ secrets.DATABASE_URL }}\"" >> .env && \
47+
echo "DATABASE_KEY=\"${{ secrets.DATABASE_KEY }}\"" >> .env && \
48+
echo "OPENAI_API_KEY=\"${{ secrets.OPENAI_API_KEY }}\"" >> .env && \
49+
echo "PINECONE_API_KEY=\"${{ secrets.PINECONE_API_KEY }}\"" >> .env && \
50+
echo "PINECONE_INDEX_NAME=\"course-matrix\"" >> .env && \
51+
echo "BREVO_API_KEY=\"${{ secrets.BREVO_API_KEY }}\"" >> .env && \
52+
echo "SENDER_EMAIL=\"${{ secrets.SENDER_EMAIL }}\"" >> .env && \
53+
echo "SENDER_NAME=\"Course Matrix Notifications\"" >> .env
54+
55+
cd ../
56+
57+
# Step 5: Logging in to dockerhub
58+
- name: Log in to Docker Hub
59+
uses: docker/login-action@v3
60+
with:
61+
username: ${{ secrets.DOCKERHUB_USERNAME }}
62+
password: ${{ secrets.DOCKERHUB_TOKEN }}
63+
64+
# Step 6: Build all required doccker images
65+
- name: Build Docker Image
66+
run: |
67+
cd course-matrix
68+
docker compose build
69+
70+
# Step 7: Check if images exist before tagging
71+
- name: List Docker Images (Debugging)
72+
run: docker images
73+
74+
# Step 8: Tags created images with version using github commit tags
75+
- name: Tag Images With Version
76+
run: |
77+
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
78+
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}
79+
80+
# Step 9: Push Docker images version to Docker Hub
81+
- name: Push Docker images version to Docker Hub
82+
run: |
83+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
84+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}
85+
86+
# Step 10: Tags created images for the master branch
87+
- name: Tag Images for Master Branch
88+
run: |
89+
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
90+
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
91+
92+
# Step 11: Push Docker images to Docker Hub master branch
93+
- name: Push images to Master Branch
94+
run: |
95+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
96+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
97+
98+
CD-PIPELINE:
99+
needs: CI-PIPELINE
100+
runs-on: ubuntu-latest
101+
102+
steps:
103+
- name: Checkout Code
104+
uses: actions/checkout@v3
105+
106+
# Step 12: Connect to virtual machine
107+
- name: Setup SSH Connection
108+
run: |
109+
echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > private_key
110+
chmod 600 private_key
111+
112+
- name: Deploy to Google Cloud VM
113+
run: |
114+
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_VM_IP }} << 'EOF'
115+
cd /home/masahisasekita/term-group-project-c01w25-project-course-matrix || { echo "Error: Directory /root/myapp does not exist!"; exit 1; }
116+
117+
# Step 13: Clears deployment environment
118+
sudo docker rmi -f $(sudo docker images -q)
119+
sudo docker system prune -a --volumes -f
120+
121+
# Step 14: Pull the latest images
122+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
123+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
124+
125+
# Step 15: Run the docker containers
126+
docker run -d -p 5173:5173 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
127+
docker run -d -p 8081:8081 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master
128+
129+
# Step 16: Run post deployment tests
130+
docker compose down
131+
docker compose up -d --pull always
132+
docker ps
133+
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master npm test
134+
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master npm test
135+
EOF

CICD/docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3.8'
2+
3+
services:
4+
backend:
5+
image: course-matrix/backend:latest
6+
build:
7+
context: ./backend
8+
ports:
9+
- "8081:8081"
10+
env_file:
11+
- ./backend/.env
12+
volumes:
13+
- ./backend:/app
14+
- /app/node_modules
15+
command: ["npm", "run", "dev"]
16+
networks:
17+
- course-matrix-net
18+
19+
frontend:
20+
image: course-matrix/frontend:latest
21+
build:
22+
context: ./frontend
23+
args:
24+
VITE_SERVER_URL: "http://34.130.253.243:8081"
25+
ports:
26+
- "5173:5173"
27+
volumes:
28+
- ./frontend:/app
29+
- /app/node_modules
30+
command: ["npm", "run", "dev"]
31+
depends_on:
32+
- backend
33+
networks:
34+
- course-matrix-net
35+
36+
networks:
37+
course-matrix-net:
38+
driver: bridge

0 commit comments

Comments
 (0)