@webship.co/workspace-openproject 0.0.0-stage → 1.0.1

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.
Files changed (32) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +183 -2
  3. package/ai/agents/openproject-site-builder.md +106 -0
  4. package/ai/agents/openproject-tester.md +118 -0
  5. package/ai/agents/openproject-work-package-worker.md +90 -0
  6. package/ai/commands/openproject-test.md +66 -0
  7. package/ai/prompts/openproject-build-and-test.md +28 -0
  8. package/ai/prompts/openproject-work-package-to-branch.md +24 -0
  9. package/ai/skills/openproject-scenarios/SKILL.md +74 -0
  10. package/ai/skills/openproject-scenarios/examples/roles.feature +17 -0
  11. package/ai/skills/openproject-scenarios/examples/session.feature +24 -0
  12. package/ai/skills/openproject-scenarios/examples/work-package.feature +17 -0
  13. package/commands/cmd-openproject-project.sh +31 -0
  14. package/commands/cmd-tools-openproject-cli.sh +24 -0
  15. package/config/plugin.openproject.settings.yml +29 -0
  16. package/config/settings.labels.yml +57 -0
  17. package/dist/src/index.d.ts +34 -0
  18. package/dist/src/index.js +60 -0
  19. package/dist/src/index.js.map +1 -0
  20. package/dist/src/lib/tracker.d.ts +26 -0
  21. package/dist/src/lib/tracker.js +323 -0
  22. package/dist/src/lib/tracker.js.map +1 -0
  23. package/features/openproject-runtimes.feature +32 -0
  24. package/features/openproject.feature +53 -0
  25. package/package.json +118 -4
  26. package/scripts/args/arg-openproject-cli.sh +28 -0
  27. package/scripts/args/arg-openproject.sh +31 -0
  28. package/scripts/docker-compose.openproject.yaml +46 -0
  29. package/scripts/functions/fun-openproject.sh +590 -0
  30. package/scripts/openproject-serve.sh +17 -0
  31. package/scripts/openproject-site.rb +246 -0
  32. package/testing/site.feature +28 -0
