-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·67 lines (60 loc) · 1.8 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·67 lines (60 loc) · 1.8 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
#!/usr/bin/env bash
# Deploy infra (CDK) and the SPA in one shot.
# Usage: ./deploy.sh # env=dev, both
# ./deploy.sh prod # env=prod, both
# ./deploy.sh dev --infra-only # CDK only
# ./deploy.sh dev --web-only # SPA only
# ./deploy.sh dev --skip-build # SPA: reuse web/dist
# ./deploy.sh dev --stacks "ApiStack DeliveryStack"
set -euo pipefail
ENV="dev"
SKIP_BUILD=0
INFRA_ONLY=0
WEB_ONLY=0
STACKS=""
for arg in "$@"; do
case "$arg" in
dev|prod) ENV="$arg" ;;
--skip-build) SKIP_BUILD=1 ;;
--infra-only) INFRA_ONLY=1 ;;
--web-only) WEB_ONLY=1 ;;
--stacks=*) STACKS="${arg#--stacks=}" ;;
--stacks) ;; # value comes as next arg, handled below
*) ;;
esac
done
# Allow `--stacks "A B"` form
prev=""
for arg in "$@"; do
if [[ "$prev" == "--stacks" ]]; then STACKS="$arg"; fi
prev="$arg"
done
if [[ "$INFRA_ONLY" -eq 1 && "$WEB_ONLY" -eq 1 ]]; then
echo "Cannot combine --infra-only and --web-only." >&2
exit 1
fi
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
say() { printf '\033[1;36m›\033[0m %s\n' "$*"; }
section() { printf '\n\033[1;35m━━ %s ━━\033[0m\n' "$*"; }
if [[ "$WEB_ONLY" -ne 1 ]]; then
section "Infra (CDK · env=$ENV)"
cd "$REPO_ROOT/infra"
if [[ -n "$STACKS" ]]; then
say "Deploying stacks: $STACKS"
# shellcheck disable=SC2086
npx cdk deploy $STACKS -c env="$ENV" --require-approval never
else
say "Deploying all stacks"
npx cdk deploy --all -c env="$ENV" --require-approval never
fi
fi
if [[ "$INFRA_ONLY" -ne 1 ]]; then
section "Web (SPA · env=$ENV)"
cd "$REPO_ROOT/web"
if [[ "$SKIP_BUILD" -eq 1 ]]; then
./deploy.sh "$ENV" --skip-build
else
./deploy.sh "$ENV"
fi
fi
section "Done"