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

Commit 8b67d09

Browse files
committed
resolved merge conflicts
2 parents 2853af7 + cc0cae1 commit 8b67d09

File tree

27 files changed

+507
-347
lines changed

27 files changed

+507
-347
lines changed

.env.template

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
SECRET_KEY=secret
22
DEBUG=True
33

4-
RDS_DB_NAME=postgres
5-
RDS_USERNAME=postgres
6-
RDS_PASSWORD=postgres
7-
RDS_HOSTNAME=postgres
8-
RDS_PORT=5432
4+
POSTGRES_NAME=postgres
5+
POSTGRES_USERNAME=postgres
6+
POSTGRES_PASSWORD=postgres
7+
POSTGRES_SERVICE_HOST=postgres
8+
POSTGRES_SERVICE_PORT=5432
99

1010
GITHUB_KEY=yourkey
1111
GITHUB_SECRET=yoursecret

.gitlab-ci.yml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,11 @@ Build Quasar PWA Assets:
143143
only:
144144
- master
145145
variables:
146-
VUE_APP_CI_COMMIT_SHORT_SHA: "$CI_COMMIT_SHORT_SHA"
147-
VUE_APP_CI_JOB_URL: "$CI_JOB_URL"
148-
VUE_APP_API_BASE_URL: "https://api.${AppUrl}"
149-
VUE_APP_BASE_URL: "https://${AppUrl}"
150-
VUE_APP_WS_PROTOCOL: wss://
151-
VUE_APP_BASE_HOST: api.${AppUrl}
152-
VUE_APP_SITE_DOMAIN: ${AppUrl}
146+
DOMAIN_NAME: "api.${AppUrl}"
147+
GOOGLE_OAUTH2_KEY: google123
148+
GITHUB_KEY: github123
149+
WS_PROTOCOL: wss
150+
HTTP_PROTOCOL: https
153151
artifacts:
154152
paths:
155153
- quasar/dist/pwa
@@ -221,9 +219,7 @@ Sync Quasar PWA Assets:
221219

222220
.Create stack:
223221
image: python:3.7
224-
stage: cloudformation
225-
only:
226-
- master
222+
stage: deploy
227223
variables:
228224
EnvironmentName: staging
229225
before_script:
@@ -243,7 +239,7 @@ Sync Quasar PWA Assets:
243239

244240
Update stack:
245241
image: python:3.7
246-
stage: cloudformation
242+
stage: deploy
247243
only:
248244
- master
249245
variables:
@@ -262,3 +258,29 @@ Update stack:
262258
--parameters file://./parameters.json
263259
after_script:
264260
- echo "Update stack complete"
261+
262+
collectstatic: &task
263+
image: python:3.7
264+
stage: deploy
265+
only:
266+
- master
267+
variables:
268+
EnvironmentName: staging
269+
before_script:
270+
- pip install awscli
271+
when: manual
272+
script:
273+
- |
274+
aws ecs run-task \
275+
--cluster ${EnvironmentName}-cluster \
276+
--task-definition collectstatic
277+
278+
migrate:
279+
<<: *task
280+
variables:
281+
EnvironmentName: staging
282+
script:
283+
- |
284+
aws ecs run-task \
285+
--cluster ${EnvironmentName}-cluster \
286+
--task-definition migrate

backend/backend/settings/base.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
CORS_ALLOW_HEADERS = default_headers + (
3737
'access-control-allow-headers',
3838
'access-control-allow-methods',
39+
'access-control-allow-origin'
3940
)
4041

4142
# Application definition
@@ -102,6 +103,7 @@
102103
'django.middleware.security.SecurityMiddleware',
103104
'django.contrib.sessions.middleware.SessionMiddleware',
104105
'social_django.middleware.SocialAuthExceptionMiddleware',
106+
'corsheaders.middleware.CorsMiddleware',
105107
'django.middleware.common.CommonMiddleware',
106108
'django.middleware.csrf.CsrfViewMiddleware',
107109
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -136,33 +138,33 @@
136138
DATABASES = {
137139
'default': {
138140
'ENGINE': 'django.db.backends.postgresql_psycopg2',
139-
'NAME': os.environ.get('RDS_DB_NAME', 'postgres'),
140-
'USER': os.environ.get('RDS_USERNAME', 'postgres'),
141-
'PASSWORD': os.environ.get('RDS_PASSWORD', 'postgres'),
142-
'HOST': os.environ.get('RDS_HOSTNAME', 'postgres'),
143-
'PORT': os.environ.get('RDS_PORT', 5432),
141+
'NAME': os.environ.get('POSTGRES_NAME', 'postgres'),
142+
'USER': os.environ.get('POSTGRES_USERNAME', 'postgres'),
143+
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
144+
'HOST': os.environ.get('POSTGRES_SERVICE_HOST', 'postgres'),
145+
'PORT': os.environ.get('POSTGRES_SERVICE_PORT', 5432),
144146
}
145147
}
146148

