Skip to content

Commit ccaae5a

Browse files
committed
add efs to task definition and fix dockerfile to have a execution command
1 parent ac69774 commit ccaae5a

File tree

4 files changed

+82
-12
lines changed

4 files changed

+82
-12
lines changed

.github/workflows/deploy-to-ecs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ jobs:
8989
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
9090
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
9191
92-
- name: Download current task definition
93-
id: download-taskdef
92+
- name: Download task definition and get EFS ID
9493
run: |
95-
aws ecs describe-task-definition \
96-
--task-definition dataspace \
97-
--query taskDefinition > aws/current-task-definition.json
98-
cat aws/current-task-definition.json
94+
aws ecs describe-task-definition --task-definition dataspace --query taskDefinition > aws/current-task-definition.json
95+
aws ecs describe-task-definition --task-definition dataspace-otel-collector --query taskDefinition > aws/current-otel-task-definition.json
96+
# Get the EFS ID from CloudFormation export
97+
EFS_ID=$(aws cloudformation list-exports --query "Exports[?Name=='dataspace-${{ env.ENVIRONMENT }}-MigrationsFileSystemId'].Value" --output text)
98+
echo "EFS_ID=$EFS_ID" >> $GITHUB_ENV
9999
100100
- name: Update container image only
101101
id: task-def-app

Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ RUN echo 'deb http://archive.debian.org/debian stretch main contrib non-free' >>
1212
WORKDIR /code
1313
COPY . /code/
1414

15-
RUN pip install psycopg2-binary
15+
RUN pip install psycopg2-binary uvicorn
1616
RUN pip install -r requirements.txt
17-
#RUN python manage.py migrate
17+
18+
# Create healthcheck script
19+
RUN echo '#!/bin/bash\nset -e\npython -c "import sys; import django; django.setup(); sys.exit(0)"' > /code/healthcheck.sh \
20+
&& chmod +x /code/healthcheck.sh
1821

1922

2023
EXPOSE 8000
21-
#CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
24+
25+
# Make entrypoint script executable
26+
RUN chmod +x /code/docker-entrypoint.sh
27+
28+
ENTRYPOINT ["/code/docker-entrypoint.sh"]
29+
CMD ["uvicorn", "DataSpace.asgi:application", "--host", "0.0.0.0", "--port", "8000"]

aws/cloudformation/dataspace-infrastructure.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,39 @@ Resources:
316316
Value: !Sub 'https://dataspace-${Environment}.yourdomain.com'
317317
Description: URL whitelist
318318

319+
MigrationsFileSystem:
320+
Type: AWS::EFS::FileSystem
321+
Properties:
322+
PerformanceMode: generalPurpose
323+
Encrypted: true
324+
FileSystemTags:
325+
- Key: Name
326+
Value: {"Fn::Sub": "${AWS::StackName}-migrations"}
327+
328+
MigrationsAccessPoint:
329+
Type: AWS::EFS::AccessPoint
330+
Properties:
331+
FileSystemId: {"Ref": "MigrationsFileSystem"}
332+
PosixUser:
333+
Uid: "1000"
334+
Gid: "1000"
335+
RootDirectory:
336+
Path: "/migrations"
337+
CreationInfo:
338+
OwnerUid: "1000"
339+
OwnerGid: "1000"
340+
Permissions: "755"
341+
342+
MigrationsFileSystemMountTarget:
343+
Type: AWS::EFS::MountTarget
344+
Properties:
345+
FileSystemId:
346+
Ref: MigrationsFileSystem
347+
SubnetId:
348+
"Fn::Select": [0, {"Ref": "SubnetIds"}]
349+
SecurityGroups:
350+
- {"Ref": "ECSSecurityGroup"}
351+
319352
Outputs:
320353
ClusterName:
321354
Description: ECS Cluster Name
@@ -331,8 +364,16 @@ Outputs:
331364

332365
RedisEndpoint:
333366
Description: Redis endpoint
334-
Value: !GetAtt RedisCluster.RedisEndpoint.Address
367+
Value: {"Fn::GetAtt": ["RedisCluster", "RedisEndpoint.Address"]}
335368

336369
TaskExecutionRoleArn:
337370
Description: ECS Task Execution Role ARN
338-
Value: !GetAtt ECSTaskExecutionRole.Arn
371+
Value: {"Fn::GetAtt": ["ECSTaskExecutionRole", "Arn"]}
372+
Export:
373+
Name: {"Fn::Sub": "${AWS::StackName}-ECSTaskExecutionRoleArn"}
374+
375+
MigrationsFileSystemId:
376+
Description: EFS File System ID for migrations
377+
Value: {"Ref": "MigrationsFileSystem"}
378+
Export:
379+
Name: {"Fn::Sub": "${AWS::StackName}-MigrationsFileSystemId"}

aws/task-definition.json.template

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
{
22
"family": "dataspace",
33
"executionRoleArn": "${ECS_EXECUTION_ROLE_ARN}",
4+
"taskRoleArn": "${ECS_EXECUTION_ROLE_ARN}",
45
"networkMode": "awsvpc",
56
"requiresCompatibilities": ["FARGATE"],
67
"cpu": "${CPU_UNITS}",
78
"memory": "${MEMORY_UNITS}",
9+
"volumes": [
10+
{
11+
"name": "migrations-volume",
12+
"efsVolumeConfiguration": {
13+
"fileSystemId": "${EFS_ID}",
14+
"rootDirectory": "/migrations",
15+
"transitEncryption": "ENABLED",
16+
"authorizationConfig": {
17+
"iam": "ENABLED"
18+
}
19+
}
20+
}
21+
],
822
"containerDefinitions": [
923
{
1024
"name": "dataspace",
@@ -17,6 +31,13 @@
1731
"protocol": "tcp"
1832
}
1933
],
34+
"mountPoints": [
35+
{
36+
"sourceVolume": "migrations-volume",
37+
"containerPath": "/code/api/migrations",
38+
"readOnly": false
39+
}
40+
],
2041
"environment": [
2142
{ "name": "DEBUG", "value": "${DEBUG_MODE}" },
2243
{ "name": "APP_PORT", "value": "${APP_PORT}" },
@@ -46,7 +67,7 @@
4667
}
4768
},
4869
"healthCheck": {
49-
"command": ["CMD-SHELL", "curl -f http://localhost:${APP_PORT}/health/ || exit 1"],
70+
"command": ["CMD-SHELL", "/code/healthcheck.sh && curl -f http://localhost:${APP_PORT}/health/ || exit 1"],
5071
"interval": 30,
5172
"timeout": 5,
5273
"retries": 3,

0 commit comments

Comments
 (0)