From 6421e699e233e325ffed6ad80488bce90a2fc92d Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 4 Jun 2023 16:45:59 -0400 Subject: [PATCH 01/12] Create main.yml --- .github/workflows/main.yml | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b2d3799 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,45 @@ +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 }} + ECR_REPOSITORY: clo835-week3-1 + IMAGE_TAG: v0.1 + run: | + cd Chapter02/kubia/ + ls -ltra + # Docker build command + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + # Unit test + docker run -d -p 80:8080 --name nodeapp $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker ps + echo "Pause for 10 seconds to let container start" + sleep 10 + curl localhost -vvv + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 1a7837f0488c8a890bdc1db0182aaeaa44ac0776 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:00:09 -0400 Subject: [PATCH 02/12] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2d3799..e2f5bf2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: - name: Build, test, tag, and push image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: clo835-week3-1 + ECR_REPOSITORY: clo835-week3 IMAGE_TAG: v0.1 run: | cd Chapter02/kubia/ From 4236dd09b09ff935779a4484c7e83b01f4d0d6d5 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:02:30 -0400 Subject: [PATCH 03/12] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e2f5bf2..84c5179 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,7 @@ jobs: ECR_REPOSITORY: clo835-week3 IMAGE_TAG: v0.1 run: | - cd Chapter02/kubia/ + # cd Chapter02/kubia/ ls -ltra # Docker build command docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . From 14fa25541d28183bb7bfca425d2cd9e948ca6920 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:09:50 -0400 Subject: [PATCH 04/12] Update main.yml --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 84c5179..d70af17 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,9 +37,9 @@ jobs: # Docker build command docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . # Unit test - docker run -d -p 80:8080 --name nodeapp $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker ps - echo "Pause for 10 seconds to let container start" - sleep 10 - curl localhost -vvv + # docker run -d -p 80:8080 --name nodeapp $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + # docker ps + # echo "Pause for 10 seconds to let container start" + # sleep 10 + # curl localhost -vvv docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 079b9163d0b9c866c6e7c0806049094a72193956 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Tue, 6 Jun 2023 19:05:15 -0400 Subject: [PATCH 05/12] Update main.yml --- .github/workflows/main.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d70af17..ddf905e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,17 +29,12 @@ jobs: - name: Build, test, tag, and push image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: clo835-week3 + SQL_REPOSITORY: mysql + WEB_REPOSITORY: webapp IMAGE_TAG: v0.1 run: | - # cd Chapter02/kubia/ - ls -ltra # Docker build command - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - # Unit test - # docker run -d -p 80:8080 --name nodeapp $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - # docker ps - # echo "Pause for 10 seconds to let container start" - # sleep 10 - # curl localhost -vvv - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker build -t $ECR_REGISTRY/$SQL_REPOSITORY:$IMAGE_TAG Dockerfile_mysql . + docker build -t $ECR_REGISTRY/$WEB_REPOSITORY:$IMAGE_TAG Dockerfile . + docker push $ECR_REGISTRY/SQL_REPOSITORY:$IMAGE_TAG + docker push $ECR_REGISTRY/$WEB_REPOSITORY:$IMAGE_TAG From f5b3aa172c1eb22eb9dade195c069c93f58bccfd Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Tue, 6 Jun 2023 19:09:52 -0400 Subject: [PATCH 06/12] Update main.yml --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ddf905e..4a2d8af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,8 @@ jobs: IMAGE_TAG: v0.1 run: | # Docker build command - docker build -t $ECR_REGISTRY/$SQL_REPOSITORY:$IMAGE_TAG Dockerfile_mysql . - docker build -t $ECR_REGISTRY/$WEB_REPOSITORY:$IMAGE_TAG Dockerfile . - docker push $ECR_REGISTRY/SQL_REPOSITORY:$IMAGE_TAG + 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 + From 45baff324e92781891064921e441615ff06f58ef Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Tue, 6 Jun 2023 21:22:09 -0400 Subject: [PATCH 07/12] Update Dockerfile --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9dded45..9b9ff3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] \ No newline at end of file +CMD [ "app.py" ] From c9c4eb3c07dd0dfa8428e897c04415493fc96636 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:55:01 -0400 Subject: [PATCH 08/12] Add files via upload --- main.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 main.txt diff --git a/main.txt b/main.txt new file mode 100644 index 0000000..ddb0bff --- /dev/null +++ b/main.txt @@ -0,0 +1,40 @@ +# 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" +} From e37e2a631e16bfaaf2abd472a48d149121413006 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:56:36 -0400 Subject: [PATCH 09/12] Rename main.txt to main.tf --- main.txt => main.tf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename main.txt => main.tf (100%) diff --git a/main.txt b/main.tf similarity index 100% rename from main.txt rename to main.tf From 009ef29f79966e3964e0cd6ac745b01177d3c7ca Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:59:22 -0400 Subject: [PATCH 10/12] Update main.tf --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index ddb0bff..2c16a70 100644 --- a/main.tf +++ b/main.tf @@ -38,3 +38,4 @@ resource "aws_ecr_repository" "webapp_repo" { resource "aws_ecr_repository" "mysql_repo" { name = "mysql" } + From b9b880d8fa75216f5a5a392d61ab8ab2af8e0dff Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 9 Jul 2023 18:05:28 -0400 Subject: [PATCH 11/12] Update main.yml --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a2d8af..54b29c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,4 +38,3 @@ jobs: 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 - From de45565e27f0d8ce0f4c556c755fdf3f4314dda0 Mon Sep 17 00:00:00 2001 From: glasuncion <98256605+glasuncion@users.noreply.github.com> Date: Sun, 9 Jul 2023 18:07:50 -0400 Subject: [PATCH 12/12] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54b29c6..4a2d8af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,3 +38,4 @@ jobs: 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 +