Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d245677
Adds compose file for the service
onlinejudge95 Jul 3, 2021
532f90b
Adds .ignore file for docker
onlinejudge95 Jul 3, 2021
6155be4
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
8047bba
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
c8a9e1f
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
52ae724
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
29f1c1e
Adds Dockerfile
onlinejudge95 Jul 3, 2021
2c59fa0
Adds Deepsource DSN for gambley_backend (#89)
onlinejudge95 Jul 7, 2021
e6ed985
Adds ecr repo for gambley_backend (#90)
onlinejudge95 Jul 7, 2021
e9abb3d
Adds Network layer for gambley (#91)
onlinejudge95 Jul 7, 2021
cabece5
Adds only VPC resource (#92)
onlinejudge95 Jul 7, 2021
4024cb7
Adds subnets (#93)
onlinejudge95 Jul 7, 2021
c0c7020
Adds elastic IPs (#94)
onlinejudge95 Jul 7, 2021
6161efc
Adds internet gateway and NAT gateway (#95)
onlinejudge95 Jul 7, 2021
c7d0a89
Removes resources that are not required (#97)
onlinejudge95 Jul 8, 2021
1442cf5
Adds EC2 instance for master node (#98)
onlinejudge95 Jul 8, 2021
7f87571
Adds security group for AWS (#100)
onlinejudge95 Jul 8, 2021
2e65cb8
Adds s3 bucket for all resources (#101)
onlinejudge95 Jul 9, 2021
d50e827
Adds IAM Instance profile to EC2 instance (#103)
onlinejudge95 Jul 9, 2021
0568a41
Adds instance policy to EC2 IAM Instance Profile (#104)
onlinejudge95 Jul 10, 2021
d1ab4b4
Adds user data script (#102)
onlinejudge95 Jul 10, 2021
2bc1e72
Fixes TF-AWS079 (#105)
onlinejudge95 Jul 10, 2021
7766a04
Adds secrets for deploying gambley_backend (#106)
onlinejudge95 Jul 10, 2021
963ff0f
Deprecates email_service from heroku (#107)
onlinejudge95 Jul 10, 2021
256a55a
Removes github repo for email_service (#108)
onlinejudge95 Jul 10, 2021
2ce4910
Removes ECR repo (#109)
onlinejudge95 Jul 10, 2021
7f2757e
Adds new secrets for gambley_backend (#110)
onlinejudge95 Jul 10, 2021
f4b3366
Adds security group rule for ec2 (#111)
onlinejudge95 Jul 12, 2021
e2cc71e
Adds security group rule for 443 port (#112)
onlinejudge95 Jul 12, 2021
8ddb1d5
Adds compose file for the service
onlinejudge95 Jul 3, 2021
f2c629a
Adds .ignore file for docker
onlinejudge95 Jul 3, 2021
2626cb2
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
abc803b
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
b33c00e
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
121373d
Updates ignore file for docker
onlinejudge95 Jul 3, 2021
f8b4269
Adds Dockerfile
onlinejudge95 Jul 3, 2021
981b115
Merge branch 'docker' of github.com:unofficialopensource-knit/infrast…
onlinejudge95 Jul 13, 2021
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
12 changes: 12 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.14.0

WORKDIR /app

RUN apk --no-cache add --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community terraform \
&& addgroup -S infrastructure && adduser -S infrastructure -G infrastructure

COPY --chown=infrastructure:infrastructure . .

RUN ls -lha

ENTRYPOINT [ "terraform" ]
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.docker/
.git/
.github/
.vscode/
src/aws/.terraform/
src/github/.terraform/
src/heroku/.terraform/

*.toml
.*ignore
.env*
*.yml
*.md
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ export TF_VAR_DOCKERHUB_USERNAME=xxxx
export TF_VAR_DOCKERHUB_TOKEN=xxxx
export TF_VAR_HEROKU_EMAIL=xxxx
export TF_VAR_HEROKU_API_KEY=xxxx
export TF_VAR_EMAIL_SERVICE_CODECOV_TOKEN=xxxx
export TF_VAR_API_GATEWAY_CODECOV_TOKEN=xxxx
export TF_VAR_EMAIL_SERVICE_DATABASE_URL=xxxx
export TF_VAR_EMAIL_SERVICE_MAIL_PASSWORD=xxxx
export TF_VAR_EMAIL_SERVICE_MAIL_USERNAME=xxxx
export TF_VAR_EMAIL_SERVICE_REDIS_TLS_URL=xxxx
export TF_VAR_EMAIL_SERVICE_REDIS_URL=xxxx
export TF_VAR_PROFILE_SERVICE_DATABASE_URL=xxxx
export TF_VAR_PROFILE_SERVICE_REDIS_TLS_URL=xxxx
export TF_VAR_PROFILE_SERVICE_REDIS_URL=xxxx
Expand All @@ -23,3 +17,9 @@ export TF_VAR_TRUSTED_HOSTS=xxxx
export TF_VAR_GAMBLEY_CD_USER_AWS_ACCESS_KEY=xxxx
export TF_VAR_GAMBLEY_CD_USER_AWS_SECRET_KEY=xxxx
export TF_VAR_SNYK_SECRET_KEY=xxxx
export TF_VAR_GAMBLEY_BACKEND_DEEPSOURCE_DSN=xxxx
export TF_VAR_GAMBLEY_BACKEND_MAIL_USERNAME=xxxx
export TF_VAR_GAMBLEY_BACKEND_MAIL_PASSWORD=xxxx
export TF_VAR_GAMBLEY_BACKEND_SUPPRESS_SEND=xxxx
export TF_VAR_GAMBLEY_BACKEND_SSH_USER=xxxx
export TF_VAR_GAMBLEY_BACKEND_SSH_HOST=xxxx
60 changes: 43 additions & 17 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ name: "Pipeline"

on:
pull_request:
branches: [ "main" ]
branches:
- main
push:
branches: [ "main" ]
branches:
- main

jobs:
test:
if: ${{ github.event_name == 'pull_request' }}
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-18.04"
steps:
- uses: actions/checkout@v2

Expand All @@ -28,6 +30,14 @@ jobs:
source scripts/pipeline_utils.sh
format_terraform github heroku aws

- name: "Adds directory for infra data"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
source scripts/pipeline_utils.sh
setup_data

- name: "Run validation to check for issues"
run: |
source scripts/pipeline_utils.sh
Expand All @@ -37,7 +47,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
needs:
- test
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-18.04"
steps:
- uses: actions/checkout@v2

Expand All @@ -51,6 +61,14 @@ jobs:
source scripts/pipeline_utils.sh
init_terraform github heroku aws

- name: "Adds directory for infra data"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
source scripts/pipeline_utils.sh
setup_data

- name: "Generate terraform plan"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -60,13 +78,7 @@ jobs:
TF_VAR_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
TF_VAR_HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
TF_VAR_HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
TF_VAR_EMAIL_SERVICE_CODECOV_TOKEN: ${{ secrets.EMAIL_SERVICE_CODECOV_TOKEN }}
TF_VAR_API_GATEWAY_CODECOV_TOKEN: ${{ secrets.API_GATEWAY_CODECOV_TOKEN }}
TF_VAR_EMAIL_SERVICE_DATABASE_URL: ${{ secrets.EMAIL_SERVICE_DATABASE_URL }}
TF_VAR_EMAIL_SERVICE_MAIL_PASSWORD: ${{ secrets.EMAIL_SERVICE_MAIL_PASSWORD }}
TF_VAR_EMAIL_SERVICE_MAIL_USERNAME: ${{ secrets.EMAIL_SERVICE_MAIL_USERNAME }}
TF_VAR_EMAIL_SERVICE_REDIS_TLS_URL: ${{ secrets.EMAIL_SERVICE_REDIS_TLS_URL }}
TF_VAR_EMAIL_SERVICE_REDIS_URL: ${{ secrets.EMAIL_SERVICE_REDIS_URL }}
TF_VAR_PROFILE_SERVICE_DATABASE_URL: ${{ secrets.PROFILE_SERVICE_DATABASE_URL }}
TF_VAR_PROFILE_SERVICE_REDIS_TLS_URL: ${{ secrets.PROFILE_SERVICE_REDIS_TLS_URL }}
TF_VAR_PROFILE_SERVICE_REDIS_URL: ${{ secrets.PROFILE_SERVICE_REDIS_URL }}
Expand All @@ -80,13 +92,19 @@ jobs:
TF_VAR_GAMBLEY_CD_USER_AWS_ACCESS_KEY: ${{ secrets.GAMBLEY_CD_USER_AWS_ACCESS_KEY }}
TF_VAR_GAMBLEY_CD_USER_AWS_SECRET_KEY: ${{ secrets.GAMBLEY_CD_USER_AWS_SECRET_KEY }}
TF_VAR_SNYK_SECRET_KEY: ${{ secrets.SNYK_SECRET_KEY }}
TF_VAR_GAMBLEY_BACKEND_DEEPSOURCE_DSN: ${{ secrets.GAMBLEY_BACKEND_DEEPSOURCE_DSN }}
TF_VAR_GAMBLEY_BACKEND_MAIL_USERNAME: ${{ secrets.GAMBLEY_BACKEND_MAIL_USERNAME }}
TF_VAR_GAMBLEY_BACKEND_MAIL_PASSWORD: ${{ secrets.GAMBLEY_BACKEND_MAIL_PASSWORD }}
TF_VAR_GAMBLEY_BACKEND_SUPPRESS_SEND: ${{ secrets.GAMBLEY_BACKEND_SUPPRESS_SEND }}
TF_VAR_GAMBLEY_BACKEND_SSH_USER: ${{ secrets.GAMBLEY_BACKEND_SSH_USER }}
TF_VAR_GAMBLEY_BACKEND_SSH_HOST: ${{ secrets.GAMBLEY_BACKEND_SSH_HOST }}
run: |
source scripts/pipeline_utils.sh
plan_terraform github heroku aws

deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-18.04"
steps:
- uses: actions/checkout@v2

Expand All @@ -100,6 +118,14 @@ jobs:
source scripts/pipeline_utils.sh
init_terraform github heroku aws

- name: "Adds directory for infra data"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
source scripts/pipeline_utils.sh
setup_data

- name: "Apply terraform plan"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -109,13 +135,7 @@ jobs:
TF_VAR_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
TF_VAR_HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
TF_VAR_HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
TF_VAR_EMAIL_SERVICE_CODECOV_TOKEN: ${{ secrets.EMAIL_SERVICE_CODECOV_TOKEN }}
TF_VAR_API_GATEWAY_CODECOV_TOKEN: ${{ secrets.API_GATEWAY_CODECOV_TOKEN }}
TF_VAR_EMAIL_SERVICE_DATABASE_URL: ${{ secrets.EMAIL_SERVICE_DATABASE_URL }}
TF_VAR_EMAIL_SERVICE_MAIL_PASSWORD: ${{ secrets.EMAIL_SERVICE_MAIL_PASSWORD }}
TF_VAR_EMAIL_SERVICE_MAIL_USERNAME: ${{ secrets.EMAIL_SERVICE_MAIL_USERNAME }}
TF_VAR_EMAIL_SERVICE_REDIS_TLS_URL: ${{ secrets.EMAIL_SERVICE_REDIS_TLS_URL }}
TF_VAR_EMAIL_SERVICE_REDIS_URL: ${{ secrets.EMAIL_SERVICE_REDIS_URL }}
TF_VAR_PROFILE_SERVICE_DATABASE_URL: ${{ secrets.PROFILE_SERVICE_DATABASE_URL }}
TF_VAR_PROFILE_SERVICE_REDIS_TLS_URL: ${{ secrets.PROFILE_SERVICE_REDIS_TLS_URL }}
TF_VAR_PROFILE_SERVICE_REDIS_URL: ${{ secrets.PROFILE_SERVICE_REDIS_URL }}
Expand All @@ -129,6 +149,12 @@ jobs:
TF_VAR_GAMBLEY_CD_USER_AWS_ACCESS_KEY: ${{ secrets.GAMBLEY_CD_USER_AWS_ACCESS_KEY }}
TF_VAR_GAMBLEY_CD_USER_AWS_SECRET_KEY: ${{ secrets.GAMBLEY_CD_USER_AWS_SECRET_KEY }}
TF_VAR_SNYK_SECRET_KEY: ${{ secrets.SNYK_SECRET_KEY }}
TF_VAR_GAMBLEY_BACKEND_DEEPSOURCE_DSN: ${{ secrets.GAMBLEY_BACKEND_DEEPSOURCE_DSN }}
TF_VAR_GAMBLEY_BACKEND_MAIL_USERNAME: ${{ secrets.GAMBLEY_BACKEND_MAIL_USERNAME }}
TF_VAR_GAMBLEY_BACKEND_MAIL_PASSWORD: ${{ secrets.GAMBLEY_BACKEND_MAIL_PASSWORD }}
TF_VAR_GAMBLEY_BACKEND_SUPPRESS_SEND: ${{ secrets.GAMBLEY_BACKEND_SUPPRESS_SEND }}
TF_VAR_GAMBLEY_BACKEND_SSH_USER: ${{ secrets.GAMBLEY_BACKEND_SSH_USER }}
TF_VAR_GAMBLEY_BACKEND_SSH_HOST: ${{ secrets.GAMBLEY_BACKEND_SSH_HOST }}
run: |
source scripts/pipeline_utils.sh
apply_terraform github heroku aws
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.terraform/
.vscode/
data/

.env
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.8"


networks:
infrastructure:
name: infrastructure


services:
infrastructure:
image: infrastructure:development
build:
context: .
dockerfile: .docker/Dockerfile
networks:
- infrastructure
volumes:
- .:/usr/src/app
15 changes: 15 additions & 0 deletions scripts/pipeline_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ apply_terraform() {
terraform -chdir="src/$i" apply -auto-approve -input=false
done
}

setup_data() {
echo "Created data directory"
mkdir -p src/aws/data
cd src/aws/data

echo "Copying test data to data directory"
aws s3 cp s3://gambley-infra-data/public_keys/id_gambley.pub .
echo "Copying IAM Role Policy to data directory"
aws s3 cp s3://gambley-infra-data/iam/iam_role_policy.json .
echo "Copying IAM Role Instance Policy to data directory"
aws s3 cp s3://gambley-infra-data/iam/iam_role_instance_policy.json .
echo "Copying user data script data directory"
aws s3 cp s3://gambley-infra-data/user_data/user_data.sh .
}
4 changes: 2 additions & 2 deletions src/aws/container_registry.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ resource "aws_ecr_repository" "auth_service" {
}
}

resource "aws_ecr_repository" "email_service" {
name = "email_service"
resource "aws_ecr_repository" "gambley_backend" {
name = "gambley_backend"
encryption_configuration {
encryption_type = "AES256"
}
Expand Down
7 changes: 7 additions & 0 deletions src/aws/elastic_ip.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_eip" "gambley_node1_eip" {
instance = aws_instance.gambley_swarm_master.id
tags = {
"Name" = "Gambley Node1 Elastic IP"
"Terraform" = "True"
}
}
21 changes: 21 additions & 0 deletions src/aws/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "aws_iam_role" "gambley_instance_role" {
name = "gambley-instance-role"
assume_role_policy = file("${path.module}/data/iam_role_policy.json")
tags = {
"Terraform" = "True"
}
}

resource "aws_iam_instance_profile" "gambley_iam_instance_profile" {
name = "gambley-iam-profile"
role = aws_iam_role.gambley_instance_role.name
tags = {
"Terraform" = "True"
}
}

resource "aws_iam_role_policy" "gambley_iam_instance_policy" {
name = "gambley-iam-instance-policy"
role = aws_iam_role.gambley_instance_role.id
policy = file("${path.module}/data/iam_role_instance_policy.json")
}
6 changes: 3 additions & 3 deletions src/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ provider "aws" {

terraform {
backend "s3" {
bucket = "aws-state-bucket"
key = "terraform.tfstate"
bucket = "terraform-gambley-state-bucket"
key = "aws/terraform.tfstate"
region = "ap-south-1"
dynamodb_table = "aws-lock-table"
dynamodb_table = "terraform-gambley-lock-table"
encrypt = true
}
required_providers {
Expand Down
58 changes: 58 additions & 0 deletions src/aws/virtual_machine.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
resource "aws_instance" "gambley_swarm_master" {
ami = "ami-0c1a7f89451184c8b"
instance_type = "t3a.small"
key_name = aws_key_pair.gambley_ssh_key.key_name
associate_public_ip_address = true
user_data = file("${path.module}/data/user_data.sh")
security_groups = [aws_security_group.gambley_security_group.name]
iam_instance_profile = aws_iam_instance_profile.gambley_iam_instance_profile.name
metadata_options {
http_tokens = "required"
}
tags = {
"Name" = "Gambley Node1"
"Terraform" = "True"
}
}

resource "aws_key_pair" "gambley_ssh_key" {
key_name = "Gambley SSH Key"
public_key = file("${path.module}/data/id_gambley.pub")
}

resource "aws_security_group" "gambley_security_group" {
name = "Gambley Security group"
description = "Security group for gambley host"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0"
]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0"
]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0"
]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0"
]
}
}
42 changes: 36 additions & 6 deletions src/github/github_actions_secret.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
resource "github_actions_secret" "email_service_codecov_token" {
repository = github_repository.email_service.name
secret_name = "CODECOV_TOKEN"
plaintext_value = var.EMAIL_SERVICE_CODECOV_TOKEN
}

resource "github_actions_secret" "api_gateway_codecov_token" {
repository = github_repository.api_gateway.name
secret_name = "CODECOV_TOKEN"
plaintext_value = var.API_GATEWAY_CODECOV_TOKEN
}

resource "github_actions_secret" "gambley_backend_deepsource_dsn" {
repository = github_repository.gambley_backend.name
secret_name = "DEEPSOURCE_DSN"
plaintext_value = var.GAMBLEY_BACKEND_DEEPSOURCE_DSN
}

resource "github_actions_secret" "gambley_backend_mail_username" {
repository = github_repository.gambley_backend.name
secret_name = "MAIL_USERNAME"
plaintext_value = var.GAMBLEY_BACKEND_MAIL_USERNAME
}

resource "github_actions_secret" "gambley_backend_mail_password" {
repository = github_repository.gambley_backend.name
secret_name = "MAIL_PASSWORD"
plaintext_value = var.GAMBLEY_BACKEND_MAIL_PASSWORD
}

resource "github_actions_secret" "gambley_backend_supress_send" {
repository = github_repository.gambley_backend.name
secret_name = "SUPPRESS_SEND"
plaintext_value = var.GAMBLEY_BACKEND_SUPPRESS_SEND
}

resource "github_actions_secret" "gambley_backend_ssh_user" {
repository = github_repository.gambley_backend.name
secret_name = "SSH_USER"
plaintext_value = var.GAMBLEY_BACKEND_SSH_USER
}

resource "github_actions_secret" "gambley_backend_ssh_host" {
repository = github_repository.gambley_backend.name
secret_name = "SSH_HOST"
plaintext_value = var.GAMBLEY_BACKEND_SSH_HOST
}
Loading