Skip to content

Commit

Permalink
update github workflow, clean up apply scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alismx committed Jun 24, 2024
1 parent 65cf0aa commit 2b3c8c3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
51 changes: 38 additions & 13 deletions .github/workflows/ecr_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,45 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
region: us-east-1
# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1
# with:
# region: us-east-1

# - name: Authenticate Docker Registry for ECR
# run: aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 339712971032.dkr.ecr.us-east-1.amazonaws.com

- name: Build Docker fhir-converter image
run: docker build -t fhir-converter .

- name: Tag Docker image
run: docker tag fhir-converter:latest 339712971032.dkr.ecr.us-east-1.amazonaws.com/fhir-converter:latest

- name: Push Docker image
run: docker push 339712971032.dkr.ecr.us-east-1.amazonaws.com/fhir-converter:latest
- uses: hashicorp/[email protected]
with:
terraform_version: 1.3.3
- name: Init Terraform
working-directory: ./terraform/implementation/ecs
env:
ENVIRONMENT: dev
BUCKET: infra-tfstate-alis-default-aizwjxuh
DYNAMODB_TABLE: infra-tfstate-lock-alis-default-aizwjxuh
REGION: us-east-1
OWNER: alis
PROJECT: infra
shell: bash
run: |
touch $ENVIRONMENT.tfvars
echo "owner = \"$OWNER\""
echo "project = \"$PROJECT\""
echo "region = \"$REGION\""
terraform init \
-migrate-state \
-var-file="$ENVIRONMENT.tfvars" \
-backend-config "bucket=$BUCKET" \
-backend-config "dynamodb_table=$DYNAMODB_TABLE" \
-backend-config "region=$REGION"
terraform apply -var-file="$ENVIRONMENT.tfvars"
# - name: Apply Terraform
# working-directory: ./terraform/implementation/ecs
# env:
# ENVIRONMENT: value
# shell: bash
# run: |
# terraform apply -var-file="$ENVIRONMENT.tfvars"
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,30 @@ if [ ! -f "$ENVIRONMENT.tfvars" ]; then
fi

if ! grep -q "owner" "$ENVIRONMENT.tfvars"; then
read -p "Who is the owner of this infrastructure? default=skylight" owner_choice
read -p "Who is the owner of this infrastructure? ( default=skylight ): " owner_choice
owner_choice=${owner_choice:-skylight}
echo "owner = \"$owner_choice\"" >> "$ENVIRONMENT.tfvars"
fi

if ! grep -q "project" "$ENVIRONMENT.tfvars"; then
read -p "What is this project called? default=dibbs" project_choice
read -p "What is this project called? ( default=dibbs ): " project_choice
project_choice=${project_choice:-dibbs}
echo "project = \"$project_choice\"" >> "$ENVIRONMENT.tfvars"
fi

if ! grep -q "region" "$ENVIRONMENT.tfvars"; then
read -p "What aws region are you setting up in? default=us-east-1" region_choice
read -p "What aws region are you setting up in? ( default=us-east-1 ): " region_choice
region_choice=${region_choice:-us-east-1}
echo "region = \"$region_choice\"" >> "$ENVIRONMENT.tfvars"
fi

echo "Running Terraform with the following configuration:"
echo "Running Terraform with the following variables:"
echo "Environment: $ENVIRONMENT"
echo "Terraform Workspace: $ENVIRONMENT"
echo "Bucket: $BUCKET"
echo "DynamoDB Table: $DYNAMODB_TABLE"
echo "Region: $REGION"
cat "$ENVIRONMENT.tfvars"

terraform init \
-migrate-state \
Expand All @@ -117,5 +119,4 @@ else
fi
fi

terraform destroy \
-var-file="$ENVIRONMENT.tfvars"
terraform apply -var-file="$ENVIRONMENT.tfvars"
16 changes: 7 additions & 9 deletions terraform/implementation/setup/setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/bin/bash

# Load environment variables from .env file
if [ -f ../.env ]; then
export $(cat ../.env | xargs)
fi

# set default values
ENVIRONMENT="${ENVIRONMENT:-}"
ENVIRONMENT="${ENVIRONMENT:-default}"

while [[ $# -gt 0 ]]
do
Expand Down Expand Up @@ -49,22 +44,25 @@ if [ ! -f "$ENVIRONMENT.tfvars" ]; then
fi

if ! grep -q "owner" "$ENVIRONMENT.tfvars"; then
read -p "Who is the owner of this infrastructure? default=skylight" owner_choice
read -p "Who is the owner of this infrastructure? ( default=skylight ): " owner_choice
owner_choice=${owner_choice:-skylight}
echo "owner = \"$owner_choice\"" >> "$ENVIRONMENT.tfvars"
fi

if ! grep -q "project" "$ENVIRONMENT.tfvars"; then
read -p "What is this project called? default=dibbs" project_choice
read -p "What is this project called? ( default=dibbs ): " project_choice
project_choice=${project_choice:-dibbs}
echo "project = \"$project_choice\"" >> "$ENVIRONMENT.tfvars"
fi

if ! grep -q "region" "$ENVIRONMENT.tfvars"; then
read -p "What aws region are you setting up in? default=us-east-1" region_choice
read -p "What aws region are you setting up in? ( default=us-east-1 ): " region_choice
region_choice=${region_choice:-us-east-1}
echo "region = \"$region_choice\"" >> "$ENVIRONMENT.tfvars"
fi

echo "Running Terraform with the following variables:"
cat "$ENVIRONMENT.tfvars"

terraform init -var-file="$ENVIRONMENT.tfvars"
terraform apply -var-file="$ENVIRONMENT.tfvars"

0 comments on commit 2b3c8c3

Please sign in to comment.