Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b09854c
git commit -m 'docker files'
MasahisaSekita Mar 16, 2025
4818675
git commit -m 'updated a few things'
MasahisaSekita Mar 20, 2025
9cdec9f
git commit -m 'added a workflow'
MasahisaSekita Mar 20, 2025
3839add
git commit -m 'updated workflow'
MasahisaSekita Mar 20, 2025
7049499
git commit -m 'updated workflow bugs'
MasahisaSekita Mar 20, 2025
cf7a42a
git commit -m 'running workflow again'
MasahisaSekita Mar 20, 2025
75bdd88
git commit -m 'updated autodeply'
MasahisaSekita Mar 20, 2025
bd7d25f
git commit -m 'fixing workflow bugs'
MasahisaSekita Mar 20, 2025
126125c
git commit -m 'test'
MasahisaSekita Mar 20, 2025
1d9d32d
git commit -m 'hopefully working'
MasahisaSekita Mar 20, 2025
37e8158
git commit -m 'testing workflow redeployment'
MasahisaSekita Mar 20, 2025
15e0568
git checkout -m 'CI/CD on develop'
MasahisaSekita Mar 20, 2025
1a88faf
git commit -m 'sensitive fields now stored as secrets'
MasahisaSekita Mar 20, 2025
d871d45
git comit -m 'updated error in deploymment'
MasahisaSekita Mar 20, 2025
e4e76da
git commit -m 'updated formatting'
MasahisaSekita Mar 20, 2025
7ce8a0c
git commit -m 'updated .env '
MasahisaSekita Mar 20, 2025
55ad917
git commit -m 'ensures that the .env file is clean'
MasahisaSekita Mar 20, 2025
886cf93
git commit -m 'updated .env formatting'
MasahisaSekita Mar 20, 2025
7b5fe93
git commit -m 'updated .env'
MasahisaSekita Mar 20, 2025
2d90b5c
git commit -m 'updated formatting'
MasahisaSekita Mar 20, 2025
7e2bfe0
git commit -m 'updated docker compose'
MasahisaSekita Mar 20, 2025
66133d7
git commit -m 'updated server'
MasahisaSekita Mar 20, 2025
bea6b9c
git commit -m 'made sure it updates only on develop'
MasahisaSekita Mar 20, 2025
118924b
git commit -m 'pushes to dockerhub'
MasahisaSekita Mar 21, 2025
7303b19
git commit -m 'updated with docker hub'
MasahisaSekita Mar 21, 2025
5be0a34
git comit -m 'made sure was in right folder'
MasahisaSekita Mar 21, 2025
2531b87
git commit -m 'updated dockerhub'
MasahisaSekita Mar 21, 2025
1984573
git commit -m 'sprint 3 version'
MasahisaSekita Mar 21, 2025
4d95003
git commit -m 'testing workflow'
MasahisaSekita Mar 22, 2025
5cd2146
git commit -m 'assignment 2'
MasahisaSekita Mar 22, 2025
043f45b
git commit -m 'autodeploy'
MasahisaSekita Mar 22, 2025
029b8b0
git commit -m 'test'
MasahisaSekita Mar 22, 2025
12c31e4
git commit -m 'test'
MasahisaSekita Mar 22, 2025
2d88343
git commit -m 'deploy latest version'
MasahisaSekita Mar 22, 2025
59ef8ad
git commit -m 'deploy latest version'
MasahisaSekita Mar 22, 2025
6c173de
git commit -m 'pushed to dockerhub'
MasahisaSekita Mar 22, 2025
feec762
git commit 'updated CI Pipeline'
MasahisaSekita Mar 22, 2025
2cd8316
git commit -m 'master branch and version tag'
MasahisaSekita Mar 22, 2025
b9ca8c6
git commit -m 'pushes to dockerhhub'
MasahisaSekita Mar 22, 2025
634c6d6
git commit -m 'test'
MasahisaSekita Mar 22, 2025
e5eeca1
git commit -m 'updated documentation'
MasahisaSekita Mar 22, 2025
dbd1ef8
git commit -m 'testing'
MasahisaSekita Mar 22, 2025
01dc41f
git commit -m 'for develop master branch'
MasahisaSekita Mar 22, 2025
25b96b0
git commit 'updated documentation'
MasahisaSekita Mar 22, 2025
78cedba
git commit -m 'post deployment tests'
MasahisaSekita Mar 22, 2025
e9a1030
git commit -m 'all documentation for assignment 2'
MasahisaSekita Mar 23, 2025
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
142 changes: 142 additions & 0 deletions .github/workflows/autodeploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: CI/CD Pipeline

on:
push:
branches: develop
jobs:
CI-PIPELINE:
runs-on: ubuntu-latest

# Installs needed dependencies
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

# Tests code too ensure it passes all tests
- name: Run frontend tests
run: cd course-matrix/frontend && npm install && npm run test
- name: Run backend tests
run: cd course-matrix/backend && npm install && npm run test

# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Sets our our application's environment
- name: setup application env
run: |
cd course-matrix

