Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrr committed Jul 19, 2024
1 parent b090934 commit 713079f
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .aws/task-definition-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"family": "atlas-orchestration",
"containerDefinitions": [
{
"name": "backend",
"image": "533266983284.dkr.ecr.us-east-1.amazonaws.com/atlas-backend",
"cpu": 0,
"portMappings": [
{
"name": "backend-8000-tcp",
"containerPort": 8000,
"hostPort": 8000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [
{
"value": "arn:aws:s3:::atlasenvironment/server.env",
"type": "s3"
}
],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/atlas-orchestration",
"awslogs-create-group": "true",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": []
},
{
"name": "frontend",
"image": "533266983284.dkr.ecr.us-east-1.amazonaws.com/atlas-frontend",
"cpu": 0,
"portMappings": [
{
"name": "frontend-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/atlas-orchestration",
"awslogs-create-group": "true",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::533266983284:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::533266983284:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "2048",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
}
}
87 changes: 87 additions & 0 deletions .github/workflows/aws-deploy-multi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy to Amazon ECS

on:
workflow_run:
workflows: ["Run Tests (Frontend)"]
branches: [login-window]
types:
- completed

env:
AWS_REGION: us-east-1 # AWS region
ECR_REPOSITORY_BACKEND: atlas-backend
ECR_REPOSITORY_FRONTEND: atlas-frontend
ECS_SERVICE: atlas-multi-container # Amazon ECS service name
ECS_CLUSTER: atlas-dev # Amazon ECS cluster name
ECS_TASK_DEFINITION: .aws/task-definition-multi.json # Amazon ECS task definition
CONTAINER_NAME_BACKEND: atlas-backend
CONTAINER_NAME_FRONTEND: atlas-frontend

permissions:
id-token: write
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_PROD_ID }}
aws-secret-access-key: ${{ secrets.AWS_PROD_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

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

- name: Fill in the new image ID in the Amazon ECS task definition
id: render-frontend-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.render-backend-container.outputs.task-definition }}
container-name: ${{ env.CONTAINER_NAME_FRONTEND }}
image: ${{ steps.build-front-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-frontend-container.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true

0 comments on commit 713079f

Please sign in to comment.