Skip to content

Commit 72b0fed

Browse files
Merge pull request #11 from Developer-DAO/ecs-cd
ECS CD
2 parents 9bdc0e0 + cb067cb commit 72b0fed

File tree

7 files changed

+83
-61
lines changed

7 files changed

+83
-61
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DATABASE_URL=postgres://ddrpcdev:[email protected]:5432/ddrpc
22
SMTP_USERNAME=[email protected]
3-
SMTP_PASSWORD=test!
3+
SMTP_PASSWORD=test!!
44
ETHEREUM_ENDPOINT=http://host.docker.internal:8545
55
JWT_KEY=<JWT>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Deploy dd-rpc to ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- ecs-cd
9+
10+
jobs:
11+
build-and-deploy:
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: infra/opentofu/ecs
16+
env:
17+
AWS_REGION: us-east-2
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log in to GitHub Container Registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Build and push dd-rpc image
33+
uses: docker/build-push-action@v5
34+
with:
35+
context: .
36+
file: ./Dockerfile
37+
push: true
38+
tags: ghcr.io/developer-dao/rpc:${{ github.sha }}
39+
40+
- name: Set up Terraform
41+
uses: hashicorp/setup-terraform@v3
42+
with:
43+
terraform_version: 1.8.5
44+
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v4
47+
with:
48+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
49+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
50+
aws-region: ${{ env.AWS_REGION }}
51+
52+
- name: Terraform Init
53+
run: terraform init
54+
55+
- name: Terraform Plan
56+
run: terraform plan -var="rpc_image=ghcr.io/developer-dao/rpc:${{ github.sha }}"
57+
58+
- name: Terraform Apply
59+
run: terraform apply -auto-approve -var="rpc_image=ghcr.io/developer-dao/rpc:${{ github.sha }}"

.github/workflows/docker-build.yml

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

infra/opentofu/ecs/backend.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
terraform {
2-
# backend "s3" { # TODO: Migrate to S3 when AWS account and S3 bucket is set up
3-
# bucket = "dd-rpc-terraform-state"
4-
# key = "ecs/terraform.tfstate"
5-
# region = var.region
6-
# encrypt = true
7-
# }
8-
backend "local" {}
2+
backend "s3" {
3+
bucket = "dd-test-rpc-terraform-state"
4+
key = "ecs/terraform.tfstate"
5+
region = "us-east-2"
6+
encrypt = true
7+
}
98

109
required_version = ">= 1.0.0"
1110
required_providers {

infra/opentofu/ecs/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Reference VPC outputs from the vpc folder's state
22
# TODO: Migrate to S3 when AWS account and S3 bucket is set up
33
data "terraform_remote_state" "vpc" {
4-
backend = "local"
4+
backend = "s3"
55
config = {
6-
path = "../vpc/terraform.tfstate"
6+
bucket = "dd-test-rpc-terraform-state"
7+
key = "vpc/terraform.tfstate"
8+
region = "us-east-2"
79
}
810
}
911

@@ -85,7 +87,7 @@ module "ecs" {
8587
cpu = 512
8688
memory = 1024
8789
essential = true
88-
image = "ghcr.io/developer-dao/rpc:latest"
90+
image = var.rpc_image
8991
port_mappings = [
9092
{
9193
name = "dd-rpc"

infra/opentofu/ecs/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ variable "region" {
22
description = "The AWS region to deploy the VPC in."
33
default = "us-east-2"
44
type = string
5+
}
6+
7+
variable "rpc_image" {
8+
description = "The image tag or URI for the dd-rpc container."
9+
type = string
10+
default = "ghcr.io/developer-dao/rpc:latest"
511
}

infra/opentofu/vpc/backend.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
terraform {
2-
# backend "s3" { # TODO: Migrate to S3 when AWS account and S3 bucket is set up
3-
# bucket = "dd-rpc-terraform-state"
4-
# key = "vpc/terraform.tfstate"
5-
# region = var.region
6-
# encrypt = true
7-
# }
8-
backend "local" {}
2+
backend "s3" {
3+
bucket = "dd-test-rpc-terraform-state"
4+
key = "vpc/terraform.tfstate"
5+
region = "us-east-2"
6+
encrypt = true
7+
}
98

109
required_version = ">= 1.0.0"
1110
required_providers {

0 commit comments

Comments
 (0)