# Update frontend .env
cd frontend
echo "VITE_SERVER_URL=\"http://34.130.253.243:8081\"" > .env && \
echo "VITE_PUBLIC_ASSISTANT_BASE_URL=\"${{ secrets.VITE_PUBLIC_ASSISTANT_BASE_URL }}\"" >> .env && \
echo "VITE_ASSISTANT_UI_KEY=\"${{ secrets.VITE_ASSISTANT_UI_KEY }}\"" >> .env

# Update backend .env
cd ../backend
echo "NODE_ENV=\"development\"" > .env && \
echo "PORT=8081" >> .env && \
echo "CLIENT_APP_URL=\"http://34.130.253.243:5173\"" >> .env && \
echo "DATABASE_URL=\"${{ secrets.DATABASE_URL }}\"" >> .env && \
echo "DATABASE_KEY=\"${{ secrets.DATABASE_KEY }}\"" >> .env && \
echo "OPENAI_API_KEY=\"${{ secrets.OPENAI_API_KEY }}\"" >> .env && \
echo "PINECONE_API_KEY=\"${{ secrets.PINECONE_API_KEY }}\"" >> .env && \
echo "PINECONE_INDEX_NAME=\"course-matrix\"" >> .env && \
echo "BREVO_API_KEY=\"${{ secrets.BREVO_API_KEY }}\"" >> .env && \
echo "SENDER_EMAIL=\"${{ secrets.SENDER_EMAIL }}\"" >> .env && \
echo "SENDER_NAME=\"Course Matrix Notifications\"" >> .env

cd ../

# Logging in to dockerhub
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Build all required doccker images
- name: Build Docker Image
run: |
cd course-matrix
docker compose build

# Check if images exist before tagging
- name: List Docker Images (Debugging)
run: docker images

# Tags created images with version using github commit tags
- name: Tag Images With Version
run: |
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}

# Push Docker images version to Docker Hub
- name: Push Docker images version to Docker Hub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:${{ github.sha }}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:${{ github.sha }}

# Tags created images for the master branch
- name: Tag Images for Master Branch
run: |
docker tag course-matrix/frontend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
docker tag course-matrix/backend:latest ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master

# Push Docker images to Docker Hub master branch
- name: Push images to Master Branch
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
docker push ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master

CD-PIPELINE:
needs: CI-PIPELINE
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup SSH Connection
run: |
echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > private_key
chmod 600 private_key

- name: Deploy to Google Cloud VM
run: |
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_VM_IP }} << 'EOF'
cd /home/masahisasekita/term-group-project-c01w25-project-course-matrix || { echo "Error: Directory /root/myapp does not exist!"; exit 1; }

# Clears deployment environment
sudo docker rmi -f $(sudo docker images -q)
sudo docker system prune -a --volumes -f

# Pull the latest images
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master

# Run the frontend container
docker run -d -p 5173:5173 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master

# Run the backend container
docker run -d -p 8081:8081 ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master

# Stop and remove existing containers
docker compose down

# Start new containers with the latest images
docker compose up -d --pull always

# Confirm running containers
docker ps

# Run post deployment tests
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-frontend:master npm test
docker exec -it ${{ secrets.DOCKERHUB_USERNAME }}/course-matrix-backend:master npm test
EOF
20 changes: 20 additions & 0 deletions course-matrix/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js image
FROM node:18

# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

# Expose the backend port
EXPOSE 8081

# Start the application
CMD ["npm", "run", "dev"]
3 changes: 2 additions & 1 deletion course-matrix/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "ts-node -r dotenv/config src/index.ts",
"test": "jest",
"test:watch": "jest --watch"
"test:watch": "jest --watch",
"build": "vite build"
},
"keywords": [],
"author": "",
Expand Down
38 changes: 38 additions & 0 deletions course-matrix/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.8'

services:
backend:
image: course-matrix/backend:latest
build:
context: ./backend
ports:
- "8081:8081"
env_file:
- ./backend/.env
volumes:
- ./backend:/app
- /app/node_modules
command: ["npm", "run", "dev"]
networks:
- course-matrix-net

frontend:
image: course-matrix/frontend:latest
build:
context: ./frontend
args:
VITE_SERVER_URL: "http://34.130.253.243:8081"
ports:
- "5173:5173"
volumes:
- ./frontend:/app
- /app/node_modules
command: ["npm", "run", "dev"]
depends_on:
- backend
networks:
- course-matrix-net

networks:
course-matrix-net:
driver: bridge
21 changes: 21 additions & 0 deletions course-matrix/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official Node.js image
FROM node:18

# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

# Expose the frontend port
EXPOSE 8081
EXPOSE 5173

# Start the application
CMD ["npm", "run", "dev"]
2 changes: 1 addition & 1 deletion course-matrix/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview",
"test": "jest",
Expand Down
6 changes: 6 additions & 0 deletions course-matrix/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ export default defineConfig({
"@": path.resolve(__dirname, "./src"),
},
},
server: {
host: "0.0.0.0", // Allow access from external devices
port: 5173, // Ensure it's using the correct port
strictPort: true, // Ensure it doesn't pick a different port if 5173 is in use
open: false, // Prevent auto-opening a browser on the server
},
});