Skip to content

Commit

Permalink
create aws-deploy.yml and add task-definition.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimagaa committed Nov 22, 2023
1 parent df7340e commit cbf3841
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/aws-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Deploy to ECS

on:
push:
branches: [ main ]

env:
AWS_REGION: us-east-1
AWS_ASSUME_ROLE: arn:aws:iam::410123344539:role/github-book-store-repository
ECR_REPOSITORY: botblend
ECS_SERVICE: botblend
ECS_CLUSTER: BotBlendCluster
ECS_TASK_DEFINITION: .github/workflows/task-definition.json
CONTAINER_NAME: botblend

permissions:
id-token: write
contents: read

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
cache: maven

- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ASSUME_ROLE}}
role-session-name: Github_push_session
aws-region: ${{ env.AWS_REGION }}

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

- name: Build and push image to ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REGISTRY_ALIAS: w5z6u3w9
REPOSITORY: online-book-store
IMAGE_TAG: latest
run: |
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
- 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: task-definition.json
container-name: my-container
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: my-service
cluster: my-cluster
wait-for-service-stability: true
95 changes: 95 additions & 0 deletions .github/workflows/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"taskDefinitionArn": "arn:aws:ecs:eu-north-1:410123344539:task-definition/botblend:2",
"containerDefinitions": [
{
"name": "botblend",
"image": "public.ecr.aws/w5z6u3w9/botblend:latest",
"cpu": 1024,
"memory": 1024,
"portMappings": [
{
"name": "botblend-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
},
{
"name": "botblend-8080-tcp",
"containerPort": 8080,
"hostPort": 8080,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/botblend",
"awslogs-region": "eu-north-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"resourceRequirements": [
{
"value": "1",
"type": "GPU"
}
]
}
],
"family": "botblend",
"taskRoleArn": "arn:aws:iam::410123344539:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::410123344539:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 2,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2"
],
"requiresCompatibilities": [
"EC2"
],
"cpu": "1024",
"memory": "1024",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2023-11-22T07:06:25.121Z",
"registeredBy": "arn:aws:iam::410123344539:root",
"tags": []
}

0 comments on commit cbf3841

Please sign in to comment.