Skip to content

Commit

Permalink
Merge pull request #148 from 0xPolygonID/add_deploy_to_new_aws_accounts
Browse files Browse the repository at this point in the history
chore: add deployment to aws accounts
  • Loading branch information
martinsaporiti authored Apr 24, 2024
2 parents 226a757 + 11dd817 commit ffb456b
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/deployment_new_aws_account.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Polygon ID Docs Deployment

on:
push:
branches:
- main
- develop

env:
AWS_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
ECR_REPOSITORY: devs-ecr
ECS_SERVICE: devs-ecs-service

jobs:
deploy_prod:
name: AWS Deployment
permissions:
id-token: write
contents: write
environment:
name: ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/PolygonIDActionsRole
role-session-name: GithubActionsSession

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'

- name: Install dependencies
run: rm -rf node_modules && npm ci

- name: Create .env file
run: echo 'ALGOLIA_API_KEY=${{ secrets.ALGOLIA_API_KEY }}' >> .env

# Runs a single command using the runners shell
- name: Build
run: npm run build

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ vars.ECS_TASK_DEFINITION }}
container-name: ${{ vars.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ vars.ECS_CLUSTER }}
wait-for-service-stability: true
89 changes: 89 additions & 0 deletions develop-taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"containerDefinitions": [
{
"name": "log_router",
"image": "grafana/fluent-bit-plugin-loki:2.9.1",
"cpu": 0,
"memoryReservation": 50,
"portMappings": [],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"user": "0",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "firelens-container",
"awslogs-region": "eu-west-1",
"awslogs-stream-prefix": "firelens"
}
},
"systemControls": [],
"firelensConfiguration": {
"type": "fluentbit",
"options": {
"enable-ecs-log-metadata": "true"
}
}
},
{
"name": "tooling-dev-devs-app",
"image": "654654630007.dkr.ecr.eu-west-1.amazonaws.com/devs-ecr",
"cpu": 0,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"command": null,
"environment": [
{
"name": "ENVIRONMENT",
"value": "dev"
}
],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awsfirelens",
"options": {
"LabelKeys": "container_name,ecs_task_definition,source,ecs_cluster",
"Labels": "{job=\"firelens\"}",
"LineFormat": "key_value",
"Name": "grafana-loki",
"RemoveKeys": "container_id,ecs_task_arn",
"TenantID": "dev",
"Url": "http://52.31.211.156:3100/loki/api/v1/push"
}
},
"systemControls": []
}
],
"requiresCompatibilities": [
"FARGATE"
],
"compatibilities": [
"EC2",
"FARGATE"
],
"inferenceAccelerators": [],
"volumes": [],
"networkMode": "awsvpc",
"memory": "2048",
"cpu": "1024",
"executionRoleArn": "arn:aws:iam::654654630007:role/tooling-dev-task-execution-role",
"family": "devs",
"taskRoleArn": "arn:aws:iam::654654630007:role/tooling-dev-task-execution-role",
"runtimePlatform": {
"operatingSystemFamily": "LINUX"
},
"tags": [{
"key": "Environment",
"value": "dev"
}]
}
89 changes: 89 additions & 0 deletions main-taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"containerDefinitions": [
{
"name": "log_router",
"image": "grafana/fluent-bit-plugin-loki:2.9.1",
"cpu": 0,
"memoryReservation": 50,
"portMappings": [],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"user": "0",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "firelens-container",
"awslogs-region": "eu-west-1",
"awslogs-stream-prefix": "firelens"
}
},
"systemControls": [],
"firelensConfiguration": {
"type": "fluentbit",
"options": {
"enable-ecs-log-metadata": "true"
}
}
},
{
"name": "tooling-dev-devs-app",
"image": "654654630007.dkr.ecr.eu-west-1.amazonaws.com/devs-ecr",
"cpu": 0,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"command": null,
"environment": [
{
"name": "ENVIRONMENT",
"value": "prod"
}
],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awsfirelens",
"options": {
"LabelKeys": "container_name,ecs_task_definition,source,ecs_cluster",
"Labels": "{job=\"firelens\"}",
"LineFormat": "key_value",
"Name": "grafana-loki",
"RemoveKeys": "container_id,ecs_task_arn",
"TenantID": "dev",
"Url": "http://52.31.211.156:3100/loki/api/v1/push"
}
},
"systemControls": []
}
],
"requiresCompatibilities": [
"FARGATE"
],
"compatibilities": [
"EC2",
"FARGATE"
],
"inferenceAccelerators": [],
"volumes": [],
"networkMode": "awsvpc",
"memory": "2048",
"cpu": "1024",
"executionRoleArn": "arn:aws:iam::654654630007:role/tooling-dev-task-execution-role",
"family": "devs",
"taskRoleArn": "arn:aws:iam::654654630007:role/tooling-dev-task-execution-role",
"runtimePlatform": {
"operatingSystemFamily": "LINUX"
},
"tags": [{
"key": "Environment",
"value": "prod"
}]
}

0 comments on commit ffb456b

Please sign in to comment.