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

Bader sabbah patch 4 #22

Open
wants to merge 24 commits into
base: main
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
44 changes: 44 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy to ECR phase1

on:
push:
branches:
- main

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
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
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: webapp
IMAGE_TAG: latest
run: |
ls -ltra # List files for debugging
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Build and Push SQL
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: mysql
IMAGE_TAG: latest
run: |
ls -ltra # List files for debugging
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile_mysql .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8080
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
CMD [ "app.py" ]
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def FetchData():
output["primary_skills"] = result[3]
output["location"] = result[4]

except Exception as e:
except Exception as e:
print(e)

finally:
Expand Down Expand Up @@ -133,4 +133,4 @@ def FetchData():
print("Color not supported. Received '" + COLOR + "' expected one of " + SUPPORTED_COLORS)
exit(1)

app.run(host='0.0.0.0',port=8080,debug=True)
app.run(host='0.0.0.0',port=8080,debug=True)
6 changes: 6 additions & 0 deletions mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# mysql/Dockerfile
FROM mysql:5.7
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_DATABASE=mydb
COPY schema.sql /docker-entrypoint-initdb.d/

3 changes: 3 additions & 0 deletions mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- mysql/schema.sql
CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255));

20 changes: 20 additions & 0 deletions terraform_code/dev/instances/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
120 changes: 120 additions & 0 deletions terraform_code/dev/instances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@


#----------------------------------------------------------
# ACS730 - Week 3 - Terraform Introduction
#
# Build EC2 Instances
#
#----------------------------------------------------------

# Define the provider
provider "aws" {
region = "us-east-1"
}

# Data source for AMI id
data "aws_ami" "latest_amazon_linux" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}


# Data source for availability zones in us-east-1
data "aws_availability_zones" "available" {
state = "available"
}

# Data block to retrieve the default VPC id
data "aws_vpc" "default" {
default = true
}

# Define tags locally
locals {
default_tags = merge(module.globalvars.default_tags, { "env" = var.env })
prefix = module.globalvars.prefix
name_prefix = "${local.prefix}-${var.env}"
}

# Retrieve global variables from the Terraform module
module "globalvars" {
source = "../../modules/globalvars"
}

# Reference subnet provisioned by 01-Networking
resource "aws_instance" "my_amazon" {
ami = data.aws_ami.latest_amazon_linux.id
instance_type = lookup(var.instance_type, var.env)
key_name = aws_key_pair.my_key.key_name
vpc_security_group_ids = [aws_security_group.my_sg.id]
associate_public_ip_address = false

lifecycle {
create_before_destroy = true
}

tags = merge(local.default_tags,
{
"Name" = "${local.name_prefix}-Amazon-Linux"
}
)
}


# Adding SSH key to Amazon EC2
resource "aws_key_pair" "my_key" {
key_name = local.name_prefix
public_key = file("${local.name_prefix}.pub")
}

# Security Group
resource "aws_security_group" "my_sg" {
name = "allow_ssh"
description = "Allow SSH inbound traffic"
vpc_id = data.aws_vpc.default.id

ingress {
description = "SSH from everywhere"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

tags = merge(local.default_tags,
{
"Name" = "${local.name_prefix}-sg"
}
)
}

# Elastic IP
resource "aws_eip" "static_eip" {
instance = aws_instance.my_amazon.id
tags = merge(local.default_tags,
{
"Name" = "${local.name_prefix}-eip"
}
)
}
resource "aws_ecr_repository" "mysql" {
name = "mysql"
}

# Create ECR repository for WebApp
resource "aws_ecr_repository" "webapp" {
name = "webapp"
}
4 changes: 4 additions & 0 deletions terraform_code/dev/instances/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Step 10 - Add output variables
output "eip" {
value = aws_eip.static_eip.public_ip
}
22 changes: 22 additions & 0 deletions terraform_code/dev/instances/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Instance type
variable "instance_type" {
default = {
"prod" = "t3.medium"
"test" = "t3.micro"
"staging" = "t2.micro"
"dev" = "t2.micro"
}
description = "Type of the instance"
type = map(string)
}

# Variable to signal the current environment
variable "env" {
default = "dev"
type = string
description = "Deployment Environment"
}




13 changes: 13 additions & 0 deletions terraform_code/modules/globalvars/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Default tags
output "default_tags" {
value = {
"Owner" = "Dockerintro"
"App" = "Web"
"Project" = "CLO835"
}
}

# Prefix to identify resources
output "prefix" {
value = "week1"
}