Init Git
This commit is contained in:
52
scripts/deploy.sh
Normal file
52
scripts/deploy.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_NAME="eop-api"
|
||||
AWS_REGION="ap-southeast-7"
|
||||
ECR_REPO_URI="804770683810.dkr.ecr.ap-southeast-7.amazonaws.com/amrez/eop-services"
|
||||
SSM_PREFIX="/amrez/eop"
|
||||
|
||||
need() {
|
||||
local v
|
||||
v=$(aws ssm get-parameter --with-decryption --region "$AWS_REGION" --name "${SSM_PREFIX}/$1" \
|
||||
--query "Parameter.Value" --output text 2>/dev/null || true)
|
||||
if [ -z "${v:-}" ] || [ "$v" == "None" ]; then
|
||||
echo "ERROR: missing SSM parameter: ${SSM_PREFIX}/$1" >&2; exit 1
|
||||
fi
|
||||
echo "$v"
|
||||
}
|
||||
|
||||
DC=$( need "Connections__DefaultConnection") # Host=127.0.0.1;Port=15432;...
|
||||
UST=$( need "Connections__UseSchemaPerTenant")
|
||||
SB=$( need "Connections__StorageBackend")
|
||||
RC=$( need "Connections__RedisConnection")
|
||||
RDB=$( need "Connections__RedisDb")
|
||||
|
||||
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$ECR_REPO_URI"
|
||||
docker pull "$ECR_REPO_URI:latest"
|
||||
|
||||
if docker ps -aq -f name=^/${APP_NAME}$ >/dev/null; then
|
||||
docker stop "$APP_NAME" || true
|
||||
docker rm "$APP_NAME" || true
|
||||
fi
|
||||
|
||||
# DB tunnel ต้องพร้อม (15432)
|
||||
if ! ss -lnt | grep -q ":15432 "; then
|
||||
echo "ERROR: tunnel 127.0.0.1:15432 is not listening" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# host network ⇒ 127.0.0.1 ใน container = ของโฮสต์
|
||||
docker run -d --name "$APP_NAME" \
|
||||
--network=host \
|
||||
--restart=always \
|
||||
-e ASPNETCORE_ENVIRONMENT=Production \
|
||||
-e ASPNETCORE_URLS=http://0.0.0.0:80 \
|
||||
-e "Connections__DefaultConnection=${DC}" \
|
||||
-e "Connections__UseSchemaPerTenant=${UST}" \
|
||||
-e "Connections__StorageBackend=${SB}" \
|
||||
-e "Connections__RedisConnection=${RC}" \
|
||||
-e "Connections__RedisDb=${RDB}" \
|
||||
"$ECR_REPO_URI:latest"
|
||||
|
||||
echo "Deployed $APP_NAME using $ECR_REPO_URI:latest"
|
||||
Reference in New Issue
Block a user