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

Master #8

Open
wants to merge 13 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
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy to ECR
# updated secrets
on:
push:
branches: [ master ]

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, test, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
SQL_REPOSITORY: mysql
WEB_REPOSITORY: webapp
IMAGE_TAG: v0.1
run: |
# Docker build command
docker build -t $ECR_REGISTRY/$SQL_REPOSITORY:$IMAGE_TAG -f Dockerfile_mysql .
docker build -t $ECR_REGISTRY/$WEB_REPOSITORY:$IMAGE_TAG -f Dockerfile .
docker push $ECR_REGISTRY/$SQL_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$WEB_REPOSITORY:$IMAGE_TAG

6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ WORKDIR /app
RUN set -xe \
&& apt-get update -y \
&& apt-get install -y python3-pip \
&& apt-get install -y mysql-client
&& apt-get install -y mysql-client \
&& apt-get install -y mysql-client \
&& apt-get install -y iputils-ping
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8080
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
CMD [ "app.py" ]
41 changes: 41 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Define the provider
provider "aws" {
region = "us-east-1"
}

# 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
}

# Launch EC2 instance
resource "aws_instance" "web_instance" {
ami = data.aws_ami.latest_amazon_linux.id
instance_type = "t2.micro"
iam_instance_profile = "LabInstanceProfile"
key_name = "clo835_assign1"


user_data = <<-EOF
#!/bin/bash
yum update -y
amazon-linux-extras install docker -y
service docker start
usermod -a -G docker ec2-user
EOF
}

# Create ECR repository
resource "aws_ecr_repository" "webapp_repo" {
name = "webapp"
}

resource "aws_ecr_repository" "mysql_repo" {
name = "mysql"
}