diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4a2d8af --- /dev/null +++ b/.github/workflows/main.yml @@ -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 + 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" ] diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2c16a70 --- /dev/null +++ b/main.tf @@ -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" +} +