-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·55 lines (44 loc) · 1.61 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -e # Exit script on any error
# Grab first argument if there is one
if [ $# -eq 1 ]
then
# First argument expected to be the github org/username
GITHUB_ORG=$1
fi
# Define AWS region and profile
AWS_REGION="us-east-2"
AWS_PROFILE="admin-sandbox"
# Check if aws-vault is installed
if command -v aws-vault &> /dev/null
then
# aws-vault is installed, use it for AWS credentials
AWS_VAULT_PREFIX="aws-vault exec $AWS_PROFILE --"
else
# aws-vault is not installed, proceed without it
AWS_VAULT_PREFIX=""
fi
# Step 1: Apply terraform for ECR
pushd terraform
${AWS_VAULT_PREFIX} terragrunt apply -target=aws_ecr_repository.knowledgeshare_ui_ecr --auto-approve
# Step 2: Get the ECR repository URL
ECR_REPO_URL=$(${AWS_VAULT_PREFIX} terragrunt output -raw ecr_repository_url)
popd
# Step 3: Build docker image
docker buildx build --platform linux/amd64 -t keyless-workflow-demo .
# Step 4: Authenticate Docker to the ECR registry
${AWS_VAULT_PREFIX} aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REPO_URL
# Step 5: Tag and push docker image to ECR
docker tag keyless-workflow-demo:latest $ECR_REPO_URL:latest
docker push $ECR_REPO_URL:latest
pushd terraform
# Step 6: Apply the rest of the terraform passing github org as a variable if it was provided
if [ -z ${GITHUB_ORG+x} ]
then
# GITHUB_ORG is not set, apply terraform without it
${AWS_VAULT_PREFIX} terragrunt apply --auto-approve
else
# GITHUB_ORG is set, apply terraform with it
${AWS_VAULT_PREFIX} terragrunt apply -var "github_organization=$GITHUB_ORG" --auto-approve
fi
popd