Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

10 fix local dev issues #11

Merged
merged 27 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ef58ded
debug flower health check
briancaffey May 26, 2020
11aa66d
Merge branch 'develop'
briancaffey May 28, 2020
7bc1d1c
Merge branch 'develop'
briancaffey May 30, 2020
c86cf9a
refactored cdk.yml
briancaffey Jun 20, 2020
5f3ce16
upated architecture diagram, updated documentation with new diagram
briancaffey Jun 20, 2020
620a270
changed event type from sync to gevent in gunicorn settings
briancaffey Jun 24, 2020
6fccd97
Merge branch '47-feature-gunicorn-gevent' into 'develop'
briancaffey Jun 24, 2020
1bdca4d
Merge branch 'develop' into 'master'
briancaffey Jun 24, 2020
99a08bd
changed cdk.yml rules
briancaffey Jun 24, 2020
45015c8
changed cdk destroy command
briancaffey Jun 24, 2020
c133165
fixed pip install command for cdk destroy
briancaffey Jun 24, 2020
d4d2e87
added awscli with pip
briancaffey Jun 24, 2020
f09a552
temporarily pause rb command
briancaffey Jun 24, 2020
2e990d4
added --force option to cdk destroy
briancaffey Jun 24, 2020
9c5c38c
refactored gitlab ci cdk with base template
briancaffey Jun 26, 2020
ad4d16a
removed after_script
briancaffey Jun 26, 2020
b1a5883
added production environment, added gitlab ci environment key to cdk …
briancaffey Jun 26, 2020
cb1b36e
removed unused code for gcp
briancaffey Jun 26, 2020
d70d1b2
fixed includes templates in main gitlab ci file
briancaffey Jun 26, 2020
3bed8c5
debugging workflow rules
briancaffey Jun 26, 2020
c9fba0e
debugging workflow rules
briancaffey Jun 26, 2020
3ed8860
debugging workflow rules
briancaffey Jun 26, 2020
9b107db
moved include key to dev.yml
briancaffey Jun 26, 2020
88b566c
updated app.py to handle base domain name for app environment
briancaffey Jun 28, 2020
951dd49
removed unused env vars, removed watch scripts for celery, added watc…
briancaffey Sep 3, 2020
5a55b35
fixed index.template.html for quasar v2, ran npm run lint -- --fix, c…
briancaffey Sep 3, 2020
4e3da4a
fixed broken ws link, env vars were adding double quotes around ws://…
briancaffey Sep 3, 2020
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
10 changes: 0 additions & 10 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
SECRET_KEY=secret
DEBUG=True

POSTGRES_NAME=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_SERVICE_HOST=postgres
POSTGRES_SERVICE_PORT=5432


# social auth
GITHUB_KEY=yourkey
GITHUB_SECRET=yoursecret
Expand All @@ -18,9 +11,6 @@ GOOGLE_OAUTH2_SECRET=abcde-fghij
SOCIAL_AUTH_FACEBOOK_KEY = ''
SOCIAL_AUTH_FACEBOOK_SECRET = ''

CELERY_BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/1

DJANGO_EMAIL_HOST=mailhog
DJANGO_EMAIL_PORT=1025

Expand Down
6 changes: 2 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ stages:
- build
- integration
- release
- plan
- deploy

# gitlab ci deployment options
include:
- local: /gitlab-ci/documentation.yml
- local: /gitlab-ci/renovate.yml
- local: /gitlab-ci/aws/cdk.yml
# - local: /gitlab-ci/aws/cloudformation.yml
#- local: /gitlab-ci/gcp/terraform.yml
- local: /gitlab-ci/aws/dev.yml
- local: /gitlab-ci/aws/app.yml

.Pytest:
image: python:3.8
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

89 changes: 80 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,92 @@ Documentation for this project can be found here:

[https://verbose-equals-true.gitlab.io/django-postgres-vue-gitlab-ecs/](https://verbose-equals-true.gitlab.io/django-postgres-vue-gitlab-ecs/)


## Project Architecture Overview

Here is an overview of the project architecture, including the CI/CD pipeline and the AWS infrastructure that will be automatically provisioned through the AWS Cloud Development Kit:

![png](/architecture.png)

(This diagram was created with [draw.io](https://draw.io). Here's the link to the a read-only version of the diagram on draw.io: [https://drive.google.com/file/d/1gU61zjoW80fCusUcswU1zhEE5VFB1Z5U/view?usp=sharing](https://drive.google.com/file/d/1gU61zjoW80fCusUcswU1zhEE5VFB1Z5U/view?usp=sharing)

### Legend

1 - GitLab is used to host the source code, test the source code and deploy the application to AWS.

2 - Unit testing (see `.gitlab-ci.yml`)

2a - Pytest

2b - Jest

2c - Cypress

3 - Deployment phase (see `/gitlab-ci/aws/cdk.yml`)

3a - Quasar PWA assets are built if there are changes in the `quasar` directory

3b - AWS Cloud Development Kit (CDK) defines all infrastructure in AWS (4a - 12)

3c - AWS CLI is used to run Fargate tasks through manual GitLab CI jobs

4 - CDK Assets (ECR and S3 buckets that CDK uses internally to manage build assets and artifacts)

4a - Elastic Container Repository is used to manage the Django docker image used in various parts of the application

4b - S3 bucket used to store files associated with CDK and CloudFormation

5 - Route53 is used to route traffic to the CloudFront distribution

6 - CloudFront distribution that serves as the "front desk" of the application. It routes requests to to the correct CloudFront Origin

7 - CloudFront Origin Configurations

7a - S3 bucket for Quasar PWA assets

7b - Application Load Balancer for Django application (`/api/`, `/admin/`, `/flower/`, `/ws/`, `/graphql/`)

7c - S3 bucket for Django assets (static files, public media and private media)

8 - Web server and websocket servers

8a - Fargate service running uvicorn process (REST, GraphQL, Django Channels)

8b - Autoscaling Group for Fargate Service that serves Django API

9 - Celery and celery worker autoscaling

9a - Fargate service that is autoscaled between 0 and `N` Fargate tasks for a given celery queue

9b - Scheduled Event that triggers a Lambda to make a request to Django backend which collects celery queue metrics and published metrics to CloudWatch using boto3

9c - Lambda event the makes a request to `/api/celery-metrics/`

9d - CloudWatch alarm that is used to scale the Fargate service for a celery queue

9e - Autoscaling group for celery Fargate service

10 - Fargate tasks that run Django management commands such as `migrate` and `collectstatic`. These are triggered from manual GitLab CI jobs using the AWS CLI (3c)

11 - ElastiCache for Redis, used for Caching, Celery Broker, Channels Layer, etc.

12 - Aurora Postgres Serverless

## Local Development

First, copy `.env.template` to a new file in the project's root directory called `.env`. This file will be read by `docker-compose` in the next step. Adjust any of the values in this file if needed, or add new variables for any secret information you need to pass to docker-compose (or to docker containers).

```sh
docker-compose up
```

Open `http://localhost` in your browser.

You can specify environment variables for docker-compose by adding an `.env` file to the root of the project based on `.env.template`.

### Social Authentication Keys

To use social sign on in development, you will need to create an application with the given provider.
To use social sign on in local development, you will need to create an application with the given provider such as GitHub, Google, Facebook, etc.

#### GitHub

Expand All @@ -23,14 +102,6 @@ Go to [https://github.com/settings/applications/new](https://github.com/settings

In the `.env` file, add the `Client ID` of your GitHub OAuth App as the `GITHUB_KEY` variable, and add the `Client Secret` as the `GITHUB_SECRET` variable.

```sh
docker-compose up
```

Open `http://localhost` in your browser.

You can specify environment variables for docker-compose by adding an `.env` file to the root of the project based on `.env.template`.

## VuePress Documentation

This project uses VuePress for documentation. To view the documentation site locally, run the following command:
Expand Down
Binary file modified architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions awscdk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# if the the production environent subdomain should nott be included in the URL
# redefine `full_domain_name` to `base_domain_name` for that environment
full_domain_name = f"{environment_name}.{base_domain_name}" # dev.mysite.com
# if environment_name == "prod":
# full_domain_name = base_domain_name
if environment_name == "app":
full_domain_name = base_domain_name
base_app_name = os.environ.get("APP_NAME", "mysite-com")
full_app_name = f"{environment_name}-{base_app_name}" # dev-mysite-com
aws_region = os.environ.get("AWS_DEFAULT_REGION", "us-east-1")
Expand Down
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
media
static
37 changes: 0 additions & 37 deletions backend/apps/core/management/commands/watch_celery.py

This file was deleted.

33 changes: 0 additions & 33 deletions backend/apps/core/management/commands/watch_celery_beat.py

This file was deleted.

10 changes: 4 additions & 6 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
"""

import os
from pathlib import Path

from kombu import Queue
import redis

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
Expand Down Expand Up @@ -269,7 +267,7 @@
# Assets

STATIC_URL = "/static/"
STATIC_ROOT = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
1 change: 1 addition & 0 deletions backend/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ djangorestframework==3.11.0
djangorestframework_simplejwt==4.4.0
django-debug-toolbar==2.2

gevent==20.6.2

# Python Social Auth

Expand Down
6 changes: 5 additions & 1 deletion backend/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ django-extensions==2.2.9 # NOTE: in installed_apps
Werkzeug==1.0.1 # used for runserver_plus exception console
ipython==7.14.0
jupyter==1.0.0
gql==2.0.0
gql==2.0.0

watchdog==0.10.3
pyyaml==5.3.1
argh==0.26.2
49 changes: 0 additions & 49 deletions backend/scripts/ci/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion backend/scripts/prod/start_prod.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

gunicorn -t 300 -b 0.0.0.0:8000 backend.wsgi
gunicorn -t 300 -k gevent -w 4 -b 0.0.0.0:8000 backend.wsgi
29 changes: 0 additions & 29 deletions cloudformation/infrastructure/certs.yaml

This file was deleted.

Loading