@@ -0,0 +1,46 @@
1
+ # OpenProject of this project: the publisher's all-in-one image (its web server, background worker and cache) on the
2
+ # project's own PostgreSQL (the container tool's db service), served at the project's address; the project's web
3
+ # container keeps the mail catcher, which takes the site's mail. Written by the OpenProject builder of the workspace
4
+ # (the plugin's docker-compose.openproject.yaml); build again rather than editing by hand. The site's own values (its
5
+ # secret key, the first administrator's password, its address) are in openproject/env, which only you can read.
6
+ services:
7
+ web:
8
+ environment:
9
+ - HTTP_EXPOSE=8093:80,8025:8025
10
+ - HTTPS_EXPOSE=8457:80,8026:8025
11
+ openproject:
12
+ image: "openproject/openproject:${OPENPROJECT_VERSION:-17.9.8}"
13
+ container_name: ddev-${DDEV_SITENAME}-openproject
14
+ labels:
15
+ com.ddev.site-name: ${DDEV_SITENAME}
16
+ com.ddev.approot: ${DDEV_APPROOT}
17
+ restart: "no"
18
+ expose:
19
+ - "80"
20
+ depends_on:
21
+ - db
22
+ env_file:
23
+ - ${DDEV_APPROOT}/openproject/env
24
+ volumes:
25
+ - openproject_assets:/var/openproject/assets
26
+ # The image declares this volume too; the site's database is the project's (DATABASE_URL), so it holds nothing
27
+ # of the site, but unnamed it would be left on the machine each time the container is made.
28
+ - openproject_pgdata:/var/openproject/pgdata
29
+ # The plugin's scripts, which the builder and the tool run in this container.
30
+ - ${DDEV_APPROOT}/openproject:/opt/webship:ro
31
+ environment:
32
+ VIRTUAL_HOST: ${DDEV_HOSTNAME}
33
+ HTTP_EXPOSE: "80:80"
34
+ HTTPS_EXPOSE: "443:80"
35
+ DATABASE_URL: postgres://db:db@db:5432/db
36
+ OPENPROJECT_HOST__NAME: ${DDEV_SITENAME}.ddev.site
37
+ OPENPROJECT_HTTPS: "true"
38
+ OPENPROJECT_SMTP__ADDRESS: web
39
+ USE_JEMALLOC: "false"
40
+ # Every volume the image declares, named after the project, so removing the project removes them with its database,
41
+ # and a new build starts empty.
42
+ volumes:
43
+ openproject_assets:
44
+ name: ddev-${DDEV_SITENAME}-openproject-assets
45
+ openproject_pgdata:
46
+ name: ddev-${DDEV_SITENAME}-openproject-pgdata
@@ -0,0 +1,590 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # OpenProject for the Webship Workspace: build a site of OpenProject (the open-source project management software) from
4
+ # the publisher's image, run its own tools in its container, add its default accounts and their memberships, add its
5
+ # sample content, and wire its step pack into the testing setup.
6
+ #
7
+ # Placed by `plugins.sh --install openproject` in core/scripts/plugins/openproject/functions/, where bootstrap sources
8
+ # it after the core's own functions. Everything runs in containers, never on the host:
9
+ # - DDEV (the default): OpenProject's all-in-one image is a service of a generic project, on the project's own
10
+ # PostgreSQL (the db service), at https://<name>.ddev.site; the project's web container keeps the mail catcher.
11
+ # - Docker Compose (--runtime docker): the publisher's image is the web container's (rt_stack image), on the
12
+ # project's PostgreSQL, its server and background worker started by the stack (rt_serve), at http://127.0.0.1:<port>.
13
+ # Podman, Kubernetes, Lando and Docksal are not proven yet: asked for one, the builder says so and changes nothing.
14
+ #
15
+ # The container tool has no project type for OpenProject, so a site of this plugin is recognised by a file on DDEV
16
+ # (.ddev/config.openproject.yaml, written by the builder) and by the plugin's claim on the other runtimes (rt_claim).
17
+ # Four names are the ones the core's tools look for:
18
+ # set_openproject_users the default accounts (cmd-tools-add-users.sh <project> openproject)
19
+ # add_openproject_users make them, and their memberships (the same tool, and --add-users of the builder)
20
+ # cancel_openproject_users lock them (cmd-tools-cancel-users.sh <project> openproject)
21
+ # testing_configure_openproject the step pack in the testing stack (cmd-tools-testing.sh <project>)
22
+
23
+ # The step pack a site is tested with, and the release line it is required at.
24
+ readonly OPENPROJECT_STEPS_PACKAGE='@webship-js/openproject-steps';
25
+ readonly OPENPROJECT_STEPS_VERSION='^2.0.0';
26
+
27
+ # The release the builder runs when none is asked for (a tag of the publisher's image).
28
+ readonly OPENPROJECT_DEFAULT_VERSION='17.9.8';
29
+
30
+ # The sample project the default accounts are members of (its identifier and its name), and the folder of a site with
31
+ # the plugin's scripts and the site's own values (its container reads them at /opt/webship on DDEV).
32
+ readonly OPENPROJECT_PROJECT='webship-site';
33
+ readonly OPENPROJECT_PROJECT_NAME='Webship site';
34
+ readonly OPENPROJECT_FILES='openproject';
35
+
36
+ # The default accounts, the ones a scenario logs in as: a Project admin of the sample project (owner), a Member
37
+ # (member), a Reader (reader), and an account with no membership (stranger), whose work package the tracker treats as
38
+ # from outside the project. Accounts are configuration, made once on the site; a test suite never creates or deletes
39
+ # one. The workspace account the builder makes with --install is an administrator of its own and is not in this list.
40
+ function set_openproject_users() {
41
+ users=(owner member reader stranger);
42
+ local user ;
43
+ for user in "${users[@]}" ; do
44
+ printf -v "user_${user}_name" '%s' "${user}" ;
45
+ printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
46
+ printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
47
+ printf -v "user_${user}_fullname" '%s' "${user^} Test" ;
48
+ done
49
+ user_owner_role='Project admin' ;
50
+ user_member_role='Member' ;
51
+ user_reader_role='Reader' ;
52
+ user_stranger_role='' ;
53
+ }
54
+
55
+ # The runtime of the project in this folder, or of a new build (--runtime, else the workspace's setting, else DDEV).
56
+ # A core without the runtime layer has DDEV only.
57
+ function openproject_runtime() {
58
+ if declare -f runtime_of > /dev/null ; then runtime_of "$@" ; else echo 'ddev' ; fi
59
+ }
60
+
61
+ # The address of the site in this folder (or of a new build named PROJECT_NAME, on DDEV).
62
+ function openproject_url() {
63
+ if [ "$(openproject_runtime)" != 'ddev' ] && declare -f rt_url > /dev/null ; then rt_url ; return ; fi
64
+ echo "https://${1:-${PROJECT_NAME}}.ddev.site" ;
65
+ }
66
+
67
+ # Is this folder an OpenProject site of this plugin? On DDEV the builder leaves .ddev/config.openproject.yaml in it;
68
+ # on another runtime the project carries the plugin's claim.
69
+ function openproject_is_project() {
70
+ local project_path="$1" ;
71
+ [ -f "${project_path}/.ddev/config.openproject.yaml" ] && return 0 ;
72
+ if declare -f rt_is_platform > /dev/null ; then rt_is_platform "${project_path}" openproject ; return $? ; fi
73
+ return 1 ;
74
+ }
75
+
76
+ # Go to the project a tool was asked about, or say why not.
77
+ function openproject_enter_project() {
78
+ local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
79
+ if [ ! -d "${project_path}" ] ; then
80
+ echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
81
+ return 1 ;
82
+ fi
83
+ if ! openproject_is_project "${project_path}" ; then
84
+ echo "${doc_name}/${PROJECT_NAME} is not an OpenProject site of this plugin." ;
85
+ return 1 ;
86
+ fi
87
+ openproject_refresh_files "${project_path}" || return 1 ;
88
+ cd "${project_path}" || return 1 ;
89
+ }
90
+
91
+ # The site's copy of the plugin's scripts (openproject/), brought up to the installed plugin's, so a plugin updated
92
+ # with --install reaches the sites built before it. The site's own values (openproject/env) are left as they are.
93
+ function openproject_refresh_files() {
94
+ local project_path="$1" from="${WORKSPACE_SCRIPTS}/plugins/openproject" f ;
95
+ [ -d "${project_path}/${OPENPROJECT_FILES}" ] || return 0 ;
96
+ for f in openproject-site.rb openproject-serve.sh ; do
97
+ if [ -f "${from}/${f}" ] && ! cmp -s "${from}/${f}" "${project_path}/${OPENPROJECT_FILES}/${f}" ; then
98
+ cp "${from}/${f}" "${project_path}/${OPENPROJECT_FILES}/${f}" || return 1 ;
99
+ fi
100
+ done
101
+ }
102
+
103
+ # A value of the site's own values (openproject/env), never printed by the tools: OPENPROJECT_VERSION.
104
+ function openproject_setting() {
105
+ sed -n "s/^$1=\\(.*\\)\$/\\1/p" "${2:-.}/${OPENPROJECT_FILES}/env" 2>/dev/null | head -n 1 ;
106
+ }
107
+
108
+ # A value made for this site only: letters and digits.
109
+ function openproject_secret() {
110
+ head -c 96 /dev/urandom | base64 -w0 | tr -dc 'A-Za-z0-9' | head -c "${1:-64}" ;
111
+ }
112
+
113
+ # Write the project's files: on DDEV OpenProject's service (.ddev/docker-compose.openproject.yaml), the release in
114
+ # .ddev/.env and the claim (.ddev/config.openproject.yaml); on another runtime the claim, the publisher's image as the
115
+ # web container's and its start (rt_claim, rt_stack, rt_web_build, rt_serve). Then the plugin's scripts and the site's
116
+ # own values (openproject/env, which only you can read): its secret key, the first administrator's password, the mail.
117
+ function openproject_write_config() {
118
+ local project_path="$1" version="$2" runtime="$3" ;
119
+ local from="${WORKSPACE_SCRIPTS}/plugins/openproject" f ;
120
+ for f in docker-compose.openproject.yaml openproject-site.rb openproject-serve.sh ; do
121
+ if [ ! -f "${from}/${f}" ] ; then
122
+ echo "${f} is not in ${from}: install the plugin (plugins.sh --install openproject)." ;
123
+ return 1 ;
124
+ fi
125
+ done
126
+ mkdir -p "${project_path}/${OPENPROJECT_FILES}" || return 1 ;
127
+ for f in openproject-site.rb openproject-serve.sh ; do
128
+ cp "${from}/${f}" "${project_path}/${OPENPROJECT_FILES}/${f}" || return 1 ;
129
+ done
130
+
131
+ local env="${project_path}/${OPENPROJECT_FILES}/env" ;
132
+ ( umask 077 && cat > "${env}" <<ENVEOF
133
+ # The values of this OpenProject site, made by the OpenProject builder of the workspace: its secret key and the first
134
+ # administrator's password (the account admin) are of this site only. Read by the site's container; never printed.
135
+ OPENPROJECT_VERSION=${version}
136
+ SECRET_KEY_BASE=$(openproject_secret 96)
137
+ OPENPROJECT_SEED__ADMIN__USER__PASSWORD=$(openproject_secret 24)
138
+ OPENPROJECT_SEED__ADMIN__USER__PASSWORD__RESET=false
139
+ OPENPROJECT_SEED__ADMIN__USER__MAIL=admin@example.com
140
+ OPENPROJECT_DEFAULT__LANGUAGE=en
141
+ OPENPROJECT_EMAIL__DELIVERY__METHOD=smtp
142
+ OPENPROJECT_SMTP__PORT=1025
143
+ OPENPROJECT_SMTP__ENABLE__STARTTLS__AUTO=false
144
+ OPENPROJECT_MAIL__FROM=openproject@example.com
145
+ ENVEOF
146
+ ) || return 1 ;
147
+
148
+ if [ "${runtime}" = 'ddev' ] ; then
149
+ cp "${from}/docker-compose.openproject.yaml" "${project_path}/.ddev/docker-compose.openproject.yaml" || return 1 ;
150
+ printf 'OPENPROJECT_VERSION=%s\n' "${version}" > "${project_path}/.ddev/.env" || return 1 ;
151
+ cat > "${project_path}/.ddev/config.openproject.yaml" <<YAMLEOF
152
+ # OpenProject in this project: its service (docker-compose.openproject.yaml), the release in .env, the site's own
153
+ # values in ../openproject/env. Written by the OpenProject builder of the workspace; build again rather than editing.
154
+ web_environment:
155
+ - OPENPROJECT_VERSION=${version}
156
+ YAMLEOF
157
+ return 0 ;
158
+ fi
159
+
160
+ # Another runtime: the publisher's image is the web container's, and the stack starts it (openproject-serve.sh).
161
+ local address port ;
162
+ address="$(cd "${project_path}" && rt_url)" ; port="${address##*:}" ;
163
+ cat >> "${env}" <<ENVEOF
164
+ DATABASE_URL=postgres://db:db@db:5432/db
165
+ OPENPROJECT_HOST__NAME=${address#http://}
166
+ OPENPROJECT_HTTPS=false
167
+ OPENPROJECT_SMTP__ADDRESS=mail
168
+ OPENPROJECT_RAILS__CACHE__STORE=file_store
169
+ OPENPROJECT_COLLABORATIVE__EDITING__HOCUSPOCUS__URL=
170
+ PORT=8080
171
+ ENVEOF
172
+ ( cd "${project_path}" \
173
+ && rt_claim openproject \
174
+ && rt_stack image "openproject/openproject:${version}" \
175
+ && rt_web_build openproject <<'DOCKEREOF'
176
+ # The image's own entrypoint starts its all-in-one setup as root; the stack starts OpenProject its own way instead
177
+ # (start.sh, then openproject/openproject-serve.sh, as the host user).
178
+ ENTRYPOINT []
179
+ # What OpenProject writes while it runs (its cache and process files, its log, its files) belongs to the host user,
180
+ # www-data with the host's UID by now: the image's own user (app) has UID 1000, which the host's may not be.
181
+ RUN mkdir -p /app/tmp/pids /app/tmp/cache /var/openproject/assets/files \
182
+ && chown -R www-data:www-data /app/tmp /app/log /app/files /var/openproject
183
+ DOCKEREOF
184
+ ) || return 1 ;
185
+ ( cd "${project_path}" && rt_serve 8080 "bash ${OPENPROJECT_FILES}/openproject-serve.sh" ) || return 1 ;
186
+ [[ "${port}" =~ ^[0-9]+$ ]] || { echo "No port for the site (${address})." ; return 1 ; } ;
187
+ }
188
+
189
+ # Run a command line in OpenProject's container, as OpenProject's own user, in its folder (/app), with the site's
190
+ # values; what is piped in reaches it.
191
+ function openproject_exec() {
192
+ local line="$1" ;
193
+ if [ "$(openproject_runtime)" = 'ddev' ] ; then
194
+ ddev exec -s openproject "su app -s /bin/bash -c $(printf '%q' "cd /app && ${line}")" ;
195
+ else
196
+ ddev exec "set -a ; . /var/www/html/${OPENPROJECT_FILES}/env ; set +a ; cd \"\${APP_PATH:-/app}\" && ${line}" ;
197
+ fi
198
+ }
199
+
200
+ # The folder the plugin's scripts are read from in OpenProject's container.
201
+ function openproject_scripts_dir() {
202
+ if [ "$(openproject_runtime)" = 'ddev' ] ; then echo '/opt/webship' ; else echo "/var/www/html/${OPENPROJECT_FILES}" ; fi
203
+ }
204
+
205
+ # The answer of OpenProject's own health check (200 when it serves and reaches its database), asked inside the
206
+ # project's network: on DDEV from the web container through OpenProject's proxy, elsewhere inside its own container.
207
+ function openproject_probe() {
208
+ local host ;
209
+ if [ "$(openproject_runtime)" = 'ddev' ] ; then
210
+ host="$(sed -n 's/^name:[[:space:]]*"\{0,1\}\([A-Za-z0-9._-]*\)"\{0,1\}[[:space:]]*$/\1/p' .ddev/config.yaml | head -n 1).ddev.site" ;
211
+ ddev exec "curl -s -o /dev/null -m 10 -w '%{http_code}' -H 'Host: ${host}' -H 'X-Forwarded-Proto: https' http://openproject/health_checks/default" < /dev/null 2>/dev/null | tr -d '\r' | tail -1 ;
212
+ else
213
+ host="$(rt_url)" ; host="${host#http://}" ;
214
+ ddev exec "curl -s -o /dev/null -m 10 -w '%{http_code}' -H 'Host: ${host}' http://127.0.0.1:8080/health_checks/default" < /dev/null 2>/dev/null | tr -d '\r' | tail -1 ;
215
+ fi
216
+ }
217
+
218
+ # Wait until the site answers, in the project's folder: up to fifteen minutes, as the first start loads the database
219
+ # and seeds it.
220
+ function openproject_wait() {
221
+ local attempt code="" ;
222
+ for attempt in $(seq 1 300) ; do
223
+ code="$(openproject_probe)" ;
224
+ [ "${code}" == '200' ] && return 0 ;
225
+ sleep 3 ;
226
+ done
227
+ echo "OpenProject did not answer (its health check: ${code:-none}); the end of its log:" ;
228
+ if [ "$(openproject_runtime)" = 'ddev' ] ; then ddev logs -s openproject --tail 40 < /dev/null 2>/dev/null ; else ddev logs < /dev/null 2>/dev/null | tail -n 40 ; fi
229
+ return 1 ;
230
+ }
231
+
232
+ # The release the site runs, as OpenProject says it.
233
+ function openproject_version() {
234
+ ( cd "${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}" 2>/dev/null && openproject_exec "cat VERSION 2>/dev/null || ruby -e 'require \"./lib/open_project/version\"; puts OpenProject::VERSION.to_semver'" < /dev/null 2>/dev/null ) | tr -d '\r' | tail -n 1 ;
235
+ }
236
+
237
+ # Run verbs of openproject-site.rb (accounts, content, tidy, list, token) with OpenProject's own Rails runner in its
238
+ # container. A payload (accounts, the default accounts' password) travels on the input, never on a command line.
239
+ function openproject_site() {
240
+ local verbs="$*" ;
241
+ # Warnings and errors only: the runner of the production environment logs every job it queues otherwise.
242
+ openproject_exec "OPENPROJECT_LOG__LEVEL=warn bundle exec rails runner $(openproject_scripts_dir)/openproject-site.rb ${verbs}" ;
243
+ }
244
+
245
+ # Rows of accounts for openproject-site.rb, as the base64 of its JSON list: "login|mail|password|first|last|admin|
246
+ # role|action" lines in OPENPROJECT_ROWS, which travel to Python in the environment, never on a command line.
247
+ function openproject_accounts_payload() {
248
+ OPENPROJECT_ROWS="$1" python3 -c '
249
+ import base64, json, os
250
+ rows = []
251
+ for line in os.environ["OPENPROJECT_ROWS"].split("\x1e"):
252
+ if not line:
253
+ continue
254
+ login, mail, password, first, last, admin, role, action = line.split("\x1f")
255
+ rows.append({"login": login, "mail": mail, "password": password, "firstname": first, "lastname": last,
256
+ "admin": admin == "yes", "role": role, "action": action})
257
+ print(base64.b64encode(json.dumps(rows).encode()).decode())' ;
258
+ }
259
+
260
+ # Build an OpenProject site from nothing: the project and OpenProject; with --install the workspace account as an
261
+ # administrator; with --add-users the default accounts, members of the sample project; with --sample-content the
262
+ # project's work packages, sprint and comment the step pack is tested on.
263
+ function openproject_build() {
264
+ trim_project_name ;
265
+ local version="${OPENPROJECT_VERSION:-${site_openproject_version:-${OPENPROJECT_DEFAULT_VERSION}}}" ;
266
+ local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}" ;
267
+ local runtime ; runtime="$(cd "${WORKSPACE_ROOT}/${doc_name}" && openproject_runtime)" ;
268
+
269
+ case "${runtime}" in
270
+ ddev|docker) ;;
271
+ *) echo "OpenProject builds on DDEV and on Docker Compose for now (--runtime ddev or docker), not on ${runtime}: that runtime is not proven for it yet. Nothing was changed." ; exit 1 ;;
272
+ esac
273
+ if [ "${runtime}" != 'ddev' ] && ! declare -f rt_stack > /dev/null ; then
274
+ echo "--runtime ${runtime} needs a Webship Workspace with the container runtimes (webship/workspace#694, #841): update the workspace, or build on DDEV." ;
275
+ exit 1 ;
276
+ fi
277
+ if ! [[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
278
+ echo "--openproject-version takes a release (17.9.8), not ${version}. Nothing was changed." ;
279
+ exit 1 ;
280
+ fi
281
+ if [ "${ADD_USERS}" == 'yes' ] && [ "${INSTALL}" != 'yes' ] ; then
282
+ echo "--add-users needs --install: the default accounts go into the site --install sets up." ;
283
+ exit 1 ;
284
+ fi
285
+ if [ "${SAMPLE_CONTENT}" == 'yes' ] && [ "${ADD_USERS}" != 'yes' ] ; then
286
+ echo "--sample-content needs --add-users: the sample project's members are the default accounts." ;
287
+ exit 1 ;
288
+ fi
289
+ if [ ${#PROJECT_NAME} -gt 40 ] || ! [[ "${PROJECT_NAME}" =~ ^[a-z0-9][a-z0-9-]*$ ]] ; then
290
+ echo "The project name ${PROJECT_NAME} must be small letters, digits and dashes (its address and its containers take it). Nothing was changed." ;
291
+ exit 1 ;
292
+ fi
293
+ if [ "${INSTALL}" == 'yes' ] && [ ${#account_pass} -lt 10 ] ; then
294
+ echo "The workspace account's password (core/config/settings.yml) has fewer than ten characters, which OpenProject asks of a password: --install makes it an account of the site. Nothing was changed." ;
295
+ exit 1 ;
296
+ fi
297
+
298
+ cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
299
+
300
+ # A project of the same name goes first, with its containers and its volumes (OpenProject's database and files).
301
+ drop_database ;
302
+ rm -rf "${PROJECT_NAME:?}" ;
303
+ mkdir -p "${PROJECT_NAME}" ;
304
+ cd "${project_path}" || exit 1 ;
305
+
306
+ # A generic project on PostgreSQL 17, the release OpenProject's image carries the tools of.
307
+ if [ "${runtime}" = 'ddev' ] ; then
308
+ ddev config --project-type=generic --project-name=${PROJECT_NAME} --database=postgres:17 \
309
+ --nodejs-version=$(ddev_nodejs_version) < /dev/null || exit 1 ;
310
+ else
311
+ ddev config --project-type=generic --webserver-type=generic --project-name=${PROJECT_NAME} --database=postgres:17 --auto < /dev/null || exit 1 ;
312
+ fi
313
+ openproject_write_config "${project_path}" "${version}" "${runtime}" || exit 1 ;
314
+ local base_url ; base_url="$(openproject_url)" ;
315
+
316
+ echo "Starting the project and OpenProject ${version}: its image is about 2 GB the first time, and the first start loads and seeds the database (some minutes)." ;
317
+ ddev_up start -y < /dev/null || exit 1 ;
318
+ openproject_wait || exit 1 ;
319
+
320
+ if [ "${INSTALL}" == 'yes' ] ; then
321
+ echo "Making the workspace account an administrator of the site." ;
322
+ local rows ;
323
+ rows="${account_name}"$'\x1f'"${account_mail:-${account_name}@example.com}"$'\x1f'"${account_pass}"$'\x1f'"${account_name^}"$'\x1f''Workspace'$'\x1f''yes'$'\x1f'$'\x1f'$'\x1e' ;
324
+ openproject_accounts_payload "${rows}" | openproject_site accounts || { echo "The workspace account could not be made." ; exit 1 ; } ;
325
+ if [ "${ADD_USERS}" == 'yes' ] ; then
326
+ set_openproject_users ;
327
+ add_openproject_users || exit 1 ;
328
+ if [ "${SAMPLE_CONTENT}" == 'yes' ] ; then
329
+ echo "Adding the sample content: the project ${OPENPROJECT_PROJECT_NAME}'s work packages, its active sprint and a comment." ;
330
+ ( cd "${project_path}" && openproject_site content < /dev/null ) || exit 1 ;
331
+ fi
332
+ users=() ;
333
+ fi
334
+ echo "${doc_name} ${PROJECT_NAME} has been installed: OpenProject $(openproject_version).";
335
+ echo "The site: ${base_url}" ;
336
+ echo "The workspace account logs in as ${account_name}; the first administrator (admin) has a password of this site only, in ${doc_name}/${PROJECT_NAME}/${OPENPROJECT_FILES}/env.";
337
+ else
338
+ echo "${doc_name} ${PROJECT_NAME} is ready: OpenProject $(openproject_version) at ${base_url}.";
339
+ echo "Its first administrator (admin) has a password of this site only, in ${doc_name}/${PROJECT_NAME}/${OPENPROJECT_FILES}/env. Build it again with --install (and --add-users) for the workspace account and the default accounts.";
340
+ fi
341
+
342
+ if [ "${LAUNCH}" == 'yes' ] ; then
343
+ ddev launch ;
344
+ fi
345
+
346
+ cd ${WORKSPACE_ROOT}/${doc_name};
347
+ }
348
+
349
+ # Make the default accounts, or give them back their names, passwords and status, with the first login done (no
350
+ # welcome dialog), and each a member of the sample project in its role (the stranger in none). The list is loaded by
351
+ # the caller (set_openproject_users): the core's add_users, the builder, the tool.
352
+ function add_openproject_users() {
353
+ openproject_enter_project || return 1 ;
354
+ local user user_name user_mail user_password user_fullname user_role rows="" ;
355
+ for user in "${users[@]}" ; do
356
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
357
+ user_password="user_${user}_password"; user_fullname="user_${user}_fullname"; user_role="user_${user}_role";
358
+
359
+ echo " ---------------------------------------------------------------- ";
360
+ echo " User name: ${!user_name}";
361
+ echo " User mail: ${!user_mail}";
362
+ echo " User password: ${!user_password}";
363
+ echo " User role: ${!user_role:-no membership} of ${OPENPROJECT_PROJECT_NAME}";
364
+ echo " ================================================================= ";
365
+ rows="${rows}${!user_name}"$'\x1f'"${!user_mail}"$'\x1f'"${!user_password}"$'\x1f'"${!user_fullname% *}"$'\x1f'"${!user_fullname##* }"$'\x1f''no'$'\x1f'"${!user_role}"$'\x1f'$'\x1e' ;
366
+ done
367
+ openproject_accounts_payload "${rows}" | openproject_site accounts ;
368
+ local status=$? ;
369
+ cd ${WORKSPACE_ROOT}/${doc_name};
370
+ return ${status} ;
371
+ }
372
+
373
+ # Lock the default accounts (they cannot log in any more; their work stays), never the workspace account.
374
+ function cancel_openproject_users() {
375
+ openproject_enter_project || return 1 ;
376
+ local user user_name user_mail rows="" ;
377
+ for user in "${users[@]}" ; do
378
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
379
+ echo " ---------------------------------------------------------------- ";
380
+ echo " User name: ${!user_name}";
381
+ echo " User mail: ${!user_mail}";
382
+ echo " ================================================================= ";
383
+ rows="${rows}${!user_name}"$'\x1f'"${!user_mail}"$'\x1f'$'\x1f'$'\x1f'$'\x1f''no'$'\x1f'$'\x1f''lock'$'\x1e' ;
384
+ done
385
+ openproject_accounts_payload "${rows}" | openproject_site accounts ;
386
+ local status=$? ;
387
+ cd ${WORKSPACE_ROOT}/${doc_name};
388
+ return ${status} ;
389
+ }
390
+
391
+ # Point the dashboard's OpenProject (core/config/plugin.openproject.settings.yml) at this site, as an account of it:
392
+ # a new API token of that account goes into the settings file, which only you can read, never on a screen or in a
393
+ # log; with it the site's address, and the sample project as the default one when none was set.
394
+ function openproject_connect() {
395
+ local login="$1" settings="${WORKSPACE_CONFIG}/plugin.openproject.settings.yml" out token url ;
396
+ if ! [[ "${login}" =~ ^[A-Za-z0-9._@-]+$ ]] ; then echo "--connect takes the login of an account of the site." ; return 1 ; fi
397
+ if [ ! -f "${settings}" ] ; then echo "No ${settings}: install the plugin first (plugins.sh --install openproject)." ; return 1 ; fi
398
+ out="$(printf '%s\n' "${login}" | openproject_site token 2>/dev/null)" ;
399
+ token="$(printf '%s\n' "${out}" | tr -d '\r' | sed -n 's/^TOKEN //p' | tail -n 1)" ;
400
+ out='' ;
401
+ if ! [[ "${token}" =~ ^[A-Za-z0-9_-]{20,}$ ]] ; then echo "No API token could be made for ${login} (is it an active account of the site?)." ; return 1 ; fi
402
+ url="$(openproject_url)" ;
403
+ OPENPROJECT_NEW_TOKEN="${token}" python3 - "${settings}" "${url}" "${OPENPROJECT_PROJECT}" <<'PYEOF' || return 1
404
+ import os, re, sys
405
+ path, url, project = sys.argv[1:4]
406
+ token = os.environ['OPENPROJECT_NEW_TOKEN']
407
+ text = open(path).read()
408
+ def put(text, key, value):
409
+ line = '%s: %s' % (key, value)
410
+ if re.search(r'^%s:.*$' % key, text, re.M):
411
+ return re.sub(r'^%s:.*$' % key, lambda m: line, text, count=1, flags=re.M)
412
+ return text.rstrip('\n') + '\n' + line + '\n'
413
+ text = put(text, 'url', url)
414
+ text = put(text, 'token', token)
415
+ if not re.search(r'^default_scope:[ \t]*[^ \t\n"]', text, re.M) and not re.search(r'^default_scope:[ \t]*"[^"]', text, re.M):
416
+ text = put(text, 'default_scope', project)
417
+ fd = os.open(path + '.new', os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
418
+ with os.fdopen(fd, 'w') as f:
419
+ f.write(text)
420
+ os.replace(path + '.new', path)
421
+ PYEOF
422
+ token='' ;
423
+ echo "The dashboard reads the work packages of ${url} as ${login} now: a new API token of that account is in ${settings} (not shown here), and ${OPENPROJECT_PROJECT} is the default project when none was set." ;
424
+ }
425
+
426
+ # What cmd-tools-openproject-cli.sh does: the first of --run, --add-users, --cancel-users, --sample-content, --tidy,
427
+ # --connect that was asked for; with none of them, what the site is and its accounts.
428
+ function openproject_cli_tool() {
429
+ trim_project_name ;
430
+ openproject_enter_project || exit 1 ;
431
+
432
+ if [ "$(openproject_runtime)" = 'ddev' ] ; then
433
+ ddev describe -j 2>/dev/null | grep -q '"status":"running"' || ddev start -y < /dev/null || exit 1 ;
434
+ else
435
+ ddev start < /dev/null > /dev/null 2>&1 || ddev start -y < /dev/null || exit 1 ;
436
+ fi
437
+ openproject_wait > /dev/null || { echo "OpenProject of ${PROJECT_NAME} does not answer; start it again (ddev restart in ${doc_name}/${PROJECT_NAME})." ; exit 1 ; } ;
438
+
439
+ if [ ! "${RUN}" == '_none_' ] ; then
440
+ # OpenProject's own tasks (bundle exec rake <task>), in its container, as its user.
441
+ openproject_exec "bundle exec rake ${RUN}" < /dev/null ;
442
+ exit $? ;
443
+ fi
444
+
445
+ set_openproject_users ;
446
+ if [ "${ADD_USERS}" == 'yes' ] ; then
447
+ add_openproject_users ;
448
+ elif [ "${CANCEL_USERS}" == 'yes' ] ; then
449
+ cancel_openproject_users ;
450
+ elif [ "${SAMPLE_CONTENT}" == 'yes' ] ; then
451
+ openproject_site content list < /dev/null ;
452
+ elif [ "${TIDY}" == 'yes' ] ; then
453
+ # What a test run that was stopped half way left: its work packages ("Webship test …"), with their time.
454
+ openproject_site tidy list < /dev/null ;
455
+ elif [ "${CONNECT}" != '_none_' ] ; then
456
+ openproject_connect "${CONNECT}" ;
457
+ else
458
+ echo "${doc_name}/${PROJECT_NAME}: OpenProject $(openproject_version)" ;
459
+ echo " the site: $(openproject_url)" ;
460
+ echo "" ;
461
+ openproject_site list < /dev/null ;
462
+ fi
463
+ cd ${WORKSPACE_ROOT}/${doc_name};
464
+ }
465
+
466
+ # The step pack in the testing stack of an OpenProject site. The core's testing_configure calls this in the project
467
+ # folder once webship-js is scaffolded and before the dependencies are installed; for a project that is not one of
468
+ # this plugin's it changes nothing.
469
+ #
470
+ # It adds the pack to package.json, lists its step definitions in cucumber.js after webship-js's own, gives cucumber.js
471
+ # the tags that keep the pack's assertions that must fail out of a normal run, the account that prepares and removes
472
+ # test content (manager), the project the steps work in when they name none, and the users registry of the default
473
+ # accounts (a handle a scenario reads, mapped to an account; never the workspace account), and writes a first feature
474
+ # when the project has none of its own. Every part is skipped when it is already there, so a second run adds what the
475
+ # first missed and never resets a suite.
476
+ function testing_configure_openproject() {
477
+ local project_path="$1";
478
+ openproject_is_project "${project_path}" || return 0 ;
479
+ if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
480
+ echo " OpenProject: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
481
+ return 1 ;
482
+ fi
483
+
484
+ echo "Adding the OpenProject step pack (${OPENPROJECT_STEPS_PACKAGE} ${OPENPROJECT_STEPS_VERSION}).";
485
+ set_openproject_users ;
486
+ local registry="" user user_name user_password user_fullname ;
487
+ for user in "${users[@]}" ; do
488
+ user_name="user_${user}_name"; user_password="user_${user}_password"; user_fullname="user_${user}_fullname";
489
+ registry="${registry}${user}|${!user_name}|${!user_password}|${!user_fullname}"$'\n' ;
490
+ done
491
+
492
+ local address ;
493
+ address="$(cd "${project_path}" && openproject_url "$(sed -n 's/^name:[[:space:]]*"\{0,1\}\([A-Za-z0-9._-]*\)"\{0,1\}[[:space:]]*$/\1/p' .ddev/config.yaml 2>/dev/null | head -n 1)")" ;
494
+
495
+ python3 - "${project_path}" "${OPENPROJECT_STEPS_PACKAGE}" "${OPENPROJECT_STEPS_VERSION}" 'OPENPROJECT' "${registry}" "${address}" "${OPENPROJECT_PROJECT}" <<'PYEOF' || return 1
496
+ import json, re, sys
497
+
498
+ project, pack, version, prefix, registry, address, sample = sys.argv[1:8]
499
+
500
+ # package.json: the pack as a dev dependency, at the release line this plugin was proven on.
501
+ pkg_file = project + '/package.json'
502
+ pkg = json.load(open(pkg_file))
503
+ if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
504
+ pkg.setdefault('devDependencies', {})[pack] = version
505
+ open(pkg_file, 'w').write(json.dumps(pkg, indent=4) + '\n')
506
+ print(' package.json: %s %s' % (pack, version))
507
+
508
+ cucumber_file = project + '/cucumber.js'
509
+ src = open(cucumber_file).read()
510
+ before = src
511
+
512
+ if ('node_modules/%s/' % pack) not in src:
513
+ line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
514
+ core = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
515
+ opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
516
+ if core:
517
+ src = src[:core.end()] + '\n' + core.group(1) + line + src[core.end():]
518
+ elif opening:
519
+ src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
520
+ else:
521
+ sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
522
+ print(' cucumber.js: the step definitions of %s' % pack)
523
+
524
+ if not re.search(r"^[ \t]*tags:", src, re.M):
525
+ default = re.search(r"^([ \t]*)default:[ \t]*\{[ \t]*$", src, re.M)
526
+ if default:
527
+ pad = default.group(1) + ' '
528
+ block = [
529
+ pad + "// The pack's assertions that must fail are no part of a normal run.",
530
+ pad + "tags: process.env.CUCUMBER_TAGS || 'not @wip and not @must-fail',",
531
+ ]
532
+ src = src[:default.end()] + '\n' + '\n'.join(block) + src[default.end():]
533
+ print(' cucumber.js: the tags that keep the assertions that must fail out of a normal run')
534
+
535
+ world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
536
+ if not world:
537
+ sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
538
+ pad = world.group(1) + ' '
539
+ additions = []
540
+ if not re.search(r"^[ \t]*manager:", src, re.M):
541
+ additions += [
542
+ pad + "// The account that prepares and removes test content through the site's API: a Project admin of the project.",
543
+ pad + "manager: process.env.MANAGER || 'owner',",
544
+ ]
545
+ if not re.search(r"^[ \t]*project:", src, re.M):
546
+ additions += [
547
+ pad + "// The project the steps work in when they name none (its identifier).",
548
+ pad + "project: process.env.PROJECT || '%s'," % sample,
549
+ ]
550
+ if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
551
+ rows = [r.split('|') for r in registry.splitlines() if r.strip()]
552
+ additions += [
553
+ pad + "// The users registry: a handle a scenario reads, mapped to an account of the site (the default accounts:",
554
+ pad + "// cmd-tools-openproject-cli.sh --add-users). Override one with %s_<HANDLE>_USER and %s_<HANDLE>_PASSWORD." % (prefix, prefix),
555
+ pad + "users: {",
556
+ ]
557
+ for handle, login, password, fullname in rows:
558
+ env = '%s_%s' % (prefix, handle.upper())
559
+ additions.append(pad + " %s: { username: process.env.%s_USER || '%s', password: process.env.%s_PASSWORD || '%s', name: '%s' }," % (handle, env, login, env, password, fullname))
560
+ additions.append(pad + "},")
561
+ print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
562
+ if additions:
563
+ src = src[:world.end()] + '\n' + '\n'.join(additions) + src[world.end():]
564
+ print(' cucumber.js: the managing account and the project of the steps')
565
+
566
+ # The address the suite opens when LAUNCH_URL is not set: the placeholder of the scaffold becomes the site's.
567
+ placeholder = "process.env.LAUNCH_URL || 'http://localhost:8080'"
568
+ if placeholder in src:
569
+ src = src.replace(placeholder, "process.env.LAUNCH_URL || '%s'" % address)
570
+ print(' cucumber.js: the address of the site (%s)' % address)
571
+
572
+ if src != before:
573
+ open(cucumber_file, 'w').write(src)
574
+ PYEOF
575
+
576
+ # A first feature, when the project has none for the site yet.
577
+ local feature="${WORKSPACE_SCRIPTS}/plugins/openproject/site.feature" ;
578
+ if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
579
+ mkdir -p "${project_path}/tests/features" && cp "${feature}" "${project_path}/tests/features/site.feature" \
580
+ && echo " tests/features/site.feature: a first feature for the work packages" ;
581
+ fi
582
+
583
+ # The scenarios log in as the default accounts and read the sample project: make sure the site has them, once it
584
+ # answers again (installing the testing stack may restart the project, and OpenProject with it).
585
+ if ( cd "${project_path}" && openproject_wait > /dev/null 2>&1 && add_openproject_users > /dev/null 2>&1 && openproject_site content < /dev/null > /dev/null 2>&1 ) ; then
586
+ echo " the default accounts and the sample content are on the site (${users[*]})" ;
587
+ else
588
+ echo " The default accounts could not be written: is the site running (ddev start in ${project_path})?" ;
589
+ fi
590
+ }
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # OpenProject's own server on a runtime other than DDEV (Docker Compose): the web container is the publisher's image
4
+ # with the workspace's layer, and runs this as the host user from the project's root (rt_serve) once the project's
5
+ # PostgreSQL takes connections. The database is loaded (or migrated) and seeded first, then the background worker
6
+ # starts beside the web server. Written by the OpenProject builder of the workspace; build again rather than editing.
7
+
8
+ set -a ;
9
+ # shellcheck disable=SC1091
10
+ . "$(dirname "$0")/env" || exit 1 ;
11
+ set +a ;
12
+ cd "${APP_PATH:-/app}" || exit 1 ;
13
+ ./docker/prod/migrate || exit 1 ;
14
+ ./docker/prod/seeder --skip-migrate || exit 1 ;
15
+ # The background jobs (mail, notifications, copies) beside the web server; it stops with the container.
16
+ bundle exec good_job start &
17
+ exec ./docker/prod/web