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
18 changes: 9 additions & 9 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
venv
_*pycache*_
qr_codes
*.db
*.sqlite
.vscode
.env
.coverage

venv
_*pycache*_
qr_codes
*.db
*.sqlite
.vscode
.env
.coverage
6 changes: 3 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smtp_server=sandbox.smtp.mailtrap.io
smtp_port=2525
smtp_username=
smtp_server=sandbox.smtp.mailtrap.io
smtp_port=2525
smtp_username=
smtp_password=
170 changes: 85 additions & 85 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
name: CI/CD Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10.12] # Define Python versions here
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: myappdb
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache Python packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

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

- name: Run tests with Pytest
env:
DATABASE_URL: postgresql+asyncpg://user:password@localhost:5432/myappdb # Configure the DATABASE_URL environment variable for tests
run: pytest

build-and-push-docker:
needs: test
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4

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

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: woffee/wis_club_api:${{ github.sha }} # Uses the Git SHA for tagging
platforms: linux/amd64,linux/arm64 # Multi-platform support
cache-from: type=registry,ref=woffee/wis_club_api:cache
cache-to: type=inline,mode=max

- name: Scan the Docker image
uses: aquasecurity/trivy-action@master
with:
image-ref: 'woffee/wis_club_api:${{ github.sha }}'
format: 'table'
exit-code: '1' # Fail the job if vulnerabilities are found
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10.12] # Define Python versions here
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: myappdb
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests with Pytest
env:
DATABASE_URL: postgresql+asyncpg://user:password@localhost:5432/myappdb # Configure the DATABASE_URL environment variable for tests
run: pytest
build-and-push-docker:
needs: test
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: woffee/wis_club_api:${{ github.sha }} # Uses the Git SHA for tagging
platforms: linux/amd64,linux/arm64 # Multi-platform support
cache-from: type=registry,ref=woffee/wis_club_api:cache
cache-to: type=inline,mode=max
- name: Scan the Docker image
uses: aquasecurity/trivy-action@master
with:
image-ref: 'woffee/wis_club_api:${{ github.sha }}'
format: 'table'
exit-code: '1' # Fail the job if vulnerabilities are found
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
venv
_*pycache*_
qr_codes
*.db
*.sqlite
.vscode
.env
.coverage
venv
_*pycache*_
qr_codes
*.db
*.sqlite
.vscode
.env
.coverage
.DS_Store
84 changes: 42 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
# Use an official lightweight Python image.
# 3.12-slim variant is chosen for a balance between size and utility.
FROM python:3.12-slim-bullseye as base

# Set environment variables to configure Python and pip.
# Prevents Python from buffering stdout and stderr, enables the fault handler, disables pip cache,
# sets default pip timeout, and suppresses pip version check messages.
ENV PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PIP_NO_CACHE_DIR=true \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
QR_CODE_DIR=/myapp/qr_codes

# Set the working directory inside the container
WORKDIR /myapp

# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy only the requirements, to cache them in Docker layer
COPY ./requirements.txt /myapp/requirements.txt

# Upgrade pip and install Python dependencies from requirements file
RUN pip install --upgrade pip \
&& pip install -r requirements.txt

# Add a non-root user and switch to it
RUN useradd -m myuser
USER myuser

# Copy the rest of your application's code with appropriate ownership
COPY --chown=myuser:myuser . /myapp

# Inform Docker that the container listens on the specified port at runtime.
EXPOSE 8000

# Use ENTRYPOINT to specify the executable when the container starts.
# ENTRYPOINT ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# Use an official lightweight Python image.
# 3.12-slim variant is chosen for a balance between size and utility.
FROM python:3.12-slim-bullseye as base
# Set environment variables to configure Python and pip.
# Prevents Python from buffering stdout and stderr, enables the fault handler, disables pip cache,
# sets default pip timeout, and suppresses pip version check messages.
ENV PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PIP_NO_CACHE_DIR=true \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
QR_CODE_DIR=/myapp/qr_codes
# Set the working directory inside the container
WORKDIR /myapp
# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy only the requirements, to cache them in Docker layer
COPY ./requirements.txt /myapp/requirements.txt
# Upgrade pip and install Python dependencies from requirements file
RUN pip install --upgrade pip \
&& pip install -r requirements.txt
# Add a non-root user and switch to it
RUN useradd -m myuser
USER myuser
# Copy the rest of your application's code with appropriate ownership
COPY --chown=myuser:myuser . /myapp
# Inform Docker that the container listens on the specified port at runtime.
EXPOSE 8000
# Use ENTRYPOINT to specify the executable when the container starts.
# ENTRYPOINT ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
Binary file added Screenshot (388).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading