From 2799c4548d246d70127e227609c3e3826fecdace Mon Sep 17 00:00:00 2001 From: noah-isayas Date: Sun, 10 Nov 2024 15:13:35 +0100 Subject: [PATCH 1/5] Pipeline addition, to push image to ecr --- .github/workflows/pipeline.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/workflows/pipeline.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..e69de29 From d7979c40b1c6e48f0adbc23130e8565ea7804b76 Mon Sep 17 00:00:00 2001 From: noah-isayas Date: Sun, 10 Nov 2024 15:15:42 +0100 Subject: [PATCH 2/5] Added workflow to commit --- .github/workflows/pipeline.yml | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index e69de29..e0174af 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,64 @@ +name: "Terraform" + +on: + push: + branches: + - main + pull_request: + +jobs: + # Builds a new container image, and pushes it on every commit to the repository + # Also pushes a tag called "latest" to track the lates commit + + build_docker_image: + name: Push Docker image to ECR + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Build and push Docker image + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 244530008913.dkr.ecr.eu-west-1.amazonaws.com + rev=$(git rev-parse --short HEAD) + docker build . -t hello + docker tag hello 244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private:$rev + docker tag hello 244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private:latest + docker push 244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private:$rev + docker push 244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private:latest + + terraform: + name: "Terraform" + needs: build_docker_image + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: eu-west-1 + IMAGE: 244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private:latest + PREFIX: noha019 + # TF_LOG: trace + steps: + - uses: actions/checkout@v3 + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Plan + id: plan + run: terraform plan -var="prefix=$PREFIX" -var="image=$IMAGE" -no-color + continue-on-error: true + + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + run: terraform apply -var="prefix=noha019" -var="244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private" -auto-approve \ No newline at end of file From 9033531d57b5d66e31e3a524cf63eaa4f37d7994 Mon Sep 17 00:00:00 2001 From: noah-isayas Date: Sun, 10 Nov 2024 15:20:35 +0100 Subject: [PATCH 3/5] Fixed a missunderstanding in the terraform apply job --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index e0174af..a1769af 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -61,4 +61,4 @@ jobs: - name: Terraform Apply if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -var="prefix=noha019" -var="244530008913.dkr.ecr.eu-west-1.amazonaws.com/noha019-private" -auto-approve \ No newline at end of file + run: terraform apply -var="prefix=$PREFIX" -var="image=$IMAGE" -auto-approve \ No newline at end of file From f182ea7eb10758ddb0483dc986604d05d7a5ff53 Mon Sep 17 00:00:00 2001 From: noah-isayas Date: Sun, 10 Nov 2024 15:49:43 +0100 Subject: [PATCH 4/5] Pr-plan --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index a1769af..2f122d8 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -7,7 +7,7 @@ on: pull_request: jobs: - # Builds a new container image, and pushes it on every commit to the repository + # Builds a new container image and pushes it on every commit to the repository # Also pushes a tag called "latest" to track the lates commit build_docker_image: From e733a80aade429ee67e79e72e2d21c65594d2d9a Mon Sep 17 00:00:00 2001 From: noah-isayas Date: Sun, 10 Nov 2024 15:53:10 +0100 Subject: [PATCH 5/5] Last change to ensure workflow part that runs on pr is working --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 2f122d8..fabd8b6 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -7,7 +7,7 @@ on: pull_request: jobs: - # Builds a new container image and pushes it on every commit to the repository + # Builds a new container image and pushes it on every commit to the repository # Also pushes a tag called "latest" to track the lates commit build_docker_image: