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

Feature/pr plan #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
64 changes: 64 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -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=$PREFIX" -var="image=$IMAGE" -auto-approve