S19: establish engineering repository
This commit is contained in:
38
resources/deploy/provision.sh
Normal file
38
resources/deploy/provision.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Account-level provisioning. Docker sudo must already be enabled separately.
|
||||
set -eu
|
||||
umask 077
|
||||
root=$1
|
||||
registry_user=$2
|
||||
registry=$3
|
||||
bind=$4
|
||||
port=$5
|
||||
docker=${6:?Supply the Docker executable path}
|
||||
test -x "$docker"
|
||||
sudo -n "$docker" compose version
|
||||
sudo -n "$docker" info --format '{{.OSType}}/{{.Architecture}}'
|
||||
test ! -L "$root"
|
||||
mkdir -p "$root" "$root/docker-auth"
|
||||
chmod 700 "$root" "$root/docker-auth"
|
||||
if [ ! -f "$root/production.env" ]; then
|
||||
# First provisioning must not take a port already occupied by another service.
|
||||
command -v netstat >/dev/null
|
||||
if netstat -lnt | awk -v port=":$port" '$4 ~ (port "$") { found=1 } END { exit !found }'; then
|
||||
echo 'Frontend port is already occupied; production configuration unchanged' >&2
|
||||
exit 1
|
||||
fi
|
||||
printf 'BIND_IP=%s\nFRONTEND_PORT=%s\nDOCKER_BIN=%s\nDOCKER_SUDO=1\nDOCKER_CONFIG=%s/docker-auth\n' \
|
||||
"$bind" "$port" "$docker" "$root" > "$root/production.env"
|
||||
chmod 600 "$root/production.env"
|
||||
else
|
||||
# Preserve existing config; refuse to silently rebind a configured deployment.
|
||||
. "$root/production.env"
|
||||
test "$BIND_IP" = "$bind" && test "$FRONTEND_PORT" = "$port" \
|
||||
&& test "$DOCKER_CONFIG" = "$root/docker-auth" || {
|
||||
echo 'Existing production.env differs; review it before provisioning' >&2
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
# Credential enters only via stdin. No password, environment or auth config is logged.
|
||||
sudo -n "$docker" --config "$root/docker-auth" login "$registry" --username "$registry_user" --password-stdin
|
||||
echo 'Production directory and dedicated registry login prepared; no containers were changed.'
|
||||
Reference in New Issue
Block a user