147149
ASGI_APPLICATION = 'backend.routing.application'
148150

149-
ELASTICACHE_REDIS_HOST_NAME = \
151+
REDIS_SERVICE_HOST = \
150152
os.environ.get(
151-
'CELERY_BROKER_URL',
153+
'REDIS_SERVICE_HOST',
152154
'redis://redis:6379'
153-
)[8:].split(':')[0]
155+
)
154156

155157
CHANNEL_LAYERS = {
156158
'default': {
157159
'BACKEND': 'channels_redis.core.RedisChannelLayer',
158160
'CONFIG': {
159-
"hosts": [(ELASTICACHE_REDIS_HOST_NAME, 6379)],
161+
"hosts": [(REDIS_SERVICE_HOST, 6379)],
160162
},
161163
},
162164
}
163165

164166
REDIS = redis.Redis(
165-
host=ELASTICACHE_REDIS_HOST_NAME,
167+
host=REDIS_SERVICE_HOST,
166168
port=6379,
167169
db=3,
168170
charset="utf-8",
@@ -186,10 +188,6 @@
186188

187189
# Celery Configuration
188190

189-
CELERY_BROKER_URL = \
190-
os.environ.get('CELERY_BROKER_URL', 'redis://redis:6379')
191-
CELERY_RESULT_BACKEND = \
192-
os.environ.get('CELERY_RESULT_BACKEND', 'redis://redis:6379')
193191
CELERY_ACCEPT_CONTENT = ['application/json']
194192
CELERY_TASK_SERIALIZER = 'json'
195193
CELERY_RESULT_SERIALIZER = 'json'

backend/backend/settings/development.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
SECRET_KEY = "my-secret-key"
44

5-
DATABASES = {
6-
'default': {
7-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
8-
'NAME': os.environ.get('RDS_DB_NAME', 'postgres'), # noqa
9-
'USER': os.environ.get('RDS_USERNAME', 'postgres'), # noqa
10-
'PASSWORD': os.environ.get('RDS_PASSWORD', 'postgres'), # noqa
11-
'HOST': os.environ.get('RDS_HOSTNAME', 'postgres'), # noqa
12-
'PORT': os.environ.get('RDS_PORT', 5432), # noqa
13-
}
14-
}
5+
# Celery
6+
7+
CELERY_BROKER_URL = \
8+
os.environ.get('CELERY_BROKER_URL', 'redis://redis:6379') # noqa
9+
CELERY_RESULT_BACKEND = \
10+
os.environ.get('CELERY_RESULT_BACKEND', 'redis://redis:6379') # noqa
1511

1612
DEBUG_APPS = [
1713
'django_extensions',

backend/backend/settings/production.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@
3636
},
3737
},
3838
}
39+
40+
# Celery
41+
42+
CELERY_BROKER_URL = f"redis://{REDIS_SERVICE_HOST}:6379/0" # noqa
43+
CELERY_RESULT_BACKEND = f"redis://{REDIS_SERVICE_HOST}:6379/0" # noqa

backend/core/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def hello_world(request):
4545
response = JsonResponse(
4646
{
4747
'message': 'Hello, World!',
48-
'git_sha': os.environ.get('GIT_SHA', '<git sha>')
48+
'git_sha': os.environ.get('GIT_SHA', '<git SHA>'),
49+
'debug': settings.DEBUG,
50+
'format': 'JSON'
4951
}
5052
)
5153
return response

backend/scripts/prod/start_prod.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22

33
python3 manage.py collectstatic --no-input
4-
python3 manage.py makemigrations
54
python3 manage.py migrate --no-input
65
gunicorn -t 300 -b 0.0.0.0:8000 backend.wsgi

cloudformation/infrastructure/ecr-repository.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ Description: >
22
This template deploys an ECR Repository that we will use when pushing our backend container images.
33
44
Parameters:
5+
6+
StackName:
7+
Type: String
8+
Description: The name of the stack
9+
510
ECRBackendRepositoryName:
611
Type: "String"
712
Description: "The name of the ECR Repository for our backend conainer."
@@ -13,5 +18,6 @@ Resources:
1318
RepositoryName: !Ref ECRBackendRepositoryName
1419

1520
Outputs:
16-
ECRBackendRepositoryURL:
21+
EcrBackendRepo:
22+
Description: The ECR Repository for the main backend container
1723
Value: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ECRBackendRepositoryName}"

