diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /scripts/upgrade.sh | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'scripts/upgrade.sh')
-rwxr-xr-x | scripts/upgrade.sh | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh deleted file mode 100755 index 64c7e1581..000000000 --- a/scripts/upgrade.sh +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | set -eu | ||
4 | |||
5 | PEERTUBE_PATH=${1:-/var/www/peertube} | ||
6 | |||
7 | if [ ! -e "$PEERTUBE_PATH" ]; then | ||
8 | echo "Error - path \"$PEERTUBE_PATH\" wasn't found" | ||
9 | echo "" | ||
10 | echo "If peertube was installed in another path, you can specify it with" | ||
11 | echo " ./upgrade.sh <PATH>" | ||
12 | exit 1 | ||
13 | fi | ||
14 | |||
15 | if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.yaml" ]; then | ||
16 | echo "Error - Couldn't find peertube installation in \"$PEERTUBE_PATH\"" | ||
17 | echo "" | ||
18 | echo "If peertube was installed in another path, you can specify it with" | ||
19 | echo " ./upgrade.sh <PATH>" | ||
20 | exit 1 | ||
21 | fi | ||
22 | |||
23 | if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ]; then | ||
24 | REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) | ||
25 | ONE_GB=$((1024 * 1024)) | ||
26 | |||
27 | if [ "$REMAINING" -lt "$ONE_GB" ]; then | ||
28 | echo "Error - not enough free space for upgrading" | ||
29 | echo "" | ||
30 | echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" | ||
31 | exit 1 | ||
32 | fi | ||
33 | fi | ||
34 | |||
35 | # Backup database | ||
36 | if [ -x "$(command -v pg_dump)" ]; then | ||
37 | mkdir -p $PEERTUBE_PATH/backup | ||
38 | |||
39 | SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak" | ||
40 | |||
41 | echo "Backing up PostgreSQL database in $SQL_BACKUP_PATH" | ||
42 | |||
43 | DB_USER=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['username'])") | ||
44 | DB_PASS=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['password'])") | ||
45 | DB_HOST=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['hostname'])") | ||
46 | DB_PORT=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['port'])") | ||
47 | DB_SUFFIX=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['suffix'])") | ||
48 | DB_NAME=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['name'] || '')") | ||
49 | |||
50 | PGPASSWORD=$DB_PASS pg_dump -U $DB_USER -p $DB_PORT -h $DB_HOST -F c "${DB_NAME:-peertube${DB_SUFFIX}}" -f "$SQL_BACKUP_PATH" | ||
51 | else | ||
52 | echo "pg_dump not found. Cannot make a SQL backup!" | ||
53 | fi | ||
54 | |||
55 | # If there is a pre-release, give the user a choice which one to install. | ||
56 | RELEASE_VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) | ||
57 | PRE_RELEASE_VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases | grep tag_name | head -1 | cut -d '"' -f 4) | ||
58 | |||
59 | if [ "$RELEASE_VERSION" != "$PRE_RELEASE_VERSION" ]; then | ||
60 | echo -e "Which version do you want to install?\n[1] $RELEASE_VERSION (stable) \n[2] $PRE_RELEASE_VERSION (pre-release)" | ||
61 | read choice | ||
62 | case $choice in | ||
63 | [1]* ) VERSION="$RELEASE_VERSION";; | ||
64 | [2]* ) VERSION="$PRE_RELEASE_VERSION";; | ||
65 | * ) exit; | ||
66 | esac | ||
67 | else | ||
68 | VERSION="$RELEASE_VERSION" | ||
69 | fi | ||
70 | |||
71 | echo "Installing Peertube version $VERSION" | ||
72 | wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" -O "$PEERTUBE_PATH/versions/peertube-${VERSION}.zip" | ||
73 | cd $PEERTUBE_PATH/versions | ||
74 | unzip -o "peertube-${VERSION}.zip" | ||
75 | rm -f "peertube-${VERSION}.zip" | ||
76 | |||
77 | RELEASE_PAGE_URL="https://github.com/Chocobozzz/PeerTube/releases/tag/${VERSION}" | ||
78 | LATEST_VERSION_DIRECTORY="$PEERTUBE_PATH/versions/peertube-${VERSION}" | ||
79 | cd "$LATEST_VERSION_DIRECTORY" | ||
80 | |||
81 | # Launch yarn to check if we have all required dependencies | ||
82 | NOCLIENT=1 yarn install --production --pure-lockfile | ||
83 | |||
84 | # Switch to latest code version | ||
85 | rm -rf $PEERTUBE_PATH/peertube-latest | ||
86 | ln -s "$LATEST_VERSION_DIRECTORY" $PEERTUBE_PATH/peertube-latest | ||
87 | cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml | ||
88 | |||
89 | echo "" | ||
90 | echo "==========================================================" | ||
91 | echo "" | ||
92 | |||
93 | if [ -x "$(command -v git)" ]; then | ||
94 | cd /var/www/peertube | ||
95 | |||
96 | git merge-file -p config/production.yaml "$LATEST_VERSION_DIRECTORY/config/production.yaml.example" "peertube-latest/config/production.yaml.example" | tee "config/production.yaml.new" > /dev/null | ||
97 | echo "/var/www/peertube/config/production.yaml.new generated" | ||
98 | echo "You can review it and replace your existing production.yaml configuration" | ||
99 | else | ||
100 | echo "git command not found: unable to generate config/production.yaml.new configuration file based on your existing production.yaml configuration" | ||
101 | fi | ||
102 | |||
103 | echo "" | ||
104 | echo "==========================================================" | ||
105 | echo "" | ||
106 | echo "Please read the IMPORTANT NOTES on $RELEASE_PAGE_URL" | ||
107 | echo "" | ||
108 | echo "Then restart PeerTube!" | ||