Skip to content

Commit

Permalink
updated CI/CD and requirements.txt in root directory and added Dockfi…
Browse files Browse the repository at this point in the history
…le .flake8 files to the root directory of the project
  • Loading branch information
abbastoof committed Jul 8, 2024
1 parent 9afb65c commit 1749c4c
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude = venv/*
max-line-length = 79
270 changes: 168 additions & 102 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,126 +1,192 @@
name: CI Pipeline
# name: CI Pipeline

# permissions:
# pull-requests: read
# contents: read
# issues: read
# deployments: read

# # Events that trigger the workflow
# on:
# push:
# branches: [main, develop] # Trigger on push to main and develop branches
# pull_request:
# branches: [main, develop] # Trigger on pull request to main and develop branches

# # Define jobs in the workflow
# jobs:
# setup:
# runs-on: ubuntu-latest
# steps:
# - name: Upgrade setuptools
# run: pip install --upgrade setuptools

# - name: Checkout code
# uses: actions/checkout@v3 # Checkout the repository code

# # Set up Python environment
# - name: Set up Python 3.11
# uses: actions/setup-python@v3
# with:
# python-version: 3.11 # Use Python version 3.11

# # Install project dependencies
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip # Upgrade pip
# pip install -r requirements.txt # Install dependencies from requirements.txt

# # test:
# # needs: setup
# # runs-on: ubuntu-latest
# # steps:
# # - name: Checkout code
# # uses: actions/checkout@v3

# # - name: Set up Python 3.11
# # uses: actions/setup-python@v3
# # with:
# # python-version: 3.11

# # - name: Install dependencies
# # run: |
# # python -m pip install --upgrade pip
# # pip install -r requirements.txt

# # # Run test suite
# # - name: Run tests
# # run: |
# # pytest # Execute tests using pytest

# security:
# needs: setup
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up Python 3.11
# uses: actions/setup-python@v3
# with:
# python-version: 3.11

# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt

# # Run security checks
# - name: Run security checks
# run: |
# pip install bandit # Install Bandit for security checks
# bandit -r . # Run Bandit on the codebase

# build:
# needs: [setup, security]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up Python 3.11
# uses: actions/setup-python@v3
# with:
# python-version: 3.11

# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt

# # Build the Docker image
# - name: Build Docker image
# run: |
# docker build -t transcendence .

# deploy:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# # Log in to Docker Hub
# - name: Deploy to Docker Hub
# env:
# DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
# DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
# run: |
# echo "${DOCKER_HUB_PASSWORD}" | docker login -u "${DOCKER_HUB_USERNAME}" --password-stdin
# docker tag transcendence ${DOCKER_HUB_USERNAME}/transcendence:latest
# docker push ${DOCKER_HUB_USERNAME}/transcendence:latest

# # Deploy to the server
# - name: Deploy to server
# run: |
# ssh user@server "docker pull ${DOCKER_HUB_USERNAME}/transcendence:latest && docker-compose up --build -d"

permissions:
pull-requests: read
contents: read
issues: read
deployments: read
name: CI Pipeline

# Events that trigger the workflow
on:
push:
branches: [main, develop] # Trigger on push to main and develop branches
pull_request:
branches: [main, develop] # Trigger on pull request to main and develop branches
branches:
- feature/015-game-history-microservice

# Define jobs in the workflow
jobs:
setup:
lint-project:
runs-on: ubuntu-latest
steps:
- name: Upgrade setuptools
run: pip install --upgrade setuptools
- name: Check out code
uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v3 # Checkout the repository code

# Set up Python environment
- name: Set up Python 3.11
uses: actions/setup-python@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11 # Use Python version 3.11

# Install project dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip # Upgrade pip
pip install -r requirements.txt # Install dependencies from requirements.txt
# test:
# needs: setup
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up Python 3.11
# uses: actions/setup-python@v3
# with:
# python-version: 3.11

# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt

# # Run test suite
# - name: Run tests
# run: |
# pytest # Execute tests using pytest

security:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: 3.11
python-version: '3.11'

- name: Install dependencies
run: |
python -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools==58.0.4 wheel
pip install -r requirements.txt
# Run security checks
- name: Run security checks
pip install flake8
- name: Create flake8 configuration file
run: |
pip install bandit # Install Bandit for security checks
bandit -r . # Run Bandit on the codebase
echo "[flake8]" > .flake8
echo "exclude = venv/*" >> .flake8
echo "max-line-length = 79" >> .flake8
build:
needs: [setup, security]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: 3.11

- name: Install dependencies
- name: Verify installed packages
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
. venv/bin/activate
pip check
# Build the Docker image
- name: Build Docker image
- name: Run linters
run: |
docker build -t transcendence .
. venv/bin/activate
flake8 .
deploy:
needs: build
publish-test-image:
needs: lint-project
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

# Log in to Docker Hub
- name: Deploy to Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
run: |
echo "${DOCKER_HUB_PASSWORD}" | docker login -u "${DOCKER_HUB_USERNAME}" --password-stdin
docker tag transcendence ${DOCKER_HUB_USERNAME}/transcendence:latest
docker push ${DOCKER_HUB_USERNAME}/transcendence:latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# Deploy to the server
- name: Deploy to server
run: |
ssh user@server "docker pull ${DOCKER_HUB_USERNAME}/transcendence:latest && docker-compose up --build -d"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: abbastoof
password: ${{ secrets.GH_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ghcr.io/${{ github.repository }}:feature/015-game-history-microservice
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt requirements.txt
RUN python -m pip install --upgrade pip
RUN pip install setuptools==58.0.4 wheel
RUN pip --timeout=1000 install -r requirements.txt

WORKDIR /app

COPY . /app

RUN chown -R www-data:www-data /app

USER www-data

EXPOSE 8000

CMD ["manage.py", "runserver", "0.0.0.0:8000"]
63 changes: 32 additions & 31 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
# # # Application dependencies
# Django==4.0.6
# djangorestframework==3.12.4
# fastapi==0.75.1
# uvicorn==0.17.0
# mysqlclient==2.0.3
# requests==2.26.0
# Application dependencies
Django==4.0.6
djangorestframework==3.12.4
fastapi==0.75.1
uvicorn==0.17.0
mysqlclient==2.0.3
requests==2.26.0

# # # Testing dependencies
# pytest==7.1.2
# Testing dependencies
pytest==7.1.2

# # # Security dependencies
# bandit==1.7.0
# Security dependencies
bandit==1.7.0

# # # Other dependencies
# docker==5.0.3
# Pillow==9.0.0
# django-redis==5.0.0
# asgiref==3.5.0
# channels==3.0.4
# idna==3.3
# pytz==2021.3
# python-dateutil==2.8.2
# simplejson==3.17.5
# urllib3==1.26.8
# sqlparse==0.4.2
# PyYAML==6.0
# typing_extensions==4.0.1
# django-rest-swagger==2.2.0
# django-rest-knox==4.1.0
# django-rest-auth==0.9.5
# django-allauth==0.47.0
# Other dependencies
docker==5.0.3
Pillow==9.0.0
django-redis==5.0.0
asgiref==3.5.0
channels==3.0.4
idna==3.3
pytz==2021.3
python-dateutil==2.8.2
simplejson==3.17.5
urllib3==1.26.8
sqlparse==0.4.2
PyYAML==6.0
typing_extensions==4.0.1
django-rest-swagger==2.2.0
django-rest-knox==4.1.0
django-rest-auth==0.9.5
django-allauth==0.47.0

# # # Build dependencies
# setuptools==58.0.4
# Build dependencies
setuptools==58.0.4
wheel==0.37.0

0 comments on commit 1749c4c

Please sign in to comment.