-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathopsfile.yml
More file actions
367 lines (338 loc) · 11.8 KB
/
opsfile.yml
File metadata and controls
367 lines (338 loc) · 11.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
version: '3'
vars:
FL: ""
API_HOST:
sh: |
echo "http://localhost:80"
DEPLOY_CURRENT_HASH:
sh: |
if test -e "$OPS_ROOT/ide/deploy/bun.lockb"
then cd "$OPS_ROOT/ide/deploy" && bun "$OPS_ROOT/ide/deploy/bun.lockb" --hash
else echo "0"
fi
DEPLOY_PREVIOUS_HASH:
sh: |
if test -e "$OPS_ROOT/ide/deploy/hash.lock"
then cat "$OPS_ROOT/ide/deploy/hash.lock"
else echo "0"
fi
tasks:
prereq:
silent: true
vars:
MSG: |
This command must be run inside a devcontainer.
Please use 'ops ide devcontainer' to create a configuration and enter in a devcontainer.
You can then use 'ops ide devel' and 'ops ide deploy'.
You can also reopen the project with VSCode and use the command 'Reopen in Container'.
cmds:
- test -e "/.dockerenv" || die "{{.MSG}}"
- test "$(python3 -V | awk -F. '{print $2}')" -ge 10 || die "python 3.10 or greater not available"
- test -x "$(which virtualenv)" || die "you need python virtualenv"
- test "$(node -v | awk -F. '{print substr($1,2) }')" -ge 18 || die "nodejs 18 or greater not available"
- test "$(printf '%s\n' "$(bun -v)" "1.1.18" | sort -V | head -n 1)" = "1.1.18" || die "bun 1.1.18 or greater not available"
- test -d "$OPS_PWD/packages" || die "no packages in current directory"
- test -e ~/.wskprops || die "please run 'ops ide login' first"
- test -n "$OPSDEV_HOST" || die "please run 'ops ide login' first"
- test "$(ops -wsk property get --namespace | awk '{ print $3 }')" = "$OPSDEV_USERNAME" || die "Repeat the login"
- |
if ! test -d "$OPS_ROOT/ide/deploy/node_modules" || [ "{{.DEPLOY_CURRENT_HASH}}" != "{{.DEPLOY_PREVIOUS_HASH}}" ]
then
cd $OPS_ROOT/ide/deploy && bun install && rm -f $OPS_ROOT/ide/deploy/hash.lock && bun $OPS_ROOT/ide/deploy/bun.lockb --hash > $OPS_ROOT/ide/deploy/hash.lock
fi
- |
if test -e "$OPS_PWD/package.json"
then if ! test -d "$OPS_PWD/node_modules"
then cd $OPS_PWD ; bun install
fi
fi
- task: kill
devcontainer:
silent: true
desc: add a devcontainer to your project
cmds:
- |
if test -e "$OPS_PWD/.devcontainer/devcontainer.json"
then echo "a .devcontainer already exists"
else
mkdir -p "$OPS_PWD/.devcontainer"
cp devcontainer.json "$OPS_PWD/.devcontainer/"
echo "devcontainer created in .devcontainer - please use VSCode and the command 'Reopen in Container'"
fi
- |
if echo "$OPS_PWD/" | rg ' '
then die "please place your workspace in a folder WITHOUT SPACES IN THE FOLDER NAME!!!!"
fi
- bun x @devcontainers/cli up --workspace-folder "$OPS_PWD"
- bun x @devcontainers/cli exec --workspace-folder "$OPS_PWD" -- bash
kill:
silent: true
ignore_errors: true
cmds:
- |
PIDFILE=$(ops -opspath ~/.ops/tmp/deploy.pid)
echo $PIDFILE
if test -e $PIDFILE
then
PID=$(cat $PIDFILE)
if [ ! -z "$PID" ]; then
if ps -p "$PID" > /dev/null;
then
echo "Found previous deploy pid: $PID"
kill "$PID"
# PGRP=$(ps -o 'pgid=' -p $PID | xargs)
# if [ ! -z "$PGRP" ];
# then
# echo "Terminating deploy process group $PGRP"
# kill "$PGRP"
# else
# echo "Terminating deploy process $PID"
# kill "$PID"
# fi
fi
fi
rm -f $PIDFILE
fi
setup:
silent: true
desc: setup OpenServerless ide
cmds:
- |
clear
while ! test -e ~/.wskprops
do $OPS ide login
done
- |
echo "**************************************************************************************"
echo "*** Available Commands on Terminal:"
echo "*** 'deploy' (alias for 'ops ide deploy') to deploy your app to {{.API_HOST}}"
echo "*** 'devel' (alias for 'ops ide devel') to start incremental development mode"
echo "*** 'login' (alias for 'ops ide login') to login as a different user"
echo "*** 'ops ide' for more informations"
echo "*** https://openserverless.apache.org/ for online documentation"
echo "**************************************************************************************"
login:
silent: false
desc: login in you OpenServerless host
cmds:
- |
if test -e "$OPS_PWD/.env"
then source "$OPS_PWD/.env"
fi
if test -n "{{._apihost_}}"
then OPSDEV_APIHOST="{{._apihost_}}"
fi
echo "*** Configuring Access to OpenServerless ***"
if test -z "{{._apihost_}}"
then
if test -z "$OPS_APIHOST"
then
echo -n "Enter Apihost: "
read OPSDEV_APIHOST
OPSDEV_APIHOST="$(echo $OPSDEV_APIHOST | tr -d '\r')"
else
OPSDEV_APIHOST="$OPS_APIHOST"
fi
else OPSDEV_APIHOST="{{._apihost_}}"
fi
if test -z "{{._username_}}"
then
if test -n "$OPS_USERNAME"
then
OPSDEV_USERNAME="$OPS_USERNAME"
else
echo -n "Enter Username: "
read OPSDEV_USERNAME
OPSDEV_USERNAME="$(echo $OPSDEV_USERNAME | tr -d '\r')"
fi
else OPSDEV_USERNAME="{{._username_}}"
fi
echo "Logging user $OPSDEV_USERNAME in $OPSDEV_APIHOST"
if test -n "$OPS_PASSWORD"
then export "OPS_PASSWORD"
fi
if $OPS -login "$OPSDEV_APIHOST" "$OPSDEV_USERNAME"
then
OPSDEV_HOST_PROT="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print $1}')"
OPSDEV_HOST_URL="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print $2}')"
config OPSDEV_APIHOST="$OPSDEV_APIHOST"
config OPSDEV_USERNAME="$OPSDEV_USERNAME"
config OPSDEV_HOST="$OPSDEV_HOST_PROT://$OPSDEV_USERNAME.$OPSDEV_HOST_URL"
source ~/.wskprops
else
false
fi
poll:
silent: true
desc: poll activation logs
cmds:
- $OPS activation poll
serve:
silent: true
desc: local web server
ignore_error: true
cmds:
- |
OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web`
echo "Serving assets from ${OPS_UPLOAD_FOLDER:-web}"
bun {{.TASKFILE_DIR}}/deploy/serve.js -h 127.0.0.1 -P $OPSDEV_HOST -d "$OPS_PWD/${OPS_UPLOAD_FOLDER:-web}"
deploy:
silent: true
interactive: true
desc: deploy a project or a single action (with _action_=<dir-or-file>)
cmds:
- task: prereq
- |
set -a
if test -e $OPS_PWD/.env
then source $OPS_PWD/.env
fi
if test -e $OPS_PWD/packages/.env
then source $OPS_PWD/packages/.env
fi
if test -n "$AUTH_CHECK"
then if test "$AUTH_CHECK" != "$AUTH"
<<<<<<< HEAD
then echo "WARNING: wrong deploy! You are logged in a different user than your pinned one and configured in .env as AUTH_CHECK" ; exit 1
=======
then echo "WARNING: wrong deploy! You are logged in a different user than your configured AUTH_CHECK" ; exit 1
>>>>>>> 0c6ebab (debug)
fi
fi
if {{.__dry_run}}
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if {{.__web}}
then deploy_packages=""
else deploy_packages="1"
fi
if {{.__packages}}
then deploy_web=""
else deploy_web="1"
fi
if test -n "{{._action_}}"
then
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s "{{._action_}}" $DRY
else
if [ -n "$deploy_packages" ]
then
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY
fi
if [ -n "$deploy_web" ]
then
OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web`
echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}"
$ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web}
echo "URL: $OPSDEV_HOST"
fi
fi
undeploy:
desc: undeploy actions and packages from the current project
silent: true
cmds:
- task: prereq
- |
if {{.__dry_run}}
then DRY="--dry-run"
else DRY=""
fi
# Check if an action argument is provided
if test -n "{{._action_}}"
then
# Undeploy a specific action
echo "Undeploying specific action: {{._action_}}"
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -u -s "{{._action_}}" $DRY
else
# Undeploy all actions and packages from the current project
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -u $DRY
fi
- >
if {{.__dry_run}}
then echo '$' $OPS util clean
else $OPS util clean
fi
clean:
silent: true
cmds:
- task: kill
- |
if test -d "$OPS_PWD/packages"
then
echo "*** removing virtualenv"
/bin/rm -rvf "$OPS_PWD"/packages/*/*/virtualenv/
echo "*** removing node_modules"
/bin/rm -rvf "$OPS_PWD"/packages/*/*/node_modules/
echo "*** removing .zip"
/bin/rm -vf "$OPS_PWD"/packages/*/*.zip
else die "no packages in current directory"
fi
devel:
interactive: true
silent: true
desc: start interactive development mode files
cmds:
- task: prereq
- |
set -a
if test -e $OPS_PWD/.env
then source $OPS_PWD/.env
fi
if test -e $OPS_PWD/packages/.env
then source $OPS_PWD/packages/.env
fi
if test -n "$AUTH_CHECK"
then if test "$AUTH_CHECK" != "$AUTH"
then echo "WARNING: wrong deploy! You are logged in a different user than your configured AUTH_CHECK" ; exit 1
fi
fi
if {{.__dry_run}}
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if {{.__fast}}
then FAST="-f"
else FAST=""
fi
if [ -f /proc/version ]; then
if rg -i microsoft /proc/version >/dev/null 2>&1; then
export WATCHFILES_FORCE_POLLING=1
fi
# Check for macOS platform
elif [ "$(uname)" == "Darwin" ]; then
#export WATCHFILES_FORCE_POLLING=1
# Check for Windows platform (via WSL or similar)
elif [ -n "$WSL_DISTRO_NAME" ]; then
# WSL can have /proc/version like Linux
if rg -i microsoft /proc/version >/dev/null 2>&1; then
export WATCHFILES_FORCE_POLLING=1
fi
fi
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -w $FAST $DRY
true
shell:
desc: open a bash shell with the current environment
interactive: true
dir: $OPS_PWD
cmds:
- bash
python:
desc: python subcommand
nodejs:
desc: nodejs subcommand