Skip to content

Commit 5d991a3

Browse files
Merge pull request #34 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents bcc63a7 + e324864 commit 5d991a3

File tree

188 files changed

+20236
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+20236
-375
lines changed

.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.DS_Store
8+
**/__pycache__
9+
**/.venv
10+
**/.classpath
11+
**/.dockerignore
12+
**/.env
13+
**/.git
14+
**/.gitignore
15+
**/.project
16+
**/.settings
17+
**/.toolstarget
18+
**/.vs
19+
**/.vscode
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/bin
24+
**/charts
25+
**/docker-compose*
26+
**/compose.y*ml
27+
**/Dockerfile*
28+
**/node_modules
29+
**/npm-debug.log
30+
**/obj
31+
**/secrets.dev.yaml
32+
**/values.dev.yaml
33+
LICENSE
34+
README.md

.env.example

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,37 @@ ENV='DEVELOPMENT'
22
SECRET_KEY='unique-secret'
33
ALLOWED_HOSTS='localhost,127.0.0.1'
44
MONGODB_URI='mongodb://localhost:27017'
5-
DB_NAME='todo-app'
5+
DB_NAME='db-name'
6+
# GOOGLE OAUTH SETTINGS
7+
GOOGLE_OAUTH_CLIENT_ID="google-client-id"
8+
GOOGLE_OAUTH_CLIENT_SECRET="client-secret"
9+
GOOGLE_OAUTH_REDIRECT_URI="http://localhost:8000/v1/auth/google/callback"
10+
11+
PRIVATE_KEY="generate keys and paste here"
12+
PUBLIC_KEY="generate keys and paste here"
13+
14+
ACCESS_LIFETIME=3600
15+
REFRESH_LIFETIME=604800
16+
17+
ACCESS_TOKEN_COOKIE_NAME='todo-access'
18+
REFRESH_TOKEN_COOKIE_NAME='todo-refresh'
19+
COOKIE_DOMAIN='localhost'
20+
COOKIE_SECURE='true'
21+
COOKIE_HTTPONLY=True
22+
COOKIE_SAMESITE='Strict'
23+
24+
TODO_UI_BASE_URL='http://localhost:3000'
25+
TODO_UI_REDIRECT_PATH='dashboard'
26+
TODO_BACKEND_BASE_URL='http://localhost:8000'
27+
28+
CORS_ALLOWED_ORIGINS='http://localhost:3000,http://localhost:8000'
29+
30+
SWAGGER_UI_PATH='/api/schema'
31+
32+
33+
34+
POSTGRES_DB=todo_postgres
35+
POSTGRES_HOST=postgres
36+
POSTGRES_PASSWORD=todo_password
37+
POSTGRES_PORT=5432
38+
POSTGRES_USER=todo_user

