forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.5 KiB
77 lines
2.5 KiB
#!/bin/bash
|
|
|
|
## Init is run on host
|
|
## For now it is run every time the script is launched, but
|
|
## it should be launched only once after build.
|
|
|
|
## Accessible variables are:
|
|
## - SERVICE_NAME Name of current service
|
|
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
|
|
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
|
|
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
|
|
|
|
aimport remainder_args
|
|
case "${remainder_args[@]:0:2}" in
|
|
"crt info"|"crt list")
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
. lib/common || exit 1
|
|
|
|
set -e
|
|
|
|
|
|
service_def=$(get_compose_service_def "$SERVICE_NAME")
|
|
|
|
config="
|
|
$SERVICE_NAME:
|
|
environment:
|
|
"
|
|
if USER_EMAIL=$(echo "$service_def" | shyaml get-value options.email 2>/dev/null); then
|
|
config+=" LETSENCRYPT_USER_MAIL: $USER_EMAIL"
|
|
fi
|
|
|
|
if environment_def="$(printf "%s" "$service_def" | shyaml -y get-value options.env 2>/dev/null)"; then
|
|
while read-0 key value; do
|
|
config+="$(printf "\n %s: %s" "$key" "$value")"
|
|
done < <(printf "%s" "$environment_def" | yaml_opt_bash_env_ignore_first_level LEXICON)
|
|
|
|
if ! provider=$(printf "%s" "$environment_def" | shyaml -y get-value provider 2>/dev/null); then
|
|
provider=
|
|
## If no provider is given, we fallback on the first found
|
|
|
|
while read-0 key value; do
|
|
[[ "$(echo "$value" | shyaml get-type)" == "struct" ]] && {
|
|
provider="$key"
|
|
break
|
|
}
|
|
done < <(echo "$environment_def" | shyaml key-values-0)
|
|
warn "No ${WHITE}provider${NORMAL} key given, had to infer it, chose '$key'."
|
|
fi
|
|
|
|
config+=$(echo -en "\n LEXICON_PROVIDER: $provider")
|
|
fi
|
|
|
|
if ! challenge_type=$(printf "%s" "$service_def" | shyaml get-value "options.challenge-type" 2>/dev/null); then
|
|
warn "No ${WHITE}challenge-type${NORMAL} provided, defaulting to 'http'."
|
|
challenge_type=http
|
|
fi
|
|
config+=$(echo -en "\n CHALLENGE_TYPE: $challenge_type")
|
|
|
|
if will_need_http_access; then
|
|
while read container_id; do
|
|
info "Attempting to clear port 80 by stopping $container_id"
|
|
docker stop -t 5 "$container_id"
|
|
done < <(docker ps \
|
|
--filter label="compose.project=$PROJECT_NAME" \
|
|
--filter publish=80 \
|
|
--format "{{.ID}}"
|
|
)
|
|
config+=$(echo -en "\n ports:
|
|
- \"0.0.0.0:80:80\"")
|
|
fi
|
|
|
|
init-config-add "$config"
|
|
|
|
mkdir -p "$SERVICE_DATASTORE/etc/letsencrypt"
|