Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit d467f68

Browse files
author
Christopher Mills
committed
Add deployment changes
Signed-off-by: Chris M <[email protected]>
1 parent 979bb02 commit d467f68

File tree

9 files changed

+43
-31
lines changed

9 files changed

+43
-31
lines changed

.github/actions/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apk add --no-cache \
99
git \
1010
make
1111

12-
COPY ../../terraform /usr/src/terraform
12+
COPY ./terraform /usr/src/terraform
1313
COPY Makefile /usr/src
1414
COPY deploy.sh /usr/local/bin/deploy
1515

.github/actions/deploy.sh

100644100755
File mode changed.

terraform/ecs.tf renamed to .github/actions/terraform/ecs.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ resource "aws_route" "internet_access" {
4444
resource "aws_eip" "gw" {
4545
count = var.az_count
4646
vpc = true
47-
depends_on = aws_internet_gateway.gw
47+
depends_on = [aws_internet_gateway.gw]
4848
}
4949

5050
resource "aws_nat_gateway" "gw" {
@@ -77,8 +77,8 @@ resource "aws_route_table_association" "private" {
7777
# Load balancer security group.
7878
# This is the group you need to edit if you want to restrict access to your application.
7979
resource "aws_security_group" "ecs_lb" {
80-
name = "ecs-lb"
81-
description = "controls access to the ALB"
80+
name = "terraform-ecs-lb"
81+
description = "Controls access to the ALB"
8282
vpc_id = aws_vpc.main.id
8383

8484
ingress {
@@ -119,13 +119,13 @@ resource "aws_security_group" "ecs_tasks" {
119119

120120
### Load balancer.
121121
resource "aws_alb" "main" {
122-
name = "github-actions-deploy"
123-
subnets = [aws_subnet.public.*.id]
122+
name = var.alb_name
123+
subnets = aws_subnet.public.*.id
124124
security_groups = [aws_security_group.ecs_lb.id]
125125
}
126126

127127
resource "aws_alb_target_group" "app" {
128-
name = "github-actions-deploy"
128+
name = aws_alb.main.name
129129
port = 80
130130
protocol = "HTTP"
131131
vpc_id = aws_vpc.main.id
@@ -146,5 +146,5 @@ resource "aws_alb_listener" "front_end" {
146146

147147
### ECS
148148
resource "aws_ecs_cluster" "main" {
149-
name = "ecs-cluster"
149+
name = var.ecs_cluster_name
150150
}
File renamed without changes.

terraform/service.tf renamed to .github/actions/terraform/service.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ locals {
22
container_definitions = <<DEFINITION
33
[
44
{
5-
"cpu": var.cpu
6-
"image": var.image,
7-
"memory": var.memory,
5+
"cpu": ${var.cpu},
6+
"image": "${var.image}",
7+
"memory": ${var.memory},
88
"name": "app",
99
"networkMode": "awsvpc",
1010
"pseudoTerminal": true,
1111
"portMappings": [
1212
{
13-
"containerPort": var.port,
14-
"hostPort": var.port
13+
"containerPort": ${var.port},
14+
"hostPort": ${var.port}
1515
}
1616
]
1717
}
@@ -32,15 +32,15 @@ resource "aws_ecs_task_definition" "app" {
3232
}
3333

3434
resource "aws_ecs_service" "main" {
35-
name = "tf-ecs-service"
35+
name = var.service_name
3636
cluster = aws_ecs_cluster.main.id
3737
task_definition = aws_ecs_task_definition.app.arn
3838
desired_count = var.desired_count
3939
launch_type = "FARGATE"
4040

4141
network_configuration {
4242
security_groups = [aws_security_group.ecs_tasks.id]
43-
subnets = [aws_subnet.private.*.id]
43+
subnets = aws_subnet.private.*.id
4444
}
4545

4646
load_balancer {

terraform/variables.tf renamed to .github/actions/terraform/variables.tf

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ variable "az_count" {
1919

2020
variable "image" {
2121
description = "Docker image to run in the ECS cluster"
22+
default = "445220836204.dkr.ecr.eu-west-1.amazonaws.com/etdashboard:latest"
23+
2224
}
2325

2426
variable "port" {
2527
description = "Port exposed by the docker image to redirect traffic to"
28+
default = "3000"
2629
}
2730

2831
variable "desired_count" {
@@ -32,35 +35,46 @@ variable "desired_count" {
3235
}
3336

3437
variable "cpu" {
35-
type = number
3638
description = "Fargate instance CPU units to provision (1 vCPU = 1024 CPU units)"
37-
default = 256
39+
default = "256"
3840
}
3941

4042
variable "memory" {
41-
type = number
4243
description = "Fargate instance memory to provision (in MiB)"
43-
default = 512
44+
default = "512"
4445
}
4546

4647
variable "bucket" {
4748
default = "aws-github-actions"
4849
type = string
4950
}
5051

52+
variable "service_name" {
53+
type = string
54+
default = "terraform-et-dash"
55+
}
56+
57+
variable "alb_name" {
58+
type = string
59+
default = "et-dash-alb"
60+
}
61+
62+
variable "ecs_cluster_name" {
63+
type = string
64+
default = "terraform-et-dash"
65+
}
66+
5167
provider "aws" {
5268
version = ">= 1.47.0"
53-
access_key = var.access_key
54-
secret_key = var.secret_key
69+
access_key = var.aws_access_key_id
70+
secret_key = var.aws_secret_access_key
5571

5672
region = var.region
5773
}
5874

5975
terraform {
6076
backend "s3" {
6177
encrypt = true
62-
63-
# Path to write state to.
64-
key = "terraform.github.state/dashboard"
78+
key = "terraform.github.state/dashboard"
6579
}
6680
}

.github/main.workflow

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ action "Push" {
3737
}
3838

3939
action "Deploy to Fargate" {
40-
uses = "jessfraz/aws-fargate-action@master"
40+
uses = "./.github/actions"
4141
needs = ["Push"]
4242
env = {
4343
AWS_REGION = "eu-west-1"
44-
IMAGE = "445220836204.dkr.ecr.eu-west-1.amazonaws.com/etdashboard"
44+
IMAGE = "445220836204.dkr.ecr.eu-west-1.amazonaws.com/etdashboard:latest"
4545
PORT = "8081"
46-
COUNT = "2"
46+
COUNT = "1"
4747
CPU = "256"
4848
MEMORY = "512"
49-
BUCKET = "et-dash-actions"
49+
BUCKET = "et-dash-dev"
5050
}
5151
secrets = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"]
5252
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ RUN npm i --silent
1313

1414
COPY --chown=node:node . .
1515

16-
EXPOSE 8081
16+
EXPOSE 3000
1717

1818
CMD [ "npm", "start" ]

terraform/workspaces/production.tfvars

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)