diff --git a/.env.example b/.env.example index 5a8e916..80ee8da 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ DATABASE_URL=postgres://ddrpcdev:ddrpc123@host.docker.internal:5432/ddrpc SMTP_USERNAME=test@asdlfknason.com -SMTP_PASSWORD=test! +SMTP_PASSWORD=test!! ETHEREUM_ENDPOINT=http://host.docker.internal:8545 JWT_KEY= diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..8f2315c --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,59 @@ +name: Build and Deploy dd-rpc to ECS + +on: + push: + branches: + - main + - dev + - ecs-cd + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + defaults: + run: + working-directory: infra/opentofu/ecs + env: + AWS_REGION: us-east-2 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push dd-rpc image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/developer-dao/rpc:${{ github.sha }} + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.8.5 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Terraform Init + run: terraform init + + - name: Terraform Plan + run: terraform plan -var="rpc_image=ghcr.io/developer-dao/rpc:${{ github.sha }}" + + - name: Terraform Apply + run: terraform apply -auto-approve -var="rpc_image=ghcr.io/developer-dao/rpc:${{ github.sha }}" diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml deleted file mode 100644 index 094a58b..0000000 --- a/.github/workflows/docker-build.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: docker-build-test - -on: - push: - branches: - - "**" - -jobs: - docker: - runs-on: ubuntu-latest - permissions: - packages: write - steps: - - - name: Login to Github Container Registry - uses: docker/login-action@v3 - with: - registry: https://ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Determine Docker tags - id: vars - run: | - if [ "${{ github.ref }}" == "refs/heads/main" ]; then - echo "TAGS=ghcr.io/developer-dao/rpc:latest,ghcr.io/developer-dao/rpc:${{ github.sha }}" >> $GITHUB_ENV - else - BRANCH_NAME=$(echo "${{ github.ref }}" | sed 's|refs/heads/||' | tr '/' '-' | tr '[:upper:]' '[:lower:]') - echo "TAGS=ghcr.io/developer-dao/rpc:${BRANCH_NAME}-${{ github.sha }}" >> $GITHUB_ENV - fi - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - load: false - tags: ${{ env.TAGS }} \ No newline at end of file diff --git a/infra/opentofu/ecs/backend.tf b/infra/opentofu/ecs/backend.tf index c98f272..4bfcf4c 100644 --- a/infra/opentofu/ecs/backend.tf +++ b/infra/opentofu/ecs/backend.tf @@ -1,11 +1,10 @@ terraform { - # backend "s3" { # TODO: Migrate to S3 when AWS account and S3 bucket is set up - # bucket = "dd-rpc-terraform-state" - # key = "ecs/terraform.tfstate" - # region = var.region - # encrypt = true - # } - backend "local" {} + backend "s3" { + bucket = "dd-test-rpc-terraform-state" + key = "ecs/terraform.tfstate" + region = "us-east-2" + encrypt = true + } required_version = ">= 1.0.0" required_providers { diff --git a/infra/opentofu/ecs/main.tf b/infra/opentofu/ecs/main.tf index 975d710..9c85030 100644 --- a/infra/opentofu/ecs/main.tf +++ b/infra/opentofu/ecs/main.tf @@ -1,9 +1,11 @@ # Reference VPC outputs from the vpc folder's state # TODO: Migrate to S3 when AWS account and S3 bucket is set up data "terraform_remote_state" "vpc" { - backend = "local" + backend = "s3" config = { - path = "../vpc/terraform.tfstate" + bucket = "dd-test-rpc-terraform-state" + key = "vpc/terraform.tfstate" + region = "us-east-2" } } @@ -85,7 +87,7 @@ module "ecs" { cpu = 512 memory = 1024 essential = true - image = "ghcr.io/developer-dao/rpc:latest" + image = var.rpc_image port_mappings = [ { name = "dd-rpc" diff --git a/infra/opentofu/ecs/variables.tf b/infra/opentofu/ecs/variables.tf index deece27..a12a40b 100644 --- a/infra/opentofu/ecs/variables.tf +++ b/infra/opentofu/ecs/variables.tf @@ -2,4 +2,10 @@ variable "region" { description = "The AWS region to deploy the VPC in." default = "us-east-2" type = string +} + +variable "rpc_image" { + description = "The image tag or URI for the dd-rpc container." + type = string + default = "ghcr.io/developer-dao/rpc:latest" } \ No newline at end of file diff --git a/infra/opentofu/vpc/backend.tf b/infra/opentofu/vpc/backend.tf index ab90e58..fc025a0 100644 --- a/infra/opentofu/vpc/backend.tf +++ b/infra/opentofu/vpc/backend.tf @@ -1,11 +1,10 @@ terraform { - # backend "s3" { # TODO: Migrate to S3 when AWS account and S3 bucket is set up - # bucket = "dd-rpc-terraform-state" - # key = "vpc/terraform.tfstate" - # region = var.region - # encrypt = true - # } - backend "local" {} + backend "s3" { + bucket = "dd-test-rpc-terraform-state" + key = "vpc/terraform.tfstate" + region = "us-east-2" + encrypt = true + } required_version = ">= 1.0.0" required_providers {