Skip to content

Commit

Permalink
api deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
voynow committed Nov 10, 2024
1 parent 9761651 commit 64bd177
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
37 changes: 29 additions & 8 deletions api/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
#!/bin/bash
echo "Logging in to ECR"
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com

echo "Building image"
docker build --no-cache --platform=linux/amd64 -t $REGISTRY_NAME .
# Check if Docker is running, and start it if not
if ! docker info >/dev/null 2>&1; then
echo "Starting Docker..."
open --background -a Docker
while ! docker info >/dev/null 2>&1; do
sleep 1
done
echo "Docker started."
fi

echo "Tagging image"
docker tag $REGISTRY_NAME:$TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REGISTRY_NAME:$TAG
# Build and push the image
poetry export --without-hashes -f requirements.txt -o requirements.txt
docker build -t trackflow .
docker tag trackflow:latest 498969721544.dkr.ecr.us-east-1.amazonaws.com/trackflow:latest
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 498969721544.dkr.ecr.us-east-1.amazonaws.com
docker push 498969721544.dkr.ecr.us-east-1.amazonaws.com/trackflow:latest

echo "Pushing image to ECR"
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REGISTRY_NAME:$TAG
# Get the image digest
image_digest=$(aws ecr describe-images \
--repository-name trackflow \
--image-ids imageTag=latest \
--query 'imageDetails[0].imageDigest' \
--output text)

# Update the image in the Terraform variables
cd ../infra/app
sed -i '' "s|^image = .*|image = \"498969721544.dkr.ecr.us-east-1.amazonaws.com/trackflow@$image_digest\"|" terraform.tfvars
terraform apply -auto-approve

# Return to the api folder
cd ../../api
7 changes: 0 additions & 7 deletions api/readme.md

This file was deleted.

0 comments on commit 64bd177

Please sign in to comment.