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

Dev #3

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy to Amazon ECR

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
name: Build and Push Docker Images
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registry: 'aws-account-id.dkr.ecr.us-east-1.amazonaws.com'
region: 'us-east-1'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
AWS_REGION: us-east-1

- name: Build and Push Application Docker Image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: application
IMAGE_TAG: v1.0
run: |
cd app
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Build and Push Database Docker Image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: database
IMAGE_TAG: v1.0
run: |
cd db
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def index() -> str:


if __name__ == '__main__':
app.run(host='0.0.0.0')
app.run(host='0.0.0.0', port=5000, debug=True)
8 changes: 8 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Use an official MySQL runtime as a parent image
FROM mysql:latest

# Set the working directory to /app
COPY ./init.sql /tmp

# Copy the SQL script to create the database and table into the container
CMD [ "mysqld", "--init-file=/tmp/init.sql" ]
4 changes: 4 additions & 0 deletions terraform/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//Terraform deployment codes
provider "aws" {
region = "us-east-1"
}
27 changes: 27 additions & 0 deletions terraform/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAo/RNx83nVpV4o+EF2ESg5MGE/40PUyKg7Z045CZOn3+kXfYO
XhPiLtWZImz9SuioJIdqOBK6XGFd06tgw/BMGItPQYjuvJVoHJS4XwTHClMc2ljX
PJUi2dHrb7LY5KzkXj6/fg9CHCxfWEM+ipyTo4QisrcS3pB2MgdnpMzS1m1rMoeH
Ei+QuNYbyH/mMxMpNHsnS8Pq0W59r3W9U4Lt5NLoEsN9GpZ8sF54hsqZN/4OTdC2
U0CAmsbmvVjYNufSOM+Z8Q2oQvtEblSEcGgqEF/nh5jA+qydNcqPR+aaLx9arQfN
MP9gTobtMophbQA3ZmSYjjVLmfejHAhrIG5zzwIDAQABAoIBABbF5VPebsahBlvE
8rnidnKvyphwcHN8uNuoXfGavIr9AMioV8CLhHw64QVeHCSeglRolsFpIIeaYpz3
Df7JTtiN6RlSOs7o9cgahC12jWsKtlRByMu6b1fQB6LBNc01kpbgolqRJf6hzzCE
TpiUPRGWVfd65F0TtccnLic+5/4uhaLSOfecS1jGxbFVGQ0eziXiOYqZz69YsnWd
cCSu4M0Vgivfn9WH1PS4XAqcCWO2htU2K05e5DBhBu+0oC+ErXESg7X1U5PjwVrW
zqGXhkNlJTMihM+7WRqey/9urvLzJCYfQRwezNpcLnPh5REemD1WiYlt3be5e1NA
beOZUkkCgYEA1TLNJeKIrg0Eghcx/bls0AULD6qNZ02kq7c6BiOTBau7NRWmbwPO
1YHwRqr1rEA4xYtP41PuQeIhGL5DwOFh4yKqyp01pFku3+PktlQezCl8Hvsa7hUs
y36Swy4+Eg9rZA0111Ktp7wJLm4XmgLZTPVPAM4hRAh2V76zqL63I+sCgYEAxN6h
saZEAfEGbfWB7JMwbDupJB7+0qzrxQZE8lNe+k6RzOD/JAxiSRiDmk6R2nEtob89
rlai6bopBA45g1IfyzWHo4b/bZeHy3sa+WFEVkE8dyBBawEq3Y5jARrZM4NlIgnG
VtpM20VgyL/FLfo0mfTt6lG2vibbyqB3dWjMCq0CgYEAlO4g+ucNnbBARvQXGuvu
BD6RpIb6soA9mSqsoN829A4r/4A5PHHHicR0aZlBduuB/RU9YEsgM+vYPOWkhNes
vrNX5aP+delK4mHbQjbvMKWGLEozXL90BE9ODISAHbOhzEmiI+GAp5ymOUX0vMRi
seznHGPiPxk+OjtgW2+mlbMCgYAVp8uvh/OJJyMm60+cX2B/N1zWrVYohH720Ea7
RTJ4ZDYjjEhkhbw2AC1RxvzCQ5raZPf6+mq3PRQP7ySibmEy8DN4aHwmaPm2B1ej
QPDMcCafj/vCMoGtl2EKmRJ1WSnBwcOAgEjeAdawnm+pLBGnMcsN8Gkip5Gby2T4
lEuFjQKBgErZuKLPq0zCkUNKgVpDVWlYMpz+BlKUDtfrVG8NM3Aca/cSrdi2Emxw
bjsf9NbhLlHAiqbwtPSJIuiKCmzF7WRU97mwM+om8CyLN6oHsVoXp/Ap06mWIooi
tiEf0u4LKF2KQGsgZ2C7JynVAkGSzLUWvsqAeqMeQqAj1pQKs4Y5
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions terraform/docker.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCj9E3HzedWlXij4QXYRKDkwYT/jQ9TIqDtnTjkJk6ff6Rd9g5eE+Iu1ZkibP1K6Kgkh2o4ErpcYV3Tq2DD8EwYi09BiO68lWgclLhfBMcKUxzaWNc8lSLZ0etvstjkrORePr9+D0IcLF9YQz6KnJOjhCKytxLekHYyB2ekzNLWbWsyh4cSL5C41hvIf+YzEyk0eydLw+rRbn2vdb1Tgu3k0ugSw30alnywXniGypk3/g5N0LZTQICaxua9WNg259I4z5nxDahC+0RuVIRwaCoQX+eHmMD6rJ01yo9H5povH1qtB80w/2BOhu0yimFtADdmZJiONUuZ96McCGsgbnPP [email protected]
26 changes: 26 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
data "aws_ami" "latestLinuxAMI" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}

resource "aws_instance" "ec2" {
ami = data.aws_ami.latestLinuxAMI.id
instance_type = "t2.micro"
subnet_id = aws_subnet.this.id
iam_instance_profile = "LabInstanceProfile"
security_groups = [aws_security_group.docker_sg.id]
key_name = "docker"
}


resource "aws_ecr_repository" "database" {
name = "database"
}

resource "aws_ecr_repository" "application" {
name = "application"
}
13 changes: 13 additions & 0 deletions terraform/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data "aws_vpc" "default" {
default = true
}

resource "aws_subnet" "this" {
vpc_id = data.aws_vpc.default.id
cidr_block = "172.31.128.0/20"
map_public_ip_on_launch = true

tags = {
Name = "Public Subnet"
}
}
41 changes: 41 additions & 0 deletions terraform/securitygroup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "aws_security_group" "docker_sg" {
name = "docker_security_group"
description = "Security group for Docker Compose app"
vpc_id = data.aws_vpc.default.id

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5001
to_port = 5001
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5002
to_port = 5002
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5003
to_port = 5003
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Terraform = "true"
Environment = "dev"
}
}
Loading