forked from zilionis/dash
/
deploy
executable file
·100 lines (82 loc) · 1.98 KB
/
deploy
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/zsh
set -euo pipefail
_V=0
log() {
if [[ $_V -eq 1 ]]; then
echo "$@"
fi
}
clean_deploy() {
pushd $(git rev-parse --show-toplevel) >/dev/null
log "Removing deploy worktree"
git worktree remove .deploy
popd 2>/dev/null
}
zparseopts -D -E -A opts \
{h,-help}=help \
-detach=fly_args \
{c,-config}:=fly_args \
-branch:=opts \
-dirty=opts \
-verbose=opts \
-local=opts \
-dry-run=opts
if [ -n "${(k)opts[--verbose]:-}" ]; then
_V=1
fi
log "opts: ${(kv)opts}"
if (( $#help )); then
echo """Usage:
dev deploy [flags]
Flags:"""
cat <<FLAGS | column -t -s ';'
; --branch <branch>; Branch to deploy from [default: origin/main]
-c; --config <config file path>; Path to application configuration file
; --detach; Return immediately instead of monitoring deployment progress
; --dirty; Allow deploy to run against local branch: DANGEROUS
; --dry-run; Don't actually run "fly deploy"
; --local; Use the local docker daemon to build the container image
-h; --help; Help for deploy
; --verbose; Verbose output
FLAGS
return
fi
branch="${opts[--branch]:-origin/main}"
dirty=false
if [ -n "${(k)opts[--dirty]:-}" ]; then
dirty=true
fi
remote=true
if [ -n "${(k)opts[--local]:-}" ]; then
remote=false
fi
dry_run=false
if [ -n "${(k)opts[--dry-run]:-}" ]; then
dry_run=true
fi
pushd $(git rev-parse --show-toplevel) >/dev/null
set +e
git worktree remove .deploy 2>/dev/null
set -e
if [ "$remote" = "true" ]; then
fly_args+=(--remote-only)
fi
if [ "$dirty" = "false" ]; then
log "Fetching origin"
git fetch origin
log "Using branch: ${branch}"
short_sha=$(git rev-parse --short=12 "${branch}")
echo "Detected git reference: ${short_sha}"
fly_args+=(--build-arg "vcs_ref=${short_sha}")
log "Adding deploy worktree"
git worktree add -d .deploy "${branch}"
trap clean_deploy EXIT
cd .deploy
fi
echo
echo fly deploy "${(@)fly_args}"
if [ "$dry_run" = "true" ]; then
echo "Dry run: Skipping actual fly deploy"
else
fly deploy "${(@)fly_args}"
fi