Skip to content

Commit 1502be5

Browse files
committed
auto-deployment-backend
1 parent ed142b0 commit 1502be5

File tree

7 files changed

+371
-111
lines changed

7 files changed

+371
-111
lines changed

.github/workflows/cd.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Continuous Deployment
2+
3+
on: push
4+
5+
jobs:
6+
deploy:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Setup up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.10
17+
18+
- name: Set up virtual environment
19+
run: |
20+
python -m venv venv
21+
source venv/bin/activate
22+
23+
- name: Install dependencies
24+
run: |
25+
source venv/bin/activate
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v1
31+
with:
32+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
33+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
34+
aws-region: eu-central-1
35+
36+
- name: Setup up Requirements
37+
run: |
38+
source venv/bin/activate
39+
chmod +x ./getEnv.sh && ./getEnv.sh
40+
python load_env.py
41+
zappa package prod -o package.zip
42+
43+
- name: Deploy
44+
run: |
45+
cd deployments
46+
terraform init
47+
terraform apply -auto-approve

config/settings.py

+90-111
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,120 @@
1-
"""
2-
Django settings for config project.
3-
4-
Generated by 'django-admin startproject' using Django 4.0.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/4.0/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/4.0/ref/settings/
11-
"""
12-
13-
from pathlib import Path
1+
import os
142
from decouple import config
153

16-
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17-
BASE_DIR = Path(__file__).resolve().parent.parent
184

195

20-
# Quick-start development settings - unsuitable for production
21-
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
22-
23-
# SECURITY WARNING: keep the secret key used in production secret!
24-
SECRET_KEY = config('SECRET_KEY')
25-
26-
# SECURITY WARNING: don't run with debug turned on in production!
27-
DEBUG = True # We will turn this to false when have auto backend deployment
28-
29-
ALLOWED_HOSTS = []
6+
DEBUG = True
307

8+
USE_TZ = True
319

32-
# Application definition
10+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3311

34-
INSTALLED_APPS = [
35-
'django.contrib.admin',
36-
'django.contrib.auth',
37-
'django.contrib.contenttypes',
38-
'django.contrib.sessions',
39-
'django.contrib.messages',
40-
'django.contrib.staticfiles',
41-
'rest_framework',
42-
'livereload',
43-
'api.apps.ApiConfig',
44-
'corsheaders',
45-
]
46-
47-
MIDDLEWARE = [
48-
'corsheaders.middleware.CorsMiddleware',
49-
'django.middleware.security.SecurityMiddleware',
50-
'django.contrib.sessions.middleware.SessionMiddleware',
51-
'django.middleware.common.CommonMiddleware',
52-
'django.middleware.csrf.CsrfViewMiddleware',
53-
'django.contrib.auth.middleware.AuthenticationMiddleware',
54-
'django.contrib.messages.middleware.MessageMiddleware',
55-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
56-
'livereload.middleware.LiveReloadScript',
57-
]
12+
USE_I18N = True
5813

59-
ROOT_URLCONF = 'config.urls'
14+
USE_L10N = True
15+
16+
DATABASES = {
17+
'default': {
18+
'HOST': config('DB_HOST'),
19+
'NAME': config('DB_NAME'),
20+
'PORT': config('DB_PORT'),
21+
'USER': config('DB_USER'),
22+
'ENGINE': "django.db.backends.postgresql_psycopg2",
23+
'PASSWORD': config('DB_PASSWORD'),
24+
}
25+
}
6026

6127
TEMPLATES = [
62-
{
63-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
64-
'DIRS': [],
65-
'APP_DIRS': True,
66-
'OPTIONS': {
67-
'context_processors': [
68-
'django.template.context_processors.debug',
69-
'django.template.context_processors.request',
70-
'django.contrib.auth.context_processors.auth',
71-
'django.contrib.messages.context_processors.messages',
72-
],
73-
},
74-
},
28+
{
29+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
30+
'DIRS': [],
31+
'APP_DIRS': True,
32+
'OPTIONS': {
33+
'context_processors': [
34+
'django.template.context_processors.debug',
35+
'django.template.context_processors.request',
36+
'django.contrib.auth.context_processors.auth',
37+
'django.contrib.messages.context_processors.messages',
38+
]
39+
}
40+
}
7541
]
7642

