-
Notifications
You must be signed in to change notification settings - Fork 4
/
install
215 lines (164 loc) · 8.96 KB
/
install
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
redis_db=$(ynh_redis_get_free_db)
secret_key=$(ynh_string_random --length=40)
main_domain=$(yunohost domain list --output-as plain | grep -A1 -e '#main' | tail -n 1)
ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
ynh_app_setting_set --app=$app --key=main_domain --value=$main_domain
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=10
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_setup_source --dest_dir="$install_dir/jdk" --source_id="jdk"
export JAVA_HOME=$install_dir/jdk
chown -R $app:www-data "$install_dir"
tmp_dir=$(mktemp -d)
pushd $tmp_dir
curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh
chmod +x linux-install.sh
ynh_exec_warn_less ./linux-install.sh -p $install_dir/clojure
popd
ynh_secure_remove --file=$tmp_dir
ynh_setup_source --dest_dir="$install_dir/babashka" --source_id="babashka"
export PATH=$JAVA_HOME/bin:$install_dir/clojure/bin:$install_dir/babashka:$PATH
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_setup_source --dest_dir="$install_dir/build"
chown -R $app:www-data "$install_dir"
chmod -R o-rwx "$install_dir"
#=================================================
# INSTALL APP
#=================================================
ynh_script_progression --message="Building frontend..." --weight=5
pushd $install_dir/build/frontend
ynh_exec_warn_less env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable
ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack prepare --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production COREPACK_ENABLE_DOWNLOAD_PROMPT=0 yarn install --immutable
# ynh_exec_warn_less
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${current_hash}\"}"
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run build:app:assets
# ynh_exec_warn_less ynh_exec_as $app env PATH=$node_PATH:$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production yarn run build:storybook
ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/frontend/resources/public/index.html"
ynh_replace_string --match_string="%buildDate%" --replace_string="$build_date" --target_file="$install_dir/build/frontend/resources/public/index.html"
#echo "$version" > target/version.txt;
popd
mkdir -p $install_dir/frontend
mv $install_dir/build/frontend/resources/public/* $install_dir/frontend
# mv $install_dir/build/frontend/storybook-static $install_dir/frontend
chown -R $app:www-data $install_dir/frontend
chmod -R 750 $install_dir/frontend
ynh_script_progression --message="Building backend..." --weight=5
pushd $install_dir/build/backend
mkdir -p target/classes;
mkdir -p target/dist;
echo "$version" > target/classes/version.txt;
cp ../CHANGES.md target/classes/changelog.md;
chown -R $app:$app target
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME clojure -T:build jar;
mv target/penpot.jar target/dist/penpot.jar
cp resources/log4j2.xml target/dist/log4j2.xml
cp scripts/run.template.sh target/dist/run.sh
chmod +x target/dist/run.sh;
# Prefetch templates
mkdir builtin-templates;
bb ./scripts/prefetch-templates.clj resources/app/onboarding.edn builtin-templates/
cp -r builtin-templates target/dist/
popd
mkdir -p $install_dir/backend
mv $install_dir/build/backend/target/dist/* $install_dir/backend
chown -R $app:$app $install_dir/backend
chmod -R 700 $install_dir/backend
ynh_script_progression --message="Building exporter..." --weight=5
pushd $install_dir/build/exporter
ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --immutable
ynh_secure_remove --file="target"
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -M:dev:shadow-cljs release main
cp yarn.lock target/
cp package.json target/
ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/exporter/target/app.js"
popd
mkdir -p $install_dir/exporter
mv $install_dir/build/exporter/target/* $install_dir/exporter
cp $install_dir/build/.yarnrc.yml $install_dir/exporter
chown -R $app:$app $install_dir/exporter
chmod -R 700 $install_dir/exporter
ynh_secure_remove --file=$install_dir/.cache
pushd $install_dir/exporter
ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate
ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn install --immutable
ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run playwright install chromium
popd
ynh_script_progression --message="Cleaning up..." --weight=1
ynh_secure_remove --file=$install_dir/.npm
ynh_secure_remove --file=$install_dir/.yarn
ynh_secure_remove --file=$install_dir/build
ynh_secure_remove --file=$install_dir/.m2
ynh_secure_remove --file=$install_dir/.clojure
ynh_secure_remove --file=$install_dir/clojure
ynh_secure_remove --file=$install_dir/babashka
ynh_secure_remove --file=$install_dir/.cache/ms-playwright/firefox-*
ynh_secure_remove --file=$install_dir/.cache/ms-playwright/webkit-*
ynh_secure_remove --file=$install_dir/.cache/yarn
ynh_secure_remove --file=$install_dir/.cache/node
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..."
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --template="backend.service" --service="$app-backend"
yunohost service add $app-backend --log="/var/log/$app/$app-backend.log"
ynh_add_systemd_config --template="exporter.service" --service="$app-exporter"
yunohost service add $app-exporter --log="/var/log/$app/$app-exporter.log"
# Use logrotate to manage application logfile(s)
mkdir -p /var/log/$app
touch /var/log/$app/$app-backend.log
touch /var/log/$app/$app-exporter.log
chown -R $app: /var/log/$app
ynh_use_logrotate --logfile="/var/log/$app/$app-backend.log"
ynh_use_logrotate --logfile="/var/log/$app/$app-exporter.log"
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Updating database configuration..."
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name
ynh_script_progression --message="Adding app's configuration file..."
ynh_add_config --template="config.js" --destination="$install_dir/frontend/js/config.js"
chmod 755 "$install_dir/frontend/js/config.js"
chown $app:www-data "$install_dir/frontend/js/config.js"
ynh_add_config --template="environ" --destination="$install_dir/backend/environ"
chmod 400 "$install_dir/backend/environ"
chown $app:$app "$install_dir/backend/environ"
ynh_add_config --template="exporter.env" --destination="$install_dir/exporter/.env"
chmod 400 "$install_dir/exporter/.env"
chown $app:$app "$install_dir/exporter/.env"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --line_match="welcome to penpot"
ynh_systemd_action --service_name=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --line_match="redis connection established"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last