diff --git a/.env b/.env index bf81fbf..0eddd87 100644 --- a/.env +++ b/.env @@ -3,6 +3,7 @@ # RDS_TYPE : RDS Type (Instance or Cluster) ############################################ AWS_PROFILE= +AWS_REGION= RDS_TYPE= PMA_HOSTS= PMA_VERBOSES= diff --git a/Docker/aws-host-tunnel b/Docker/aws-host-tunnel index 90e2560..85391c5 100755 --- a/Docker/aws-host-tunnel +++ b/Docker/aws-host-tunnel @@ -11,7 +11,7 @@ else AWS_CMD=describe-db-clusters fi -AWS_MYSQL_ENDPOINT=$(aws rds $AWS_CMD --query "DB${RDS_TYPE}s[*].Endpoint" --output json --profile $AWS_PROFILE) +export AWS_RDS_ENDPOINT=$(aws rds $AWS_CMD --query "DB${RDS_TYPE}s[?DBInstanceStatus=='available'].Endpoint" --output json --profile $AWS_PROFILE) BASTION_INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=bastion" --query "Reservations[*].Instances[*].InstanceId" --output text --profile $AWS_PROFILE) -SSM_PARAM=$(echo $AWS_MYSQL_ENDPOINT | jq '{"portNumber": [(.[] | .Port | tostring)], "localPortNumber": [(.[] | .Port | tostring)], "host": [(.[] | .Address)]}') +SSM_PARAM=$(echo $AWS_RDS_ENDPOINT | jq '{"portNumber": [(.[] | .Port | tostring)], "localPortNumber": [(.[] | .Port | tostring)], "host": [(.[] | .Address)]}') aws ssm start-session --target $BASTION_INSTANCE_ID --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "$SSM_PARAM" --profile $AWS_PROFILE diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.sh index ab57f47..3379da1 100644 --- a/Docker/entrypoint.sh +++ b/Docker/entrypoint.sh @@ -1,5 +1,24 @@ #!/bin/sh -eu -/docker-entrypoint.sh php-fpm & -nginx & +nginx -g "daemon off;" & /workspace/aws-host-tunnel >>/proc/1/fd/2 & +while [ -z "$AWS_RDS_ENDPOINT" ]; do + sleep 1 +done +RDS_HOST=$(echo $AWS_RDS_ENDPOINT | jq "(.[] | .Address)" | tr -d '"') +RDS_PORT=$(echo $AWS_RDS_ENDPOINT | jq "(.[] | .Port)") +RDS_VERBOSE="$(echo $RDS_HOST | cut -d '.' -f 1)(RDS)" + +if [ -z "$PMA_HOSTS" ]; then + export PMA_HOST=$RDS_HOST + export PMA_PORT=$RDS_PORT +else + export PMA_HOSTS=$PMA_HOSTS,$RDS_HOST + export PMA_VERBOSES=$PMA_VERBOSES,$RDS_VERBOSE + export PMA_PORTS=$PMA_PORT,$RDS_PORT +fi +/docker-entrypoint.sh php-fpm & +echo -e "127.0.0.1\t$RDS_HOST" >>/etc/hosts +if [ ! -f "/etc/ssl/$AWS_REGION-bundle.pem" ]; then + curl "https://truststore.pki.rds.amazonaws.com/$AWS_REGION/$AWS_REGION-bundle.pem" -o "/etc/ssl/$AWS_REGION-bundle.pem" +fi wait diff --git a/phpmyadmin/config.user.inc.php b/phpmyadmin/config.user.inc.php new file mode 100644 index 0000000..456e2e2 --- /dev/null +++ b/phpmyadmin/config.user.inc.php @@ -0,0 +1,11 @@ +