77-
WSGI_APPLICATION = 'config.wsgi.application'
78-
79-
80-
# Database
81-
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
43+
TIME_ZONE = 'UTC'
8244

83-
# DATABASES = {
84-
# 'default': {
85-
# 'ENGINE': 'django.db.backends.sqlite3',
86-
# 'NAME': BASE_DIR / 'db.sqlite3',
87-
# }
88-
# }
45+
MIDDLEWARE = [
46+
'django.middleware.security.SecurityMiddleware',
47+
'django.contrib.sessions.middleware.SessionMiddleware',
48+
'corsheaders.middleware.CorsMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
]
8955

56+
# SECURITY WARNING: keep the secret key used in production secret!
57+
SECRET_KEY = config('SECRET_KEY')
9058

91-
# Password validation
92-
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
93-
94-
AUTH_PASSWORD_VALIDATORS = [
95-
{
96-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
97-
},
98-
{
99-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
100-
},
101-
{
102-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
103-
},
104-
{
105-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
106-
},
107-
]
59+
STATIC_URL = '/static/'
10860

61+
ROOT_URLCONF = 'config.urls'
10962

110-
# Internationalization
111-
# https://docs.djangoproject.com/en/4.0/topics/i18n/
63+
ALLOWED_HOSTS = ['*']
11264

11365
LANGUAGE_CODE = 'en-us'
11466

115-
TIME_ZONE = 'UTC'
116-
117-
USE_I18N = True
67+
INSTALLED_APPS = [
68+
'django.contrib.admin',
69+
'django.contrib.auth',
70+
'django.contrib.contenttypes',
71+
'django.contrib.sessions',
72+
'django.contrib.messages',
73+
'django.contrib.staticfiles',
74+
'corsheaders',
75+
'rest_framework',
76+
]
11877

119-
USE_TZ = True
78+
WSGI_APPLICATION = 'config.wsgi.application'
12079

80+
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
81+
82+
CORS_ALLOW_HEADERS = [
83+
'x-requested-with',
84+
'content-type',
85+
'accept',
86+
'origin',
87+
'authorization',
88+
'accept-encoding',
89+
'x-csrftoken',
90+
'access-control-allow-origin',
91+
'content-disposition',
92+
]
12193

122-
# Static files (CSS, JavaScript, Images)
123-
# https://docs.djangoproject.com/en/4.0/howto/static-files/
94+
CORS_ALLOW_METHODS = [
95+
'GET',
96+
'POST',
97+
'PUT',
98+
'PATCH',
99+
'DELETE',
100+
'OPTIONS',
101+
]
124102

103+
AWS_S3_CUSTOM_DOMAIN = f'{config("AWS_STORAGE_BUCKET_NAME")}.s3.amazonaws.com'
125104

126-
STATIC_URL = 'static/'
105+
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
127106

128-
# Default primary key field type
129-
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
107+
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
130108

131-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
109+
CORS_ORIGIN_ALLOW_ALL = True
132110

133-
# CORS_ALLOWED_ORIGINS = config('FRONTEND_URL').split(" ")
134-
# CORS_ORIGIN_WHITELIST = config('FRONTEND_URL').split(" ")
111+
CORS_ALLOW_CREDENTIALS = False
135112

136-
REST_FRAMEWORK = {
137-
'DEFAULT_AUTHENTICATION_CLASSES': [],
138-
'DEFAULT_PERMISSION_CLASSES': [],
139-
}
113+
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
140114

141-
# CSRF_TRUSTED_ORIGINS = config('FRONTEND_URL').split(" ")
115+
AUTH_PASSWORD_VALIDATORS = [
116+
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
117+
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
118+
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
119+
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
120+
]

0 commit comments

Comments
 (0)