Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Create Infrastructure and deployment for Service using Terraform (#25)
Browse files Browse the repository at this point in the history
Terraform code for all the infrastructure to run and deploy the Service
  • Loading branch information
FinnIckler authored May 9, 2023
1 parent 65c06d0 commit 0c39e9d
Show file tree
Hide file tree
Showing 15 changed files with 1,248 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy
on:
push:
branches: main
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_CD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_CD_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and push images
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/wca-registration:latest
cache-from: type=gha
cache-to: type=gha,mode=max
7 changes: 4 additions & 3 deletions docker-compose.yml → docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
wca_registration:
build:
context: .
dockerfile: dockerfile.dev
ports:
- "3001:3000"
environment:
Expand All @@ -17,12 +18,12 @@ services:
bash -c 'bundle install && yarn install &&
bin/rails server -b 0.0.0.0'
networks:
- wca-main
- wca-registration

volumes:
gems_volume:
driver: local

networks:
wca-main:
name: wca-main
wca-registration:
name: wca-registration
4 changes: 4 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ RUN apt-get update && apt-get install -y \


RUN gem update --system && gem install bundler
COPY . .
RUN bundle install && yarn install

CMD ["bin/rails", "server", "-b","0.0.0.0"]
25 changes: 25 additions & 0 deletions dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ruby:3.2.2
EXPOSE 3000

ENV DEBIAN_FRONTEND noninteractive
WORKDIR /app

# Add PPA needed to install nodejs.
# From: https://github.com/nodesource/distributions
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -

# Add PPA needed to install yarn.
# From: https://yarnpkg.com/en/docs/install#debian-stable
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y \
yarn \
build-essential \
nodejs \
libssl-dev \
libyaml-dev \
tzdata


RUN gem update --system && gem install bundler
3 changes: 3 additions & 0 deletions infra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.terraform/
*.tfvars
.terraform.lock.hcl
34 changes: 34 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Infrastructure

The infrastructure for running the WCA Registration Service.

## Setup

First, install terraform and initialize with:

```
terraform init
terraform workspace select prod || terraform workspace new prod
```

To apply changes run:

```
terraform apply
```

## Details

The WCA Registration System runs on a single Docker container

### App

We use ECS to run the app container(s). Currently the service runs on one t3.small instance which can house up to two containers

### Deployment

To automate deployment we use a CodePipeline that is triggered by pushing a new app image to ECR. The pipeline:

1. Sources the new ECR image arn.
2. Prepares files necessary for CodeDeploy (`appspec.yaml`, `taskdef.json`)
3. Triggers CodeDeploy to do Blue/Green deployment.
Loading

0 comments on commit 0c39e9d

Please sign in to comment.