Skip to content

Commit 33333bc

Browse files
committed
add basic cloudformation templates
1 parent fec23c5 commit 33333bc

File tree

7 files changed

+929
-0
lines changed

7 files changed

+929
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Deploy to Amazon ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
workflow_dispatch:
8+
9+
env:
10+
AWS_REGION: ${{ secrets.AWS_REGION }}
11+
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
12+
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
13+
ECS_EXECUTION_ROLE_ARN: ${{ secrets.ECS_EXECUTION_ROLE_ARN }}
14+
APP_NAME: dataspace
15+
APP_PORT: 8000
16+
DB_ENGINE: django.db.backends.postgresql
17+
DB_PORT: 5432
18+
DEBUG_MODE: "False"
19+
TELEMETRY_URL: http://otel-collector:4317
20+
CPU_UNITS: 256
21+
MEMORY_UNITS: 512
22+
SSM_PATH_PREFIX: /dataspace
23+
ENVIRONMENT: ${{ secrets.ENVIRONMENT || 'dev' }}
24+
25+
jobs:
26+
deploy-infrastructure:
27+
name: Deploy Infrastructure
28+
runs-on: ubuntu-latest
29+
environment: development
30+
if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.modified, 'aws/cloudformation')
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v1
38+
with:
39+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
aws-region: ${{ env.AWS_REGION }}
42+
43+
- name: Deploy CloudFormation stack
44+
run: |
45+
aws cloudformation deploy \
46+
--template-file aws/cloudformation/dataspace-infrastructure.yml \
47+
--stack-name dataspace-${{ env.ENVIRONMENT }}-infrastructure \
48+
--parameter-overrides \
49+
Environment=${{ env.ENVIRONMENT }} \
50+
VpcId=${{ secrets.VPC_ID }} \
51+
SubnetIds=${{ secrets.SUBNET_IDS }} \
52+
DBUsername=${{ secrets.DB_USERNAME }} \
53+
DBPassword=${{ secrets.DB_PASSWORD }} \
54+
DBName=${{ secrets.DB_NAME }} \
55+
ElasticsearchPassword=${{ secrets.ELASTICSEARCH_PASSWORD }} \
56+
DjangoSecretKey=${{ secrets.DJANGO_SECRET_KEY }} \
57+
--capabilities CAPABILITY_IAM \
58+
--no-fail-on-empty-changeset
59+
60+
deploy-app:
61+
name: Deploy Application
62+
runs-on: ubuntu-latest
63+
environment: development
64+
needs: deploy-infrastructure
65+
if: always() # Run even if infrastructure deployment is skipped
66+
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v3
70+
71+
- name: Configure AWS credentials
72+
uses: aws-actions/configure-aws-credentials@v1
73+
with:
74+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
75+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76+
aws-region: ${{ env.AWS_REGION }}
77+
78+
- name: Login to Amazon ECR
79+
id: login-ecr
80+
uses: aws-actions/amazon-ecr-login@v1
81+
82+
- name: Build, tag, and push image to Amazon ECR
83+
id: build-image
84+
env:
85+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
86+
IMAGE_TAG: ${{ github.sha }}
87+
run: |
88+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
89+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
90+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
91+
92+
- name: Process main task definition template
93+
id: task-def-app
94+
env:
95+
ECR_REPOSITORY_URI: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
96+
IMAGE_TAG: ${{ github.sha }}
97+
run: |
98+
envsubst < aws/task-definition.json > aws/task-definition-processed.json
99+
cat aws/task-definition-processed.json
100+
101+
- name: Deploy main application ECS task definition
102+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
103+
with:
104+
task-definition: aws/task-definition-processed.json
105+
service: ${{ secrets.ECS_SERVICE }}
106+
cluster: ${{ env.ECS_CLUSTER }}
107+
wait-for-service-stability: true
108+
109+
deploy-otel:
110+
name: Deploy OpenTelemetry Collector
111+
runs-on: ubuntu-latest
112+
environment: development
113+
needs: deploy-app
114+
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v3
118+
119+
- name: Configure AWS credentials
120+
uses: aws-actions/configure-aws-credentials@v1
121+
with:
122+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
123+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
124+
aws-region: ${{ env.AWS_REGION }}
125+
126+
- name: Process OpenTelemetry task definition template
127+
id: task-def-otel
128+
run: |
129+
envsubst < aws/otel-collector-task-definition.json > aws/otel-collector-task-definition-processed.json
130+
cat aws/otel-collector-task-definition-processed.json
131+
132+
- name: Deploy OpenTelemetry ECS task definition
133+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
134+
with:
135+
task-definition: aws/otel-collector-task-definition-processed.json
136+
service: ${{ secrets.ECS_OTEL_SERVICE }}
137+
cluster: ${{ env.ECS_CLUSTER }}
138+
wait-for-service-stability: true

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repos:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: check-yaml
8+
exclude: ^aws/cloudformation/.*\.yml$
89
- id: check-added-large-files
910
- id: debug-statements
1011

@@ -20,6 +21,17 @@ repos:
2021
- id: isort
2122
args: ["--profile", "black"]
2223

24+
- repo: local
25+
hooks:
26+
- id: cloudformation-validate
27+
name: AWS CloudFormation Validation
28+
description: Validates CloudFormation templates using AWS CLI
29+
entry: bash -c 'aws cloudformation validate-template --template-body file://$0 || exit 1'
30+
language: system
31+
files: ^aws/cloudformation/.*\.yml$
32+
require_serial: true
33+
pass_filenames: true
34+
2335
- repo: https://github.com/pre-commit/mirrors-mypy
2436
rev: v1.9.0
2537
hooks:

0 commit comments

Comments
 (0)