.github/workflows/deploy.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Build and push
29+
uses: docker/build-push-action@v5
30+
with:
31+
context: .
32+
file: production.Dockerfile
33+
platforms: linux/arm64
34+
push: true
35+
build-args: |
36+
ENV=${{ vars.ENV }}
37+
tags: |
38+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}
39+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
40+
cache-from: type=gha
41+
cache-to: type=gha,mode=max
42+
43+
- name: Deploy to EC2
44+
uses: appleboy/ssh-action@v1
45+
with:
46+
host: ${{ secrets.AWS_EC2_HOST }}
47+
username: ${{ secrets.AWS_EC2_USERNAME }}
48+
key: ${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}
49+
script: |
50+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
51+
docker stop ${{ github.event.repository.name }}-${{ vars.ENV }} || true
52+
docker rm ${{ github.event.repository.name }}-${{ vars.ENV }} || true
53+
docker run -d -p ${{ vars.PORT }}:8000 \
54+
--name ${{ github.event.repository.name }}-${{ vars.ENV }} \
55+
--network=${{ vars.DOCKER_NETWORK }} \
56+
-e ENV="${{ vars.ENV }}" \
57+
-e SECRET_KEY="${{ secrets.SECRET_KEY }}" \
58+
-e DB_NAME="${{ secrets.DB_NAME }}" \
59+
-e MONGODB_URI="${{ secrets.MONGODB_URI }}" \
60+
-e ALLOWED_HOSTS="${{ vars.ALLOWED_HOSTS }}" \
61+
-e GOOGLE_OAUTH_CLIENT_ID="${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}" \
62+
-e GOOGLE_OAUTH_CLIENT_SECRET="${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}" \
63+
-e GOOGLE_OAUTH_REDIRECT_URI="${{ vars.GOOGLE_OAUTH_REDIRECT_URI }}" \
64+
-e PUBLIC_KEY="${{ secrets.PUBLIC_KEY }}" \
65+
-e PRIVATE_KEY="${{ secrets.PRIVATE_KEY }}" \
66+
-e ACCESS_LIFETIME="${{ vars.ACCESS_LIFETIME }}" \
67+
-e REFRESH_LIFETIME="${{ vars.REFRESH_LIFETIME }}" \
68+
-e ACCESS_TOKEN_COOKIE_NAME="${{ vars.ACCESS_TOKEN_COOKIE_NAME }}" \
69+
-e REFRESH_TOKEN_COOKIE_NAME="${{ vars.REFRESH_TOKEN_COOKIE_NAME }}" \
70+
-e COOKIE_DOMAIN="${{ vars.COOKIE_DOMAIN }}" \
71+
-e COOKIE_SECURE="${{ vars.COOKIE_SECURE }}" \
72+
-e COOKIE_HTTPONLY="${{ vars.COOKIE_HTTPONLY }}" \
73+
-e COOKIE_SAMESITE="${{ vars.COOKIE_SAMESITE }}" \
74+
-e TODO_BACKEND_BASE_URL="${{ vars.TODO_BACKEND_BASE_URL }}" \
75+
-e TODO_UI_BASE_URL="${{ vars.TODO_UI_BASE_URL }}" \
76+
-e TODO_UI_REDIRECT_PATH="${{ vars.TODO_UI_REDIRECT_PATH }}" \
77+
-e CORS_ALLOWED_ORIGINS="${{ vars.CORS_ALLOWED_ORIGINS }}" \
78+
-e SWAGGER_UI_PATH="${{ vars.SWAGGER_UI_PATH }}" \
79+
-e ADMIN_EMAILS="${{ vars.ADMIN_EMAILS }}" \
80+
-e POSTGRES_HOST="${{ secrets.POSTGRES_HOST }}" \
81+
-e POSTGRES_PORT="${{ secrets.POSTGRES_PORT }}" \
82+
-e POSTGRES_DB="${{ secrets.POSTGRES_DB }}" \
83+
-e POSTGRES_USER="${{ secrets.POSTGRES_USER }}" \
84+
-e POSTGRES_PASSWORD="${{ secrets.POSTGRES_PASSWORD }}" \
85+
-e DUAL_WRITE_ENABLED="${{ vars.DUAL_WRITE_ENABLED }}" \
86+
-e DUAL_WRITE_SYNC_MODE="${{ vars.DUAL_WRITE_SYNC_MODE }}" \
87+
-e DUAL_WRITE_RETRY_ATTEMPTS="${{ vars.DUAL_WRITE_RETRY_ATTEMPTS }}" \
88+
-e DUAL_WRITE_RETRY_DELAY="${{ vars.DUAL_WRITE_RETRY_DELAY }}" \
89+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}

