Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/cd-ecs-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Deploy New Service Image

on:
push:
branches:
- master
paths:
- "src/**"
- "web/**"

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
# TODO: Create new deployment user with creds, appropriate deployment policies too
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1

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

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev-kempolds
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: task-definition.json
container-name: kempolds
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: dev-kempfolds
cluster: dev-kempfolds
wait-for-service-stability: true
27 changes: 8 additions & 19 deletions infra/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,17 @@ module "ecs_service" {

assign_public_ip = true

requires_compatibilities = ["FARGATE"]

cpu = 1024
memory = 4096

container_definitions = {
"${var.project_name}" = {
name = "${var.project_name}"
essential = true
image = "${module.public_ecr.repository_url}:latest"
port_mappings = [
{
name = "${var.project_name}"
containerPort = 80
protocol = "tcp"
}
]

readonly_root_filesystem = false

enable_cloudwatch_logging = true
memory_reservation = 100
}
}
# Create task definition file seperately to allow for continuous deployment using automation
create_task_definition = false
task_definition_arn = aws_ecs_task_definition.task_definition.arn
create_task_exec_iam_role = true
create_task_exec_policy = true
create_tasks_iam_role = true

load_balancer = {
service = {
Expand Down
39 changes: 39 additions & 0 deletions infra/files/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"name": "kempfolds",
"image": "TODO: Env Var",
"cpu": 0,
"memoryReservation": 100,
"portMappings": [
{
"name": "kempfolds",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"linuxParameters": {
"initProcessEnabled": false
},
"startTimeout": 30,
"stopTimeout": 120,
"user": "0",
"privileged": false,
"readonlyRootFilesystem": false,
"interactive": false,
"pseudoTerminal": false,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/aws/ecs/dev-kempfolds",
"awslogs-region": "eu-west-1",
"awslogs-stream-prefix": "ecs"
}
},
"systemControls": []
}
]
9 changes: 9 additions & 0 deletions infra/test-task-definition.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_ecs_task_definition" "task_definition" {
family = var.project_name
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
execution_role_arn = "arn:aws:iam::518035887622:role/ecsTaskExecutionRole"
container_definitions = file("files/task-definition.json")
cpu = 256
memory = 512
}