Adding dynamic environments #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Deploy | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
pull_request: | |
branches: | |
- main | |
jobs: | |
PrepareEnvironment: | |
runs-on: ubuntu-latest | |
outputs: | |
environment: ${{ steps.set_env.outputs.environment }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set Environment Name | |
id: set_env | |
working-directory: ./iac/scripts | |
run: | | |
# Install jq | |
sudo apt-get install -y jq | |
chmod +x get-branch-environment.sh | |
echo "environment=$(./get-branch-environment.sh ../branch-environment-map.json)" >> $GITHUB_ENV | |
BuildAndPush: | |
needs: PrepareEnvironment | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}} | |
environment: ${{ matrix.environment }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build and Push Docker Image | |
uses: ./.github/actions/container-build | |
with: | |
aws_region: ${{ secrets.AWS_REGION }} | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
ecr_url: ${{ secrets.ECR_URL }} | |
RunTerraform: | |
needs: BuildAndPush | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}} | |
environment: ${{ matrix.environment }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Run Terraform Action | |
uses: ./.github/actions/run-terraform | |
with: | |
aws_region: ${{ secrets.AWS_REGION }} | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
terraform_dir: ${{ env.TERRAFORM_DIR }} | |
ecr_url: ${{ secrets.ECR_URL }} | |
- name: Tag the deployment | |
working-directory: ./iac/scripts | |
run: | | |
chmod +x ./deployment-tagger.sh | |
./deployment-tagger.sh tag \ | |
--current \ | |
--date | |
# - name: Terraform Destroy | |
# working-directory: ${{ env.TERRAFORM_DIR }} | |
# run: | | |
# terraform destroy \ | |
# -auto-approve | |
# TagDeployment: | |
# needs: RunTerraform | |
# runs-on: ubuntu-latest | |
# strategy: | |
# matrix: | |
# environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}} | |
# environment: ${{ matrix.environment }} | |
# steps: | |
# - name: Checkout | |
# uses: actions/checkout@v4 | |
# - name: Tag the deployment | |
# working-directory: ./iac/scripts | |
# run: | | |
# chmod +x ./deploment-tagger.sh | |
# ./deploment-tagger.sh tag \ | |
# --current \ | |
# --date |