Skip to content
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
44 changes: 38 additions & 6 deletions Project/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
# TODO: Define stages for your pipeline
stages:
- build
- test
- docker-build
- deploy

# TODO: Define variables (if needed)
variables:
NODE_VERSION: "14"
PYTHON_VERSION: "3.9"

# TODO: Define a job for building the frontend
frontend-job:
stage: # TODO: Specify stage
image: # TODO: Specify Node.js image
stage: build
# TODO: Specify stage
image: node:${NODE_VERSION}-alpine
# TODO: Specify Node.js image
script:
# TODO: Install dependencies
- echo "install dependencies for frontend"
- npm install --prefix ./fronted
# TODO: Build the React app
- echo "build the react app"
- npm run build --prefix ./frontend

# TODO: Define a job for building and testing the backend
backend-job:
stage: # TODO: Specify stage
image: # TODO: Specify Python image
stage: test
# TODO: Specify stage
image: python:${PYTHON_VERSION}-slim
# TODO: Specify Python image
script:
# TODO: Install dependencies
- echo "install dependencie for backend"
- pip install -r ./backend/requirements.txt
# TODO: Run tests
- echo "run tests"
- pytest ./backend

# TODO: Define a job for building Docker images
docker-build:
stage: # TODO: Specify stage
stage: docker-build
# TODO: Specify stage
image: docker:latest
services:
- docker:dind
script:
# TODO: Build frontend Docker image
- echo "Build frontend Docker image"
- docker build ssrpt927/frontend:latest ./frontend
# TODO: Build backend Docker image
- echo "Build backend Docker image"
- docker build -t ssrpt927/backend:latest ./backend
# TODO: Push images to Docker Hub (if on main branch)
- echo "Push images to Docker Hub"
- docker push ssrpt927/frontend:latest
- docker push ssrpt927/backend:latest
only:
- main

# OPTIONAL: Define a deployment job (if applicable)
deploy:
stage: # TODO: Specify stage
stage: deploy
# TODO: Specify stage
script:
- echo "deploy the application."
# TODO: Add deployment steps
only:
- main
9 changes: 7 additions & 2 deletions Project/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Define environment variable
ENV PYTHONUNBUFFERED=1

# Run app.py when the container launches

# End of File
CMD ["python", "app.py"]
14 changes: 7 additions & 7 deletions Project/backend/Hint/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Use an official Python runtime as a parent image
FROM
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY
COPY . /app

# Install any needed packages specified in requirements.txt
RUN
RUN pip install --no-cache-dir -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE
EXPOSE 5000

# Define environment variable
ENV
ENV PYTHONUNBUFFERED=1

# Run app.py when the container launches
CMD
CMD ["python", "app.py"]
37 changes: 25 additions & 12 deletions Project/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,55 @@ services:
frontend:
# Specify the build context for the frontend
build:
context: ./frontend
# Map the host port to the container port
ports:
- "3000:3000"
# Specify dependencies (if applicable)
depends_on:

- backend
# Additional options (uncomment and configure as needed):

# Specify environment variables if needed
# environment:

environment:
- NODE_ENV=production

# Specify volume for live code reloading (optional)
# volumes:
volumes:
- ./frontend:/app

# Specify the command to run the development server (if different from Dockerfile)
# command:
command: ["npm", "start"]

backend:
# Specify the build context for the backend
build:
context: ./backend
# Map the host port to the container port
ports:

- "5000:5000"
# Additional options (uncomment and configure as needed):

# Specify environment variables if needed
# environment:

environment:
- FLASK_ENV=development
# Specify volume for live code reloading (optional)
# volumes:

volumes:
- ./backend:/app
# Specify the command to run the development server (if different from Dockerfile)
# command:
command: ["python", "app.py"]


# Additional components (uncomment and configure as needed):
# Define a custom network (if applicable)
# networks:
networks:
default:
driver: bridge


# Define volumes (if applicable)
# volumes:
volumes:
backend-data:
frontend-data:

9 changes: 9 additions & 0 deletions Project/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# Use an official Node runtime as a parent image
FROM node:14-alpine

# Set the working directory in the container
WORKDIR /app

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

# Install app dependencies
RUN npm install

# Copy the current directory contents into the container
COPY . /app

# Build the app
RUN npm run build

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define environment variable
ENV NODE_ENV=production

# Run the app when the container launches
CMD ["npm", "start"]
18 changes: 9 additions & 9 deletions Project/frontend/Hint/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Use an official Node runtime as a parent image
FROM
FROM node:14-alpine

# Set the working directory in the container
WORKDIR
WORKDIR /app

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

# Install app dependencies
RUN
RUN npm install

# Copy the current directory contents into the container
COPY
COPY . /app

# Build the app
RUN
RUN npm run build

# Make port 3000 available to the world outside this container
EXPOSE
EXPOSE 3000

# Define environment variable
ENV
ENV NODE_ENV=production

# Run the app when the container launches
CMD
CMD ["npm", "start"]
56 changes: 48 additions & 8 deletions Project/github-actions.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,88 @@
# TODO: Define the Workflow Name
name:
name: CI/CD Pipeline

# TODO: Define triggers for the workflow
on:
# push:
# branches:
# pull_request:
# branches:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
# TODO: Define a job for building and testing the frontend
frontend:
runs-on: ubuntu-latest
steps:
# TODO: Checkout code
- name: Checkout code
uses: actions/checkout@v2
# TODO: Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
# TODO: Install dependencies
# TODO: Run tests
- name: Install dependencies
run: npm install --prefix ./frontend
# TODO: Run tests
- name: Run frontend tests
run: npm test --prefix ./frontend
# TODO: Build the React app
- name: Build the React app
run: npm run build --prefix ./frontend

# TODO: Define a job for building and testing the backend
backend:
runs-on: ubuntu-latest
steps:
# TODO: Checkout code
- name: Checkout code
uses: actions/checkout@v2
# TODO: Setup Python
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
# TODO: Install dependencies
- name: Install dependencies
run: pip install -r ./backend/requirements.txt
# TODO: Run tests
- name: Run backend tests
run: pytest ./backend

# TODO: Define a job for building and pushing Docker images
docker:
# Run this job only when 'frontend' & 'backend' stages are sucessfully completed
needs:
needs: [frontend,backend]
runs-on: ubuntu-latest
steps:
# TODO: Checkout code
- name: checkout code
uses: actions/checkout@v2
# TODO: Setup Docker
- name: Set up Docker
uses: docker/setup-buildx-action@v2
# TODO: Build frontend Docker image
- name: Build frontend Docker image
run: docker build -t ssrpt927/frontend:14-alpine ./frontend
# TODO: Build backend Docker image
- name: Build backend Docker image
run: docker build -t ssrpt927/backend:3.9-slim ./backend
# TODO: Push images to Docker Hub (if on main branch)

- name: Push Docker images
run: |
docker push ssrpt927/frontend:14-alpine
docker push ssrpt927/backend:3.9-slim
if: github.ref == 'refs/heads/main'
# OPTIONAL: Define a deployment job (if applicable)
deploy:
needs: docker
runs-on: ubuntu-latest
steps:
# TODO: Add deployment steps
- name: Deploy application
run: |
echo "Deploying application."