Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/groups jams buildout #29

Merged
merged 9 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# STAGE 1: Building the base image.
################################################
FROM node:20-bookworm AS setup
FROM node:20-alpine3.19 AS setup

WORKDIR /app

Expand All @@ -11,24 +11,25 @@ COPY ./jest.config.ts ./jest.config.ts


ARG NODE_ENV=production
ENV NODE_ENV=NODE_ENV

USER root

RUN npm install -g npm && \
npm install -g typescript && \
npm install -g rimraf && \
npm install
npm ci


# STAGE 2: Building the project.
################################################
# # STAGE 2: Building the project.
# ################################################
FROM setup as build

COPY ./src ./src
WORKDIR /app
COPY ./src /app/src

RUN npm run build

EXPOSE 8000
EXPOSE 80
VOLUME ["/app/src"]

CMD ["npm", "start"]
29 changes: 29 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Development Image
################################################
FROM node:20-bookworm

WORKDIR /app

COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json
COPY ./tsconfig.json ./tsconfig.json
COPY ./jest.config.ts ./jest.config.ts


ARG NODE_ENV=development

USER root

RUN npm install -g npm && \
npm install -g typescript && \
npm install -g rimraf && \
npm install

COPY ./src /app/src

RUN npm run build

EXPOSE 8000
VOLUME ["/app/src"]

CMD ["npm", "start"]
4 changes: 4 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ docker-compose -f deploy/docker-compose.yml run --rm terraform init \
-backend-config="bucket=${S3_BUCKET}" \
-backend-config="key=${S3_BUCKET}.tfstate"
```

### Setup Keypair


1 change: 1 addition & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
volumes:
- .:/infra
working_dir: /infra
# env_file: .env
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
Expand Down
58 changes: 46 additions & 12 deletions deploy/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ is the easiest resource to create in AWS, and will only need:
- EC2 Instance
- Script template (optional, but helps with organization)
*/
###################################################
# SETUP SCRIPT - Configure EC2 Server for Project #
###################################################
##########################################
# EC2 INSTANCE - Host Server Application #
##########################################
data "aws_ami" "amzn_linux_2" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn2-ami-kernel-5.10-hvm-2.*"]
values = ["al2023-ami-2023.3.*-kernel-6.1-x86_64"]
}

filter {
Expand All @@ -24,19 +24,53 @@ data "aws_ami" "amzn_linux_2" {
}
}


resource "aws_instance" "jukebox_server" {
ami = data.aws_ami.amzn_linux_2.id
instance_type = "t3.micro"
user_data = file("./templates/ec2/server-setup.sh")
ami = data.aws_ami.amzn_linux_2.id
instance_type = "t3.micro"
user_data = file("./templates/ec2/server-setup.sh")
key_name = var.ssh_key_name
subnet_id = aws_subnet.public_a.id
user_data_replace_on_change = true

vpc_security_group_ids = [
aws_security_group.jukebox_server.id
]


tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-server" })
)
}

##########################################
# EC2 INSTANCE - Host Server Application #
##########################################
# TODO: Create ec2 instance with Amazon Linux 2 ami
# TODO: connect script

resource "aws_security_group" "jukebox_server" {
description = "Control server inbound and outbound access."
name = "${local.prefix}-server"
vpc_id = aws_vpc.main.id

ingress {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}

egress {
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
}

egress {
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}

tags = local.common_tags
}

192 changes: 189 additions & 3 deletions deploy/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,200 @@ The network configuration will include the following aws resources:
#################################################
# VPC - Contains Isolated Network Configuration #
#################################################
# TODO: Create vpc
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-vpc" })
)
}

resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-main" })
)
}



#####################################################
# Public Subnets - Inbound/Outbound Internet Access #
#####################################################
# TODO: Create public subnets
## Subnet A ######################
resource "aws_subnet" "public_a" {
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
vpc_id = aws_vpc.main.id
availability_zone = "${data.aws_region.current.name}a"

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-a" })
)
}

resource "aws_route_table" "public_a" {
vpc_id = aws_vpc.main.id

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-a" })
)
}

resource "aws_route_table_association" "public_a" {
subnet_id = aws_subnet.public_a.id
route_table_id = aws_route_table.public_a.id
}

resource "aws_route" "public_internet_access_a" {
route_table_id = aws_route_table.public_a.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}

resource "aws_eip" "public_a" {
domain = "vpc"

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-a" })
)
}

resource "aws_nat_gateway" "public_a" {
allocation_id = aws_eip.public_a.id
subnet_id = aws_subnet.public_a.id

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-a" })
)
}

## Subnet B ######################
resource "aws_subnet" "public_b" {
cidr_block = "10.0.2.0/24"
map_public_ip_on_launch = true
vpc_id = aws_vpc.main.id
availability_zone = "${data.aws_region.current.name}b"

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-b" })
)
}

resource "aws_route_table" "public_b" {
vpc_id = aws_vpc.main.id

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-b" })
)
}

resource "aws_route_table_association" "public_b" {
subnet_id = aws_subnet.public_b.id
route_table_id = aws_route_table.public_b.id
}

resource "aws_route" "public_internet_access_b" {
route_table_id = aws_route_table.public_b.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}

resource "aws_eip" "public_b" {
domain = "vpc"

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-b" })
)
}

resource "aws_nat_gateway" "public_b" {
allocation_id = aws_eip.public_b.id
subnet_id = aws_subnet.public_b.id

tags = merge(
local.common_tags,
tomap({ Name = "${local.prefix}-public-b" })
)
}


####################################################
# Private Subnets - Outbound internet access ounly #
####################################################
# TODO: Create private subnets
## Private A ######################
# resource "aws_subnet" "private_a" {
# cidr_block = "10.0.10.0/24"
# vpc_id = aws_vpc.main.id
# availability_zone = "${data.aws_region.current.name}a"

# tags = merge(
# local.common_tags,
# tomap({ Name = "${local.prefix}-private-a" })
# )
# }

# resource "aws_route_table" "private_a" {
# vpc_id = aws_vpc.main.id

# tags = merge(
# local.common_tags,
# tomap({ Name = "${local.prefix}-private-a" })
# )
# }

# resource "aws_route_table_association" "private_a" {
# subnet_id = aws_subnet.private_a.id
# route_table_id = aws_route_table.private_a.id
# }

# resource "aws_route" "private_a_internet_out" {
# route_table_id = aws_route_table.private_a.id
# nat_gateway_id = aws_nat_gateway.public_a.id
# destination_cidr_block = "0.0.0.0/0"
# }

# ## Private B ######################
# resource "aws_subnet" "private_b" {
# cidr_block = "10.0.11.0/24"
# vpc_id = aws_vpc.main.id
# availability_zone = "${data.aws_region.current.name}b"

# tags = merge(
# local.common_tags,
# tomap({ Name = "${local.prefix}-private-b" })
# )
# }

# resource "aws_route_table" "private_b" {
# vpc_id = aws_vpc.main.id

# tags = merge(
# local.common_tags,
# tomap({ Name = "${local.prefix}-private-b" })
# )
# }

# resource "aws_route_table_association" "private_b" {
# subnet_id = aws_subnet.private_b.id
# route_table_id = aws_route_table.private_b.id
# }

# resource "aws_route" "private_b_internet_out" {
# route_table_id = aws_route_table.private_b.id
# nat_gateway_id = aws_nat_gateway.public_b.id
# destination_cidr_block = "0.0.0.0/0"
# }

3 changes: 3 additions & 0 deletions deploy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "server_host" {
value = aws_instance.jukebox_server.public_dns
}
Loading