.github/workflows/test.yml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,40 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10-
services:
11-
db:
12-
image: mongo:latest
13-
ports:
14-
- 27017:27017
15-
10+
if: ${{ !contains(github.event.pull_request.title, '[skip tests]') }}
11+
1612
env:
13+
SECRET_KEY: "test-secret-key"
14+
ALLOWED_HOSTS: "localhost,127.0.0.1"
1715
MONGODB_URI: mongodb://db:27017
1816
DB_NAME: todo-app
17+
GOOGLE_OAUTH_CLIENT_ID: "test-client-id"
18+
GOOGLE_OAUTH_CLIENT_SECRET: "test-client-secret"
19+
GOOGLE_OAUTH_REDIRECT_URI: "http://localhost:8000/v1/auth/google/callback"
20+
PRIVATE_KEY: "test-private-key"
21+
PUBLIC_KEY: "test-public-key"
22+
ACCESS_LIFETIME: "3600"
23+
REFRESH_LIFETIME: "604800"
24+
ACCESS_TOKEN_COOKIE_NAME: "todo-access"
25+
REFRESH_TOKEN_COOKIE_NAME: "todo-refresh"
26+
COOKIE_DOMAIN: "localhost"
27+
COOKIE_SECURE: "False"
28+
COOKIE_HTTPONLY: "True"
29+
COOKIE_SAMESITE: "Lax"
30+
TODO_UI_BASE_URL: "http://localhost:3000"
31+
TODO_UI_REDIRECT_PATH: "dashboard"
32+
TODO_BACKEND_BASE_URL: "http://localhost:8000"
33+
CORS_ALLOWED_ORIGINS: "http://localhost:3000,http://localhost:8000"
34+
ADMIN_EMAILS: "[email protected]"
35+
POSTGRES_HOST: "localhost"
36+
POSTGRES_PORT: "5432"
37+
POSTGRES_DB: "todo-app"
38+
POSTGRES_USER: "test-user"
39+
POSTGRES_PASSWORD: "test-password"
40+
DUAL_WRITE_ENABLED: "True"
41+
DUAL_WRITE_SYNC_MODE: "async"
42+
DUAL_WRITE_RETRY_ATTEMPTS: "3"
43+
DUAL_WRITE_RETRY_DELAY: "5"
1944

2045
steps:
2146
- name: Checkout code
@@ -24,7 +49,7 @@ jobs:
2449
- name: Set up Python
2550
uses: actions/setup-python@v5
2651
with:
27-
python-version: '3.11.*'
52+
python-version: "3.11.*"
2853

2954
- name: Install dependencies
3055
run: |
@@ -34,6 +59,10 @@ jobs:
3459
run: |
3560
ruff check
3661
62+
- name: Format check
63+
run: |
64+
ruff format --check
65+
3766
- name: Run tests
3867
run: |
39-
python3.11 manage.py test
68+
python3.11 manage.py test

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,7 @@ dmypy.json
103103
cython_debug/
104104

105105
.ruff_cache
106-
mongo_data
107-
logs
106+
/mongo_data
107+
/logs
108+
109+
/postgres_data

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python: Remote Attach (Django in Docker)",
6+
"type": "debugpy",
7+
"request": "attach",
8+
"connect": {
9+
"host": "localhost",
10+
"port": 5678
11+
},
12+
"pathMappings": [
13+
{
14+
"localRoot": "${workspaceFolder}",
15+
"remoteRoot": "/app"
16+
}
17+
],
18+
"justMyCode": false,
19+
"django": true,
20+
"subProcess": false
21+
}
22+
]
23+
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FROM python:3.12-slim-bookworm
33

44
# Set environment variables
5-
ENV PYTHONUNBUFFERED 1
5+
ENV PYTHONUNBUFFERED=1
66

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

README.Docker.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Docker Deployment Guide
2+
3+
### Building and running your application
4+
5+
When you're ready, start your application by running:
6+
`docker compose up --build`.
7+
8+
Your application will be available at http://localhost:8000.
9+
10+
### Deploying your application to the cloud
11+
12+
First, build your image, e.g.: `docker build -t myapp .`.
13+
If your cloud uses a different CPU architecture than your development
14+
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
15+
you'll want to build the image for that platform, e.g.:
16+
`docker build --platform=linux/amd64 -t myapp .`.
17+
18+
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
19+
20+
Consult Docker’s [getting started guide](https://docs.docker.com/go/get-started-sharing/) for more detail on building and pushing.
21+
22+
### References
23+
* [Docker's Python guide](https://docs.docker.com/language/python/)

0 commit comments

Comments
 (0)