-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-env
More file actions
73 lines (66 loc) · 2 KB
/
Copy pathget-env
File metadata and controls
73 lines (66 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Work out which environment the deploy and container scripts should act on.
#
# Sourced rather than run, because it exists to set variables for its caller:
#
# ENV the environment's name, empty for the default one
# DOTENV_FILE absolute path of the env file to use, empty if there is none
# REST_ARGS whatever arguments were left once --env had been taken out
#
# It only *finds* the file, and never reads it. Callers that need the values inside do that
# themselves: scripts/connect sources it, scripts/container passes the path to
# `docker compose --env-file`, and scripts/deploy copies it to the server.
#
# The environment is given as -e/--env/--env=, where "-" stands for the current branch name, and
# selects dist/<ENV>.env, or dist/.env when no environment is named. A worktree keeps no deploy
# env files of its own, so the main checkout's are used instead.
set -e
cd "$(dirname "$0")/.."
. scripts/lib
REST_ARGS=()
while (($#)); do
case $1 in
-e|--env)
ENV="$2"
shift 2 # past argument and value
;;
-e*)
ENV="${1#-e}"
shift
;;
--env=*)
ENV="${1#*=}"
shift
;;
--)
shift
REST_ARGS+=("$@")
break
;;
*)
REST_ARGS+=("$1")
shift
;;
esac
done
set -a
if [ "$ENV" = "-" ]; then
ENV="$(git branch --show-current)"
if [ -z "$ENV" ]; then
printf 'Git currently has a detached HEAD, cannot deploy the branch.\n' >&2
echo >&2
exit 1
fi
fi
if [ -f dist/"$ENV".env ]; then
DOTENV_FILE="$(readlink -f dist/"$ENV".env)"
elif [ -f "$(primary_root)"/dist/"$ENV".env ]; then
# A worktree has no deploy env files of its own, since they are gitignored. Borrow the main
# checkout's rather than keeping a second copy of the deploy secrets in step with the first.
DOTENV_FILE="$(readlink -f "$(primary_root)"/dist/"$ENV".env)"
elif [ ! -z "$ENV" ]; then
printf 'The environment %q is not supported, the file dist/%q.env does not exist.\n' \
"$ENV" "$ENV" >&2
echo >&2
exit 1
fi
set +a