vela 0.11.3 → 0.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/dist/bin.js +854 -313
- package/dist/bin.js.map +4 -4
- package/package.json +19 -4
- package/templates/minimal/package.template.json +1 -1
- package/templates/minimal/vite.config.ts +1 -1
- package/templates/minimal/vitest.config.ts +3 -0
- package/templates/server/apply.sh +126 -36
- package/templates/server/destroy.sh +49 -6
- package/templates/server/lib.sh +114 -9
- package/templates/server/origin.sh +2 -0
- package/templates/server/restore.sh +7 -4
- package/templates/server/rollback.sh +12 -16
|
@@ -23,16 +23,19 @@ require_provisioned
|
|
|
23
23
|
|
|
24
24
|
INSTANCE=${1:-}; shift || true
|
|
25
25
|
[ -n "$INSTANCE" ] || die "usage: restore.sh <instance> --archive <path> [options]"
|
|
26
|
+
require_instance_id "$INSTANCE"
|
|
26
27
|
|
|
27
28
|
ARCHIVE=""
|
|
28
29
|
MIGRATE=1
|
|
29
30
|
KEEP_PREVIOUS=1
|
|
30
31
|
CLEANUP_ARCHIVE=0
|
|
31
32
|
HEALTH_PATH=""
|
|
33
|
+
LOCK_WAIT=300
|
|
32
34
|
|
|
33
35
|
while [ $# -gt 0 ]; do
|
|
34
36
|
case "$1" in
|
|
35
37
|
--archive) ARCHIVE=$2; shift 2 ;;
|
|
38
|
+
--lock-wait) LOCK_WAIT=$2; shift 2 ;;
|
|
36
39
|
--no-migrate) MIGRATE=0; shift ;;
|
|
37
40
|
--keep-previous) KEEP_PREVIOUS=$2; shift 2 ;;
|
|
38
41
|
--cleanup-archive) CLEANUP_ARCHIVE=1; shift ;;
|
|
@@ -47,6 +50,10 @@ done
|
|
|
47
50
|
# directory the CLI happened to invoke from is usually one it cannot stat.
|
|
48
51
|
cd "$VELA_ROOT"
|
|
49
52
|
|
|
53
|
+
# Taken before anything is read: a deploy or another restore in flight would
|
|
54
|
+
# otherwise have this one moving a pb_data it is about to replace.
|
|
55
|
+
lock_instance "$INSTANCE" "$LOCK_WAIT"
|
|
56
|
+
|
|
50
57
|
require_backend "$INSTANCE"
|
|
51
58
|
|
|
52
59
|
APP=$(app_dir "$INSTANCE")
|
|
@@ -66,10 +73,6 @@ PORTS=$(allocate_ports "$INSTANCE")
|
|
|
66
73
|
WEB_PORT=$(printf '%s' "$PORTS" | jq -r .web)
|
|
67
74
|
PB_PORT=$(printf '%s' "$PORTS" | jq -r .pb)
|
|
68
75
|
|
|
69
|
-
# Two restores at once would each move the other's pb_data aside.
|
|
70
|
-
exec 9>"$APP/.restore.lock"
|
|
71
|
-
flock -n 9 || die "another restore is already running for $INSTANCE"
|
|
72
|
-
|
|
73
76
|
# ---------------------------------------------------------------- preflight
|
|
74
77
|
#
|
|
75
78
|
# Everything that can be checked before a service stops is checked before a
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Put the previous release back for one instance.
|
|
4
4
|
#
|
|
5
|
-
# usage: rollback.sh <instance> [--to <release>]
|
|
5
|
+
# usage: rollback.sh <instance> [--to <release>] [--lock-wait <seconds>]
|
|
6
6
|
set -Eeuo pipefail
|
|
7
7
|
|
|
8
8
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
@@ -13,21 +13,26 @@ require_provisioned
|
|
|
13
13
|
[ "$(id -u)" -eq 0 ] || die "rollback must run as root"
|
|
14
14
|
|
|
15
15
|
INSTANCE=${1:-}; shift || true
|
|
16
|
-
[ -n "$INSTANCE" ] || die "usage: rollback.sh <instance> [--to <release>]"
|
|
16
|
+
[ -n "$INSTANCE" ] || die "usage: rollback.sh <instance> [--to <release>] [--lock-wait <seconds>]"
|
|
17
|
+
require_instance_id "$INSTANCE"
|
|
17
18
|
|
|
18
19
|
TARGET=""
|
|
20
|
+
LOCK_WAIT=300
|
|
19
21
|
while [ $# -gt 0 ]; do
|
|
20
22
|
case "$1" in
|
|
21
23
|
--to) TARGET=$2; shift 2 ;;
|
|
24
|
+
--lock-wait) LOCK_WAIT=$2; shift 2 ;;
|
|
22
25
|
*) die "unknown argument: $1" ;;
|
|
23
26
|
esac
|
|
24
27
|
done
|
|
28
|
+
[ -z "$TARGET" ] || require_release_id "$TARGET"
|
|
25
29
|
|
|
26
30
|
# Commands that drop to the app user inherit this working directory, and the
|
|
27
31
|
# directory the CLI happened to invoke from is usually one it cannot stat.
|
|
28
32
|
cd "$VELA_ROOT"
|
|
29
33
|
|
|
30
34
|
APP=$(app_dir "$INSTANCE")
|
|
35
|
+
lock_instance "$INSTANCE" "$LOCK_WAIT"
|
|
31
36
|
[ -f "$(state_file "$INSTANCE")" ] || die "no instance $INSTANCE on this server"
|
|
32
37
|
|
|
33
38
|
CURRENT=$(state_get "$INSTANCE" activeRelease || echo "")
|
|
@@ -36,10 +41,10 @@ CURRENT=$(state_get "$INSTANCE" activeRelease || echo "")
|
|
|
36
41
|
[ -d "$APP/releases/$TARGET" ] || die "release $TARGET is no longer on disk"
|
|
37
42
|
[ "$TARGET" != "$CURRENT" ] || die "$TARGET is already the active release"
|
|
38
43
|
|
|
39
|
-
BACKEND=$(
|
|
44
|
+
BACKEND=$(instance_backend "$INSTANCE")
|
|
40
45
|
HEALTH_PATH=$(state_get "$INSTANCE" healthCheckPath 2>/dev/null || echo "/")
|
|
41
46
|
WEB_PORT=$(state_get "$INSTANCE" webPort)
|
|
42
|
-
PB_PORT=$(state_get "$INSTANCE" pbPort)
|
|
47
|
+
PB_PORT=$(state_get "$INSTANCE" pbPort 2>/dev/null || echo "")
|
|
43
48
|
WEB_UNIT=$(unit_web "$INSTANCE")
|
|
44
49
|
PB_UNIT=$(unit_pb "$INSTANCE")
|
|
45
50
|
|
|
@@ -50,15 +55,8 @@ if [ "$BACKEND" = "true" ]; then
|
|
|
50
55
|
# Down migrations belong to the release being left behind, so they run from
|
|
51
56
|
# the current release's migration set before the symlink moves.
|
|
52
57
|
if [ -n "$CURRENT" ] && [ -d "$APP/releases/$CURRENT/migrations" ]; then
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
log "reverting $AHEAD migration(s) introduced after $TARGET"
|
|
56
|
-
runuser -u "$VELA_USER" -- "$APP/bin/pocketbase" \
|
|
57
|
-
--dir "$APP/shared/pb_data" \
|
|
58
|
-
--migrationsDir "$APP/releases/$CURRENT/migrations" \
|
|
59
|
-
migrate down "$AHEAD" >&2 \
|
|
60
|
-
|| die "down migrations failed - the app is still stopped"
|
|
61
|
-
fi
|
|
58
|
+
revert_migrations "$APP" "$APP/releases/$CURRENT/migrations" "$APP/releases/$TARGET/migrations" \
|
|
59
|
+
|| die "down migrations failed - the app is still stopped"
|
|
62
60
|
fi
|
|
63
61
|
fi
|
|
64
62
|
|
|
@@ -68,9 +66,7 @@ mv -Tf "$APP/.current.tmp" "$APP/current"
|
|
|
68
66
|
# The running release is part of the instance's environment, so it has to move
|
|
69
67
|
# with the symlink.
|
|
70
68
|
ETC=$(etc_dir "$INSTANCE")
|
|
71
|
-
|
|
72
|
-
sed -i "s|^VELA_RELEASE=.*|VELA_RELEASE=$TARGET|" "$ETC/runtime.env"
|
|
73
|
-
fi
|
|
69
|
+
set_runtime_release "$ETC" "$TARGET"
|
|
74
70
|
|
|
75
71
|
if [ "$BACKEND" = "true" ]; then
|
|
76
72
|
systemctl restart "$PB_UNIT"
|