cloudformation/infrastructure/ecs-cluster.yaml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Description: >
33
44
Parameters:
55

6+
StackName:
7+
Type: String
8+
Description: The name of the stack
9+
610
EnvironmentName:
711
Type: String
812
Description: An environemnt name to namespace cluster resources (e.g. qa, staging, production)
@@ -17,10 +21,6 @@ Parameters:
1721
r5.large, r5.xlarge, r5.2xlarge, r5.4xlarge, r5.12xlarge, r5.24xlarge ]
1822
ConstraintDescription: Please choose a valid instance type.
1923

20-
VPC:
21-
Description: Main VPC
22-
Type: AWS::EC2::VPC::Id
23-
2424
LoadBalancerSecurityGroup:
2525
Type: AWS::EC2::SecurityGroup::Id
2626
Description: Security group for the load balancer
@@ -57,12 +57,16 @@ Resources:
5757

5858
ECSCluster:
5959
Type: AWS::ECS::Cluster
60+
Properties:
61+
ClusterName: !Sub ${EnvironmentName}-cluster
6062

6163
ContainerInstanceSecurityGroup:
6264
Type: AWS::EC2::SecurityGroup
6365
Properties:
6466
GroupDescription: Access to the ECS hosts that run containers.
65-
VpcId: !Ref 'VPC'
67+
VpcId:
68+
Fn::ImportValue:
69+
!Sub ${StackName}:VpcId
6670
SecurityGroupIngress:
6771
- SourceSecurityGroupId: !Ref LoadBalancerSecurityGroup
6872
IpProtocol: -1
@@ -174,15 +178,27 @@ Resources:
174178
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
175179
Policies:
176180
- PolicyName: s3-access
177-
PolicyDocument: |
181+
PolicyDocument: !Sub |
178182
{
179-
"Statement": [
180-
{
181-
"Effect": "Allow",
182-
"Action": "s3:*",
183-
"Resource": "*"
184-
}
185-
]
183+
"Version": "2012-10-17",
184+
"Statement": [
185+
{
186+
"Sid": "VisualEditor0",
187+
"Effect": "Allow",
188+
"Action": [
189+
"s3:PutObject",
190+
"s3:GetObjectAcl",
191+
"s3:GetObject",
192+
"s3:ListBucket",
193+
"s3:DeleteObject",
194+
"s3:PutObjectAcl"
195+
],
196+
"Resource": [
197+
"arn:aws:s3:::${StackName}-assets/*",
198+
"arn:aws:s3:::${StackName}-assets"
199+
]
200+
}
201+
]
186202
}
187203
- PolicyName: ecs-service
188204
PolicyDocument: |
@@ -329,7 +345,7 @@ Outputs:
329345
Description: The name of the ECS cluster
330346
Value: !Ref 'ECSCluster'
331347
Export:
332-
Name: !Sub ${EnvironmentName}:ClusterName
348+
Name: !Sub ${StackName}:ECSCluster
333349

334350
AutoScalingRole:
335351
Description: The ARN of the role used for auto-scaling

cloudformation/infrastructure/elasticache-redis.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ Description: >
22
This template deploys a single node ElastiCache cluster that runs Redis
33
44
Parameters:
5-
VPC:
6-
Description: Main VPC
7-
Type: AWS::EC2::VPC::Id
5+
6+
StackName:
7+
Type: String
8+
Description: The name of the stack
89

910
PrivateSubnets:
1011
Description: List of private subnets for RDS
@@ -19,7 +20,9 @@ Resources:
1920
Type: AWS::EC2::SecurityGroup
2021
Properties:
2122
GroupDescription: ElastiCache Security Group
22-
VpcId: !Ref VPC
23+
VpcId:
24+
Fn::ImportValue:
25+
!Sub ${StackName}:VpcId
2326
SecurityGroupIngress:
2427
- IpProtocol: tcp
2528
FromPort: 6379
@@ -43,6 +46,8 @@ Resources:
4346
- !GetAtt ElastiCacheSecurityGroup.GroupId
4447

4548
Outputs:
46-
RedisEndpoint:
47-
Description: Endpoint for ElastiCache Cluster
48-
Value: !Join ['', ['redis://', !GetAtt ElastiCacheCluster.RedisEndpoint.Address, ':6379/0']]
49+
ElastiCacheHost:
50+
Description: Hostname for ElastiCache Cluster
51+
Value: !GetAtt ElastiCacheCluster.RedisEndpoint.Address
52+
Export:
53+
Name: !Sub ${StackName}:ElastiCacheHost

0 commit comments

Comments
 (0)