43 lines
1.4 KiB
Bash
Executable File
43 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Load environment variables from .env file if it exists
|
|
if [ -f ${PWD}/.env ]; then
|
|
# Use set -a to automatically export all variables
|
|
set -a
|
|
source ${PWD}/.env
|
|
set +a
|
|
fi
|
|
|
|
# Check if required environment variables are set
|
|
if [ -z "$FREEDNS_User" ] ||
|
|
[ -z "$FREEDNS_Password" ] ||
|
|
[ -z "$DOMAIN_NAME" ] ||
|
|
[ -z "$SSH_PUBLIC_KEY" ] ||
|
|
[ -z "$REPO_URL" ] ||
|
|
[ -z "$LETSENCRYPT_EMAIL" ]; then
|
|
echo "Error: FREEDNS_User, FREEDNS_Password, DOMAIN_NAME, SSH_PUBLIC_KEY, REPO_URL, and LETSENCRYPT_EMAIL must be set as environment variables or in a .env file."
|
|
exit 1
|
|
fi
|
|
|
|
# Deploy infrastructure
|
|
cdk deploy --app="python3 ${PWD}/app.py"
|
|
|
|
# Update application on running instances
|
|
INSTANCE_IDS=$(aws ec2 describe-instances \
|
|
--region us-east-2 \
|
|
--filters "Name=tag:Name,Values=IptvManagerStack/IptvManagerInstance" \
|
|
"Name=instance-state-name,Values=running" \
|
|
--query "Reservations[].Instances[].InstanceId" \
|
|
--output text)
|
|
|
|
for INSTANCE_ID in $INSTANCE_IDS; do
|
|
echo "Updating application on instance: $INSTANCE_ID"
|
|
aws ssm send-command \
|
|
--instance-ids "$INSTANCE_ID" \
|
|
--document-name "AWS-RunShellScript" \
|
|
--parameters '{"commands":["cd /home/ec2-user/iptv-manager-service && git pull && pip3 install -r requirements.txt && alembic upgrade head && sudo systemctl restart iptv-manager"]}' \
|
|
--no-cli-pager \
|
|
--no-paginate
|
|
done
|
|
|
|
echo "Deployment and instance update complete" |