mirror of
https://github.com/ohwgiles/laminar.git
synced 2026-10-18 00:54:25 +00:00
Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab620b01e | ||
|
|
1e7e9319c3 | ||
|
|
af4b51b3e9 | ||
|
|
458ec26943 | ||
|
|
6a20291dc4 | ||
|
|
3cc01bc45d | ||
|
|
e25b58944d | ||
|
|
1be755e323 | ||
|
|
e9fc547a72 | ||
|
|
01183a3c25 | ||
|
|
e7defa9f15 | ||
|
|
99e2e62906 | ||
|
|
261c08d2fe | ||
|
|
48c0e9340e | ||
|
|
7303e4d592 | ||
|
|
23cb30fc0c | ||
|
|
7eb19ce8c4 | ||
|
|
7c4e1108ae | ||
|
|
5607a93cc1 | ||
|
|
41ddd8fe4f | ||
|
|
e581a0cf5d | ||
|
|
4a6f99a203 | ||
|
|
efafda16ff | ||
|
|
bb087b72ee | ||
|
|
37bbf6ade4 | ||
|
|
e1686d454b | ||
|
|
549f49052a | ||
|
|
d913d04c4a | ||
|
|
78ceeec3e8 | ||
|
|
ded13ed9fe | ||
|
|
15dbed4cac | ||
|
|
e67e0bc453 | ||
|
|
2de8b91ad2 | ||
|
|
399f07cf3a | ||
|
|
2941a5abdd | ||
|
|
a50514a135 | ||
|
|
60f7ee5402 | ||
|
|
7f1c293588 | ||
|
|
fe4caa155b | ||
|
|
f3a6ba2f4b | ||
|
|
dff4c93e15 | ||
|
|
747ae3ada8 | ||
|
|
9a5ccc70e3 | ||
|
|
d01cf1c9b0 | ||
|
|
02810309fc | ||
|
|
b16991b17a | ||
|
|
c7c586167c | ||
|
|
7e77ec1211 | ||
|
|
9b8c3762ec | ||
|
|
c42b6d4207 | ||
|
|
8df882b273 | ||
|
|
14ea1f0f43 | ||
|
|
381fd8b55e | ||
|
|
9f969ae847 | ||
|
|
907f3926ce | ||
|
|
c140fb51eb | ||
|
|
63bbb8a6e7 | ||
|
|
882978fa77 | ||
|
|
1a5292f141 | ||
|
|
ec237f475e | ||
|
|
5e64844440 | ||
|
|
c274e321df | ||
|
|
e442652e0a | ||
|
|
212cfaf8ab | ||
|
|
b755a2ef9e | ||
|
|
cafd0ddaee | ||
|
|
69df17d7bf | ||
|
|
308d679ea4 | ||
|
|
b851c72d53 | ||
|
|
3e993d35a0 | ||
|
|
579c192d89 | ||
|
|
4fb95fcb4f | ||
|
|
bd489bdbb0 | ||
|
|
c6b60646f6 | ||
|
|
1ea9713536 | ||
|
|
746ab24676 | ||
|
|
9862affd98 | ||
|
|
9974df21ce | ||
|
|
c774acbb98 | ||
|
|
06a5f3d8ef | ||
|
|
6d2c0b208b | ||
|
|
4b62e6dbf3 | ||
|
|
dc3e41fb28 | ||
|
|
e74332595e | ||
|
|
a793a97424 | ||
|
|
4e9c4bfb04 | ||
|
|
e29568f627 | ||
|
|
4316eb8a00 | ||
|
|
8a4992e6af |
@@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
### Copyright 2015-2020 Oliver Giles
|
### Copyright 2015-2021 Oliver Giles
|
||||||
###
|
###
|
||||||
### This file is part of Laminar
|
### This file is part of Laminar
|
||||||
###
|
###
|
||||||
@@ -17,12 +17,12 @@
|
|||||||
### along with Laminar. If not, see <http://www.gnu.org/licenses/>
|
### along with Laminar. If not, see <http://www.gnu.org/licenses/>
|
||||||
###
|
###
|
||||||
project(laminar)
|
project(laminar)
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 3.6)
|
||||||
cmake_policy(SET CMP0058 NEW)
|
|
||||||
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
add_definitions("-std=c++17 -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG")
|
||||||
|
|
||||||
# Allow passing in the version string, for e.g. patched/packaged versions
|
# Allow passing in the version string, for e.g. patched/packaged versions
|
||||||
@@ -83,16 +83,14 @@ add_custom_command(OUTPUT index_html_size.h
|
|||||||
DEPENDS src/resources/index.html)
|
DEPENDS src/resources/index.html)
|
||||||
|
|
||||||
# Download 3rd-party frontend JS libs...
|
# Download 3rd-party frontend JS libs...
|
||||||
file(DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js
|
file(DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.min.js
|
||||||
js/vue.min.js EXPECTED_MD5 ae2fca1cfa0e31377819b1b0ffef704c)
|
js/vue.min.js EXPECTED_MD5 fb192338844efe86ec759a40152fcb8e)
|
||||||
file(DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/vue-router/2.7.0/vue-router.min.js
|
file(DOWNLOAD https://raw.githubusercontent.com/drudru/ansi_up/v4.0.4/ansi_up.js
|
||||||
js/vue-router.min.js EXPECTED_MD5 5d3e35710dbe02de78c39e3e439b8d4e)
|
js/ansi_up.js EXPECTED_MD5 b31968e1a8fed0fa82305e978161f7f5)
|
||||||
file(DOWNLOAD https://raw.githubusercontent.com/drudru/ansi_up/v1.3.0/ansi_up.js
|
file(DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js
|
||||||
js/ansi_up.js EXPECTED_MD5 158566dc1ff8f2804de972f7e841e2f6)
|
js/Chart.min.js EXPECTED_MD5 7dd5ea7d2cf22a1c42b43c40093d2669)
|
||||||
file(DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js
|
|
||||||
js/Chart.min.js EXPECTED_MD5 f6c8efa65711e0cbbc99ba72997ecd0e)
|
|
||||||
# ...and compile them
|
# ...and compile them
|
||||||
generate_compressed_bins(${CMAKE_BINARY_DIR} js/vue-router.min.js js/vue.min.js
|
generate_compressed_bins(${CMAKE_BINARY_DIR} js/vue.min.js
|
||||||
js/ansi_up.js js/Chart.min.js)
|
js/ansi_up.js js/Chart.min.js)
|
||||||
# (see resources.cpp where these are fetched)
|
# (see resources.cpp where these are fetched)
|
||||||
|
|
||||||
@@ -119,13 +117,26 @@ target_link_libraries(laminard capnp-rpc capnp kj-http kj-async kj pthread sqlit
|
|||||||
add_executable(laminarc src/client.cpp src/version.cpp laminar.capnp.c++)
|
add_executable(laminarc src/client.cpp src/version.cpp laminar.capnp.c++)
|
||||||
target_link_libraries(laminarc capnp-rpc capnp kj-async kj pthread)
|
target_link_libraries(laminarc capnp-rpc capnp kj-async kj pthread)
|
||||||
|
|
||||||
|
## Manpages
|
||||||
|
macro(gzip SOURCE)
|
||||||
|
get_filename_component(OUT_FILE ${SOURCE} NAME)
|
||||||
|
add_custom_command(OUTPUT ${OUT_FILE}.gz
|
||||||
|
COMMAND gzip < ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE} > ${OUT_FILE}.gz
|
||||||
|
DEPENDS ${SOURCE})
|
||||||
|
endmacro()
|
||||||
|
add_custom_target(laminar-manpages ALL DEPENDS laminard.8.gz laminarc.1.gz)
|
||||||
|
gzip(etc/laminard.8)
|
||||||
|
gzip(etc/laminarc.1)
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/laminard.8.gz DESTINATION share/man/man8)
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/laminarc.1.gz DESTINATION share/man/man1)
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
set(BUILD_TESTS FALSE CACHE BOOL "Build tests")
|
set(BUILD_TESTS FALSE CACHE BOOL "Build tests")
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
find_package(GTest REQUIRED)
|
find_package(GTest REQUIRED)
|
||||||
include_directories(${GTEST_INCLUDE_DIRS} src)
|
include_directories(${GTEST_INCLUDE_DIRS} src)
|
||||||
add_executable(laminar-tests ${LAMINARD_CORE_SOURCES} ${COMPRESSED_BINS} test/main.cpp test/laminar-functional.cpp test/unit-conf.cpp test/unit-database.cpp)
|
add_executable(laminar-tests ${LAMINARD_CORE_SOURCES} ${COMPRESSED_BINS} test/main.cpp test/laminar-functional.cpp test/unit-conf.cpp test/unit-database.cpp)
|
||||||
target_link_libraries(laminar-tests ${GTEST_LIBRARY} capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z)
|
target_link_libraries(laminar-tests ${GTEST_LIBRARIES} capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SYSTEMD_UNITDIR /lib/systemd/system CACHE PATH "Path to systemd unit files")
|
set(SYSTEMD_UNITDIR /lib/systemd/system CACHE PATH "Path to systemd unit files")
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ See [the website](https://laminar.ohwg.net) and the [documentation](https://lami
|
|||||||
|
|
||||||
First install development packages for `capnproto (version 0.7.0 or newer)`, `rapidjson`, `sqlite` and `boost` (for the header-only `multi_index_container` library) from your distribution's repository or other source.
|
First install development packages for `capnproto (version 0.7.0 or newer)`, `rapidjson`, `sqlite` and `boost` (for the header-only `multi_index_container` library) from your distribution's repository or other source.
|
||||||
|
|
||||||
On Debian Buster, this can be done with:
|
On Debian Bullseye, this can be done with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt install \
|
sudo apt install \
|
||||||
capnproto cmake g++ libboost-dev libcapnp-dev libsqlite-dev libsqlite3-dev make rapidjson-dev zlib1g-dev
|
capnproto cmake g++ libboost-dev libcapnp-dev libsqlite3-dev rapidjson-dev zlib1g-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Then compile and install laminar with:
|
Then compile and install laminar with:
|
||||||
@@ -25,7 +25,7 @@ Then compile and install laminar with:
|
|||||||
git clone https://github.com/ohwgiles/laminar.git
|
git clone https://github.com/ohwgiles/laminar.git
|
||||||
cd laminar
|
cd laminar
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
|
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
|
||||||
make -j4
|
make -j "$(nproc)"
|
||||||
# Warning: the following will overwrite an existing /etc/laminar.conf
|
# Warning: the following will overwrite an existing /etc/laminar.conf
|
||||||
sudo make install
|
sudo make install
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -17,24 +17,26 @@ Throughout this document, the fixed base path `/var/lib/laminar` is used. This i
|
|||||||
|
|
||||||
# Installing Laminar
|
# Installing Laminar
|
||||||
|
|
||||||
Pre-built packages are available for Debian 9 (Stretch) and CentOS 7 on x86_64. Alternatively, Laminar may be built from source for any Linux distribution.
|
Since Debian Bullseye, Laminar is available in [the official repositories](https://packages.debian.org/search?searchon=sourcenames&keywords=laminar).
|
||||||
|
|
||||||
## Installation from binaries
|
Alternatively, pre-built upstream packages are available for Debian 10 (Buster) on x86_64 and armhf, and for Rocky/CentOS/RHEL 7 and 8 on x86_64.
|
||||||
|
|
||||||
Alternatively to the source-based approach shown above, precompiled packages are supplied for x86_64 Debian 9 (Stretch) and CentOS 7
|
Finally, Laminar may be built from source for any Linux distribution.
|
||||||
|
|
||||||
|
## Installation from upstream packages
|
||||||
|
|
||||||
Under Debian:
|
Under Debian:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/ohwgiles/laminar/releases/download/0.6/laminar-0.6-1-amd64.deb
|
wget https://github.com/ohwgiles/laminar/releases/download/1.1/laminar_1.1-1.upstream-debian10_amd64.deb
|
||||||
sudo apt install laminar-0.6-1-amd64.deb
|
sudo apt install ./laminar_1.1-1.upstream-debian10_amd64.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
Under CentOS:
|
Under Rocky/CentOS/RHEL:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/ohwgiles/laminar/releases/download/0.5/laminar-0.6-1.x86_64.rpm
|
wget https://github.com/ohwgiles/laminar/releases/download/1.1/laminar-1.1.upstream_rocky8-1.x86_64.rpm
|
||||||
sudo yum install laminar-0.6-1.x86_64.rpm
|
sudo dnf install ./laminar-1.1.upstream_rocky8-1.x86_64.rpm
|
||||||
```
|
```
|
||||||
|
|
||||||
Both install packages will create a new `laminar` user and install (but not activate) a systemd service for launching the laminar daemon.
|
Both install packages will create a new `laminar` user and install (but not activate) a systemd service for launching the laminar daemon.
|
||||||
@@ -52,15 +54,17 @@ You can build an image that runs `laminard` by default, and contains `laminarc`
|
|||||||
docker build [-t image:tag] -f docker/Dockerfile .
|
docker build [-t image:tag] -f docker/Dockerfile .
|
||||||
```
|
```
|
||||||
|
|
||||||
Keep in mind that this is meant to be used as a base image to build from, so it contains only the minimum packages required to run laminar. The only shell available by default is sh and it does not even have ssh or git. You can use this image to run a basic build server, but it is recommended that you build a custom image from this base to better suit your needs.
|
Keep in mind that this is meant to be used as a base image to build from, so it contains only the minimum packages required to run laminar. The only shell available by default is sh (so scripts with `#!/bin/bash` will fail to execute) and it does not have `ssh` or `git`. You can use this image to run a basic build server, but it is recommended that you build a custom image from this base to better suit your needs.
|
||||||
|
|
||||||
The container will execute `laminard` by default. To start a laminar server with docker you can simply run the image as a daemon.
|
The container will execute `laminard` by default. To start a laminar server with docker you can simply run the image as a daemon, for example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -d --name laminar_server -p 8080:8080 [-v laminardir|laminar.conf] laminar:latest
|
docker run -d --name laminar_server -p 8080:8080 -v path/to/laminardir:/var/lib/laminar --env-file path/to/laminar.conf laminar:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
You can customize laminar and persist your data by mounting your laminar directory to `/var/lib/laminar` and/or mounting a custom configuration file to `/etc/laminar.conf`.
|
The [`-v` flag](https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag) is necessary to persist job scripts and artefacts beyond the container lifetime.
|
||||||
|
|
||||||
|
The [`--env-file` flag](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) is necessary to pass configuration from `laminar.conf` to `laminard` because `laminard` does not read `/etc/laminar.conf` directly but expects variables within to be exported by `systemd` or other process supervisor.
|
||||||
|
|
||||||
Executing `laminarc` may be done in any of the usual ways, for example:
|
Executing `laminarc` may be done in any of the usual ways, for example:
|
||||||
|
|
||||||
@@ -84,7 +88,7 @@ Laminar's configuration file may be found at `/etc/laminar.conf`. Laminar will s
|
|||||||
|
|
||||||
Edit `/etc/laminar.conf` and change `LAMINAR_BIND_HTTP` to `IPADDR:PORT`, `unix:PATH/TO/SOCKET` or `unix-abstract:SOCKETNAME`. `IPADDR` may be `*` to bind on all interfaces. The default is `*:8080`.
|
Edit `/etc/laminar.conf` and change `LAMINAR_BIND_HTTP` to `IPADDR:PORT`, `unix:PATH/TO/SOCKET` or `unix-abstract:SOCKETNAME`. `IPADDR` may be `*` to bind on all interfaces. The default is `*:8080`.
|
||||||
|
|
||||||
Do not attempt to run laminar on port 80. This requires running as `root`, and Laminar will not drop privileges when executing job scripts! For a more complete integrated solution (including SSL), run laminar as a reverse proxy behind a regular webserver.
|
Do not attempt to run laminar on port 80. This requires running as `root`, and Laminar will not drop privileges when executing job scripts! For a more complete integrated solution (including SSL), run laminar behind a regular webserver acting as a reverse proxy.
|
||||||
|
|
||||||
## Running behind a reverse proxy
|
## Running behind a reverse proxy
|
||||||
|
|
||||||
@@ -92,10 +96,12 @@ A reverse proxy is required if you want Laminar to share a port with other web s
|
|||||||
|
|
||||||
If you use [artefacts](#Archiving-artefacts), note that Laminar is not designed as a file server, and better performance will be achieved by allowing the frontend web server to serve the archive directory directly (e.g. using a `Location` directive).
|
If you use [artefacts](#Archiving-artefacts), note that Laminar is not designed as a file server, and better performance will be achieved by allowing the frontend web server to serve the archive directory directly (e.g. using a `Location` directive).
|
||||||
|
|
||||||
Laminar uses Sever Sent Events to provide a responsive, auto-updating display without polling. Most frontend webservers should handle this without any extra configuration.
|
Laminar uses Server Sent Events to provide a responsive, auto-updating display without polling. Most frontend webservers should handle this without any extra configuration.
|
||||||
|
|
||||||
If you use a reverse proxy to host Laminar at a subfolder instead of a subdomain root, the `<base href>` needs to be updated to ensure all links point to their proper targets. This can be done by setting `LAMINAR_BASE_URL` in `/etc/laminar.conf`.
|
If you use a reverse proxy to host Laminar at a subfolder instead of a subdomain root, the `<base href>` needs to be updated to ensure all links point to their proper targets. This can be done by setting `LAMINAR_BASE_URL` in `/etc/laminar.conf`.
|
||||||
|
|
||||||
|
See [this example configuration file for nginx](https://github.com/ohwgiles/laminar/blob/master/examples/nginx-ssl-reverse-proxy.conf).
|
||||||
|
|
||||||
## More configuration options
|
## More configuration options
|
||||||
|
|
||||||
See the [reference section](#Service-configuration-file)
|
See the [reference section](#Service-configuration-file)
|
||||||
@@ -127,30 +133,30 @@ chmod +x /var/lib/laminar/cfg/jobs/hello.run
|
|||||||
|
|
||||||
# Triggering a run
|
# Triggering a run
|
||||||
|
|
||||||
When triggering a run, the job is first added to a queue of upcoming tasks. If the server is busy, the job may wait in this queue for a while. It will only be assigned a job number when it leaves this queue and starts executing. The job number may be useful to the client that triggers the run, so there are a few ways to trigger a run.
|
To queue execution of the `hello` job, run
|
||||||
|
|
||||||
To add the `hello` job to the queue ("fire-and-forget"), execute
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laminarc queue hello
|
laminarc queue hello
|
||||||
```
|
```
|
||||||
|
|
||||||
In this case, laminarc returns immediately, with its error code indicating whether adding the job to the queue was sucessful.
|
In this case, `laminarc` returns immediately, with its error code indicating whether adding the job to the queue was sucessful. The run number will be printed to standard output.
|
||||||
|
|
||||||
To queue the job and wait until it leaves the queue and starts executing, use
|
If the server is busy, a run may wait in the queue for some time. To have `laminarc` instead block until the run leaves the queue and starts executing, use
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laminarc start hello
|
laminarc start hello
|
||||||
```
|
```
|
||||||
|
|
||||||
In this case, laminarc blocks until the job starts executing, or returns immediately if queueing failed. The run number will be printed to standard output.
|
In this case, `laminarc` blocks until the job starts executing, or returns immediately if queueing failed. The run number will be printed to standard output.
|
||||||
|
|
||||||
To launch and run the `hello` job to completion, execute
|
Finally, to launch and run the `hello` job to completion, execute
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laminarc run hello
|
laminarc run hello
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In this case, laminarc's return value indicates whether the run completed successfully.
|
||||||
|
|
||||||
In all cases, a started run means the `/var/lib/laminar/cfg/jobs/hello.run` script will be executed, with a working directory of `/var/lib/laminar/run/hello/1` (or current run number)
|
In all cases, a started run means the `/var/lib/laminar/cfg/jobs/hello.run` script will be executed, with a working directory of `/var/lib/laminar/run/hello/1` (or current run number)
|
||||||
|
|
||||||
The result and log output should be visible in the Web UI at http://localhost:8080/jobs/hello/1
|
The result and log output should be visible in the Web UI at http://localhost:8080/jobs/hello/1
|
||||||
@@ -194,6 +200,8 @@ This is what [git hooks](https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hook
|
|||||||
LAMINAR_REASON="Push to git repository" laminarc queue example-build
|
LAMINAR_REASON="Push to git repository" laminarc queue example-build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For a more advanced example, see [examples/git-post-receive-hook-notes](https://github.com/ohwgiles/laminar/blob/master/examples/git-post-receive-hook-notes)
|
||||||
|
|
||||||
What if your git server is not the same machine as the laminar instance?
|
What if your git server is not the same machine as the laminar instance?
|
||||||
|
|
||||||
## Triggering on a remote laminar instance
|
## Triggering on a remote laminar instance
|
||||||
@@ -214,13 +222,13 @@ Then, point `laminarc` to the new location using an environment variable:
|
|||||||
LAMINAR_HOST=192.168.1.1:9997 laminarc queue example
|
LAMINAR_HOST=192.168.1.1:9997 laminarc queue example
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need more flexibility, consider running the communication channel as a regular unix socket and applying user and group permissions to the file. To achieve this, set
|
If you need more flexibility, consider running the communication channel as a regular unix socket. Setting
|
||||||
|
|
||||||
```
|
```
|
||||||
LAMINAR_BIND_RPC=unix:/var/run/laminar.sock
|
LAMINAR_BIND_RPC=unix:/var/run/laminar.sock
|
||||||
```
|
```
|
||||||
|
|
||||||
or similar path in `/etc/laminar.conf`.
|
or similar path in `/etc/laminar.conf` will result in a socket with group read/write permissions (`660`), so any user in the `laminar` group can queue a job.
|
||||||
|
|
||||||
This can be securely and flexibly combined with remote triggering using `ssh`. There is no need to allow the client full shell access to the server machine, the ssh server can restrict certain users to certain commands (in this case `laminarc`). See [the authorized_keys section of the sshd man page](https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT) for further information.
|
This can be securely and flexibly combined with remote triggering using `ssh`. There is no need to allow the client full shell access to the server machine, the ssh server can restrict certain users to certain commands (in this case `laminarc`). See [the authorized_keys section of the sshd man page](https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT) for further information.
|
||||||
|
|
||||||
@@ -238,7 +246,7 @@ Additionally, the raw log output may be fetched over a plain HTTP request to htt
|
|||||||
|
|
||||||
# Job chains
|
# Job chains
|
||||||
|
|
||||||
A typical pipeline may involve several steps, such as build, test and deploy. Depending on the project, these may be broken up into seperate laminar jobs for maximal flexibility.
|
A typical pipeline may involve several steps, such as build, test and deploy. Depending on the project, these may be broken up into separate laminar jobs for maximal flexibility.
|
||||||
|
|
||||||
The preferred way to accomplish this in Laminar is to use the same method as [regular run triggering](#Triggering-a-run), that is, calling `laminarc` directly in your `example.run` scripts.
|
The preferred way to accomplish this in Laminar is to use the same method as [regular run triggering](#Triggering-a-run), that is, calling `laminarc` directly in your `example.run` scripts.
|
||||||
|
|
||||||
@@ -364,7 +372,7 @@ fi
|
|||||||
|
|
||||||
Of course, you can make this as pretty as you like. A [helper script](#Helper-scripts) can be a good choice here.
|
Of course, you can make this as pretty as you like. A [helper script](#Helper-scripts) can be a good choice here.
|
||||||
|
|
||||||
If you want to send to different addresses dependending on the job, replace `engineering@company.com` above with a variable, e.g. `$RECIPIENTS`, and set `RECIPIENTS=nora@company.com,joe@company.com` in `/var/lib/laminar/cfg/jobs/JOB.env`. See [Environment variables](#Environment-variables).
|
If you want to send to different addresses depending on the job, replace `engineering@company.com` above with a variable, e.g. `$RECIPIENTS`, and set `RECIPIENTS=nora@company.com,joe@company.com` in `/var/lib/laminar/cfg/jobs/JOB.env`. See [Environment variables](#Environment-variables).
|
||||||
|
|
||||||
You could also update the `$RECIPIENTS` variable dynamically based on the build itself. For example, if your run script accepts a parameter `$rev` which is a git commit id, as part of your job's `.after` script you could do the following:
|
You could also update the `$RECIPIENTS` variable dynamically based on the build itself. For example, if your run script accepts a parameter `$rev` which is a git commit id, as part of your job's `.after` script you could do the following:
|
||||||
|
|
||||||
@@ -373,6 +381,8 @@ author_email=$(git show -s --format='%ae' $rev)
|
|||||||
laminarc set RECIPIENTS $author_email
|
laminarc set RECIPIENTS $author_email
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See [examples/notify-email-pretty](https://github.com/ohwgiles/laminar/blob/master/examples/notify-email-pretty) and [examples/notify-email-text-log](https://github.com/ohwgiles/laminar/blob/master/examples/notify-email-text-log).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# Helper scripts
|
# Helper scripts
|
||||||
@@ -502,19 +512,29 @@ EXECUTORS=1
|
|||||||
|
|
||||||
## Associating a job with a context
|
## Associating a job with a context
|
||||||
|
|
||||||
When trying to start a job, laminar will wait until the job can be matched to a context which has at least one free executor. You can define which contexts the job will associate with by setting, for example,
|
When trying to start a job, laminar will wait until the job can be matched to a context which has at least one free executor. There are two ways to associate jobs and contexts. You can specify a comma-separated list of patterns `JOBS` in the context configuration file `/var/lib/laminar/cfg/contexts/CONTEXT.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
JOBS=amd64-target-*,usage-monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
This approach is often preferred when you have many jobs that need to share limited resources.
|
||||||
|
|
||||||
|
Alternatively, you can set
|
||||||
|
|
||||||
```
|
```
|
||||||
CONTEXTS=my-env-*,special_context
|
CONTEXTS=my-env-*,special_context
|
||||||
```
|
```
|
||||||
|
|
||||||
in `/var/lib/laminar/cfg/jobs/JOB.conf`. For each of the patterns in the comma-separated list `CONTEXTS`, Laminar will iterate over the known contexts and associate the run with the first context with free executors. Patterns are [glob expressions](http://man7.org/linux/man-pages/man7/glob.7.html).
|
in `/var/lib/laminar/cfg/jobs/JOB.conf`. This approach is often preferred when you have a small number of jobs that require exclusive access to an environment and you can supply alternative environments (e.g. target devices), because new contexts can be added without modifying the job configuration.
|
||||||
|
|
||||||
|
In both cases, Laminar will iterate over the known contexts and associate the run with the first matching context with free executors. Patterns are [glob expressions](http://man7.org/linux/man-pages/man7/glob.7.html).
|
||||||
|
|
||||||
If `CONTEXTS` is empty or absent (or if `JOB.conf` doesn't exist), laminar will behave as if `CONTEXTS=default` were defined.
|
If `CONTEXTS` is empty or absent (or if `JOB.conf` doesn't exist), laminar will behave as if `CONTEXTS=default` were defined.
|
||||||
|
|
||||||
## Adding environment to a context
|
## Adding environment to a context
|
||||||
|
|
||||||
Append desired environment variables to `/var/lib/laminar/cfg/contexts/CONTEXT_NAME.conf`:
|
Append desired environment variables to `/var/lib/laminar/cfg/contexts/CONTEXT_NAME.env`:
|
||||||
|
|
||||||
```
|
```
|
||||||
DUT_IP=192.168.3.2
|
DUT_IP=192.168.3.2
|
||||||
@@ -574,6 +594,8 @@ docker run --rm -ti -v $PWD:/root ubuntu /bin/bash -xe <<EOF
|
|||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For more advanced usage, see [examples/docker-advanced](https://github.com/ohwgiles/laminar/blob/master/examples/docker-advanced)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# Colours in log output
|
# Colours in log output
|
||||||
@@ -691,6 +713,7 @@ Finally, variables supplied on the command-line call to `laminarc queue`, `lamin
|
|||||||
- `queue [JOB [PARAMS...]]...` adds one or more jobs to the queue with optional parameters, returning immediately.
|
- `queue [JOB [PARAMS...]]...` adds one or more jobs to the queue with optional parameters, returning immediately.
|
||||||
- `start [JOB [PARAMS...]]...` starts one or more jobs with optional parameters, returning when the jobs begin execution.
|
- `start [JOB [PARAMS...]]...` starts one or more jobs with optional parameters, returning when the jobs begin execution.
|
||||||
- `run [JOB [PARAMS...]]...` triggers one or more jobs with optional parameters and waits for the completion of all jobs.
|
- `run [JOB [PARAMS...]]...` triggers one or more jobs with optional parameters and waits for the completion of all jobs.
|
||||||
|
- `--next` may be passed before `JOB` in order to place the job at the front of the queue instead of at the end.
|
||||||
- `set [VARIABLE=VALUE]...` sets one or more variables to be exported in subsequent scripts for the run identified by the `$JOB` and `$RUN` environment variables
|
- `set [VARIABLE=VALUE]...` sets one or more variables to be exported in subsequent scripts for the run identified by the `$JOB` and `$RUN` environment variables
|
||||||
- `show-jobs` shows the known jobs on the server (`$LAMINAR_HOME/cfg/jobs/*.run`).
|
- `show-jobs` shows the known jobs on the server (`$LAMINAR_HOME/cfg/jobs/*.run`).
|
||||||
- `show-running` shows the currently running jobs with their numbers.
|
- `show-running` shows the currently running jobs with their numbers.
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Laminar continuous integration service
|
Description=Laminar continuous integration service
|
||||||
After=network.target
|
After=network.target
|
||||||
|
Documentation=man:laminard(8)
|
||||||
|
Documentation=https://laminar.ohwg.net/docs.html
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=laminar
|
User=laminar
|
||||||
EnvironmentFile=-/etc/laminar.conf
|
EnvironmentFile=-/etc/laminar.conf
|
||||||
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/laminard
|
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/laminard -v
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
74
etc/laminarc.1
Normal file
74
etc/laminarc.1
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
.Dd Apr 04, 2019
|
||||||
|
.Dt LAMINARC 1
|
||||||
|
.Sh NAME
|
||||||
|
.Nm laminarc
|
||||||
|
\-
|
||||||
|
Laminar CI client application
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm laminarc Li queue \fIJOB\fR [\fIPARAM=VALUE...\fR] ...
|
||||||
|
.Nm laminarc Li start \fIJOB\fR [\fIPARAM=VALUE...\fR] ...
|
||||||
|
.Nm laminarc Li run \fIJOB\fR [\fIPARAM=VALUE...\fR] ...
|
||||||
|
.Nm laminarc Li set \fIPARAM=VALUE...\fR
|
||||||
|
.Nm laminarc Li show-jobs
|
||||||
|
.Nm laminarc Li show-running
|
||||||
|
.Nm laminarc Li show-queued
|
||||||
|
.Nm laminarc Li abort \fIJOB\fR \fINUMBER\fR
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Nm laminarc
|
||||||
|
program connects to a Laminar server and perform one of following operations:
|
||||||
|
.Bl -tag
|
||||||
|
.It Sy queue
|
||||||
|
adds job(s) (with optional parameters) to the queue and returns immediately.
|
||||||
|
.It Sy start
|
||||||
|
adds job(s) (with optional parameters) to the queue and returns when the jobs
|
||||||
|
begin execution.
|
||||||
|
.It Sy run
|
||||||
|
adds job(s) (with optional parameters) to the queue and returns when the jobs
|
||||||
|
complete execution. The exit code will be non-zero if any of the runs does
|
||||||
|
not complete successfully.
|
||||||
|
.It \t
|
||||||
|
\fB--next\fR may be passed to \fBqueue\fR, \fBstart\fR or \fBrun\fR in order
|
||||||
|
to place the job at the front of the queue instead of at the end.
|
||||||
|
.It Sy set
|
||||||
|
sets one or more parameters to be exported as environment variables in subsequent
|
||||||
|
scripts for the run identified by the $JOB and $RUN environment variables.
|
||||||
|
This is primarily intended for use from within a job execution, where those
|
||||||
|
variables are already set by the server.
|
||||||
|
.It Sy show-jobs
|
||||||
|
list jobs known to the server.
|
||||||
|
.It Sy show-running
|
||||||
|
list the currently running jobs with their numbers.
|
||||||
|
.It Sy show-queued
|
||||||
|
list the names and numbers of the jobs waiting in the queue.
|
||||||
|
.It Sy abort
|
||||||
|
manually abort a currently running job by name and number.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The laminar server to connect to is read from the
|
||||||
|
.Ev LAMINAR_HOST
|
||||||
|
environment variable. If empty, it falls back to
|
||||||
|
.Ev LAMINAR_BIND_RPC
|
||||||
|
and finally defaults to
|
||||||
|
.Ad unix-abstract:laminar
|
||||||
|
.Sh ENVIRONMENT
|
||||||
|
.Bl -tag
|
||||||
|
.It Ev LAMINAR_HOST
|
||||||
|
address of server to connect. May be of the form
|
||||||
|
.Ad IP:PORT,
|
||||||
|
.Ad unix:PATH/TO/SOCKET
|
||||||
|
or
|
||||||
|
.Ad unix-abstract:NAME
|
||||||
|
.It Ev LAMINAR_BIND_RPC
|
||||||
|
fallback server address variable. It is set by
|
||||||
|
.Nm laminard
|
||||||
|
during execution of scripts.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr laminard 8
|
||||||
|
.Sh AUTHORS
|
||||||
|
.An Oliver Giles
|
||||||
|
created Laminar CI.
|
||||||
|
.An Dmitry Bogatov
|
||||||
|
created this manual page for the Debian project (but it can be used
|
||||||
|
by others).
|
||||||
56
etc/laminard.8
Normal file
56
etc/laminard.8
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
.Dd Apr 03, 2019
|
||||||
|
.Dt LAMINARD 1
|
||||||
|
.Sh NAME
|
||||||
|
.Nm laminard
|
||||||
|
\-
|
||||||
|
Laminar CI server
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm laminard Op Fl v
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
Start Laminar CI server in the foreground. If option
|
||||||
|
.Fl v
|
||||||
|
is specified, verbose logging is enabled. Other aspects of
|
||||||
|
operation are controlled by environment variables.
|
||||||
|
.Sh ENVIRONMENT
|
||||||
|
.Bl -tag
|
||||||
|
.It Ev LAMINAR_HOME
|
||||||
|
Root location containing laminar configuration, database, build
|
||||||
|
workspaces and archive.
|
||||||
|
.Pp
|
||||||
|
Default: /var/lib/laminar
|
||||||
|
.It Ev LAMINAR_BIND_HTTP
|
||||||
|
Interface on which laminard will bind to serve the Web UI.
|
||||||
|
May be of the form IP:PORT, unix:PATH/TO/SOCKET or unix-abstract:NAME
|
||||||
|
.Pp
|
||||||
|
Default: *:8080
|
||||||
|
.It Ev LAMINAR_BIND_HRPC
|
||||||
|
Interface on which laminard will bind to accept RPC from laminarc.
|
||||||
|
May be of the form IP:PORT, unix:PATH/TO/SOCKET or unix-abstract:NAME
|
||||||
|
.Pp
|
||||||
|
Default: unix-abstract:laminar
|
||||||
|
.It Ev LAMINAR_TITLE
|
||||||
|
Page title to show in web frontend
|
||||||
|
.It Ev LAMINAR_KEEP_RUNDIRS
|
||||||
|
Setting this prevents the immediate deletion of job rundirs
|
||||||
|
$LAMINAR_HOME/run/$JOB/$RUN. Value should be an integer represeting
|
||||||
|
the number of rundirs to keep.
|
||||||
|
.Pp
|
||||||
|
Default: 0
|
||||||
|
.It Ev LAMINAR_ARCHIVE_URL
|
||||||
|
Base url used to request artifacts. Laminar can serve build artifacts
|
||||||
|
(and it will if you leave this unset), but it uses a very naive and
|
||||||
|
inefficient method. Best to let a real webserver handle serving those
|
||||||
|
requests.
|
||||||
|
.El
|
||||||
|
.Sh FILES
|
||||||
|
.Bl -tag
|
||||||
|
.It Pa /etc/laminar.conf
|
||||||
|
Variable assignments in this file are exported by systemd or other
|
||||||
|
init system before launching the system-wide installation of Laminar.
|
||||||
|
.El
|
||||||
|
.Sh AUTHORS
|
||||||
|
.An Oliver Giles
|
||||||
|
created Laminar CI.
|
||||||
|
.An Dmitry Bogatov
|
||||||
|
created this manual page for Debian project (but it can be used
|
||||||
|
by others).
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cat <<EOF
|
|
||||||
<!doctype html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>Laminar</title>
|
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="col-xs-12">
|
|
||||||
<h2>Test report for $lJobName #$lBuildNum</h2>
|
|
||||||
EOF
|
|
||||||
xsltproc "$(dirname ${BASH_SOURCE[0]})/testreport.xsl" "$1";
|
|
||||||
cat <<EOF
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
EOF
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
||||||
<xsl:output method="html" indent="no"/>
|
|
||||||
<xsl:template match="testsuite">
|
|
||||||
<h3>Test Suite: <xsl:value-of select="@name" /></h3>
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>Tests run:</dt><dd><xsl:value-of select="@tests" /></dd>
|
|
||||||
<dt>Failures:</dt><dd><xsl:value-of select="@failures" /></dd>
|
|
||||||
<dt>Errors:</dt><dd><xsl:value-of select="@errors" /></dd>
|
|
||||||
<dt>Elapsed time:</dt><dd><xsl:value-of select="@time" /></dd>
|
|
||||||
</dl>
|
|
||||||
<ul class="list-group">
|
|
||||||
<xsl:apply-templates select="testcase" />
|
|
||||||
</ul>
|
|
||||||
<xsl:apply-templates select="system-out" />
|
|
||||||
<xsl:apply-templates select="system-err" />
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<xsl:template match="testcase">
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="*">
|
|
||||||
<li class="list-group-item list-group-item-danger"><xsl:value-of select="@name" />
|
|
||||||
<xsl:apply-templates select="failure" />
|
|
||||||
</li>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<li class="list-group-item list-group-item-success"><xsl:value-of select="@name" /></li>
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<xsl:template match="failure">
|
|
||||||
<pre>
|
|
||||||
<xsl:value-of select="@message"/>
|
|
||||||
</pre>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<xsl:template match="system-out"><h5>Standard output:</h5><pre><xsl:value-of select="." /></pre></xsl:template>
|
|
||||||
<xsl:template match="system-err"><h5>Standard error:</h5><pre><xsl:value-of select="." /></pre></xsl:template>
|
|
||||||
|
|
||||||
</xsl:stylesheet>
|
|
||||||
|
|
||||||
53
examples/docker-advanced
Executable file
53
examples/docker-advanced
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
# Any failing command in a pipe will cause an error, instead
|
||||||
|
# of just an error in the last command in the pipe
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Log commands executed
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# Simple way of getting the docker build tag:
|
||||||
|
tag=$(docker build -q - <<\EOF
|
||||||
|
FROM debian:bullseye
|
||||||
|
RUN apt-get update && apt-get install -y build-essential
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# But -q suppresses the log output. If you want to keep it,
|
||||||
|
# you could use the following fancier way:
|
||||||
|
|
||||||
|
exec {pfd}<><(:) # get a new pipe
|
||||||
|
docker build - <<\EOF |
|
||||||
|
FROM debian:bullseye
|
||||||
|
RUN apt-get update && apt-get install -y build-essential
|
||||||
|
EOF
|
||||||
|
tee >(awk '/Successfully built/{print $3}' >&$pfd) # parse output to pipe
|
||||||
|
read tag <&$pfd # read tag back from pipe
|
||||||
|
exec {pfd}<&- # close pipe
|
||||||
|
|
||||||
|
# Alternatively, you can use the -t option to docker build
|
||||||
|
# to give the built image a name to refer to later. But then
|
||||||
|
# you need to ensure that it does not conflict with any other
|
||||||
|
# images, and handle cases where multiple instances of the
|
||||||
|
# job attempt to update the tagged image.
|
||||||
|
|
||||||
|
# If you want the image to be cleaned up on exit:
|
||||||
|
trap "docker rmi $tag" EXIT
|
||||||
|
|
||||||
|
# Now use the image to build something:
|
||||||
|
docker run -i --rm \
|
||||||
|
-v "$PWD:$PWD" \
|
||||||
|
-w "$PWD" \
|
||||||
|
-u $(id -u):$(id -g) \
|
||||||
|
$tag /bin/bash -eux \
|
||||||
|
<<EOF
|
||||||
|
# The passed options mean we keep our current working
|
||||||
|
# directory and user, so no permission problems on the
|
||||||
|
# artifacts produced within the container.
|
||||||
|
echo 'main(){puts("hello world");}' | gcc -x c -static -o hello -
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Test the result
|
||||||
|
./hello
|
||||||
|
|
||||||
117
examples/format-test-results
Executable file
117
examples/format-test-results
Executable file
@@ -0,0 +1,117 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This example script takes the XML output of a gtest run and formats
|
||||||
|
# it as HTML. It can easily be adapted to other XML test output formats
|
||||||
|
# such as JUnit or CTest
|
||||||
|
|
||||||
|
# Prepare xml with ./path/to/test --gtest_output=xml:path/to/output.xml
|
||||||
|
|
||||||
|
# Usage: format-test-results test_result.xml > output.html
|
||||||
|
|
||||||
|
if [ ! -f "$1" ]; then
|
||||||
|
echo "File not found: \"$1\""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
xsltproc --stringparam JOB $JOB --stringparam RUN $RUN <(cat <<\EOF
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||||
|
<xsl:output method="html" indent="yes" />
|
||||||
|
|
||||||
|
<xsl:template match="/">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Test report for <xsl:value-of select="$JOB" /> #<xsl:value-of select="$RUN" /></title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Helvetica Neue, Helvetica, Arial, sans-serif; }
|
||||||
|
label:hover { cursor: pointer; }
|
||||||
|
label:before { content: '+ ' }
|
||||||
|
input[type=checkbox].toggle-collapse { display: none; }
|
||||||
|
input[type=checkbox].toggle-collapse~.collapsible { display: none; }
|
||||||
|
input[type=checkbox].toggle-collapse:checked~.collapsible { display: block; }
|
||||||
|
code { white-space: pre-wrap; color: white; }
|
||||||
|
.failure { background-color: #c73030; color: white; }
|
||||||
|
table { min-width: 720px; border-collapse: collapse; }
|
||||||
|
td, th { padding: 5px; }
|
||||||
|
tr:nth-child(even) td { padding: 0; }
|
||||||
|
tr:nth-child(even) { border-bottom: 1px solid #b3abab; }
|
||||||
|
.testcase { padding: 5px; }
|
||||||
|
.testcase.success:before { content: '✔ '; color: green; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1><xsl:value-of select="$JOB" /> #<xsl:value-of select="$RUN" /></h1>
|
||||||
|
<h2>Test Report</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Suite</th>
|
||||||
|
<th>Tests run</th>
|
||||||
|
<th>Failures</th>
|
||||||
|
<th>Errors</th>
|
||||||
|
<th>Elapsed time</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<xsl:apply-templates select="testsuites" />
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="testsuite">
|
||||||
|
<xsl:variable name="result">
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="(@failures > 0) or (@errors > 0)">failure</xsl:when>
|
||||||
|
<xsl:otherwise>success</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
</xsl:variable>
|
||||||
|
<tr class="{$result}">
|
||||||
|
<td>
|
||||||
|
<label for="suite-{@name}"><xsl:value-of select="@name" /></label>
|
||||||
|
</td>
|
||||||
|
<td><xsl:value-of select="@tests" /></td>
|
||||||
|
<td><xsl:value-of select="@failures" /></td>
|
||||||
|
<td><xsl:value-of select="@errors" /></td>
|
||||||
|
<td><xsl:value-of select="@time" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="toggle-target">
|
||||||
|
<td colspan="5">
|
||||||
|
<input class="toggle-collapse" id="suite-{@name}" type="checkbox" />
|
||||||
|
<div class="collapsible" style="padding-left: 15px;">
|
||||||
|
<xsl:apply-templates select="testcase" />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="testcase">
|
||||||
|
<xsl:choose>
|
||||||
|
<!-- has child nodes? -->
|
||||||
|
<xsl:when test="*">
|
||||||
|
<div class="testcase failure">
|
||||||
|
<xsl:value-of select="@name" /><br />
|
||||||
|
<xsl:apply-templates select="failure" />
|
||||||
|
</div>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:otherwise>
|
||||||
|
<div class="testcase success">
|
||||||
|
<xsl:value-of select="@name" />
|
||||||
|
</div>
|
||||||
|
</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="failure">
|
||||||
|
<div style="padding: 5px; background-color: #313235">
|
||||||
|
<code>
|
||||||
|
<xsl:value-of select="@message"/>
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
) "$1"
|
||||||
42
examples/git-post-receive-hook-notes
Executable file
42
examples/git-post-receive-hook-notes
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
# Simple post-receive hook that triggers a laminar run
|
||||||
|
# for every commit pushed to every branch, and annotates
|
||||||
|
# the commit with the run number using a git note.
|
||||||
|
# On the cloned repository, useful config is
|
||||||
|
# git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*"
|
||||||
|
# to automatically fetch all notes from the origin, and
|
||||||
|
# git config --add notes.displayRef "refs/notes/*"
|
||||||
|
# to display all notes in the git log by default
|
||||||
|
|
||||||
|
# The laminar job to trigger
|
||||||
|
LAMINAR_JOB=my-project
|
||||||
|
|
||||||
|
# Default notes ref is refs/notes/commits
|
||||||
|
NOTES_REF=refs/notes/ci
|
||||||
|
|
||||||
|
# For each ref pushed...
|
||||||
|
while read old new ref; do
|
||||||
|
# Skip tags, notes, etc. Only do heads.
|
||||||
|
# Extend this to only trigger on specific branches.
|
||||||
|
if [[ $ref != refs/heads/* ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# Otherwise, for each new commit in the ref...
|
||||||
|
# (to only trigger on the newest, set commit=$new and delete the loop)
|
||||||
|
git rev-list $([[ $old =~ ^0+$ ]] && echo $new || echo $old..$new) | while read commit; do
|
||||||
|
# Queue the laminar run
|
||||||
|
run=$(laminarc queue $LAMINAR_JOB commit=$commit ref=$ref)
|
||||||
|
echo "Started Laminar $run for commit $commit to ref $ref"
|
||||||
|
|
||||||
|
# Add a git note about the run
|
||||||
|
blob=$(echo -n "Laminar-Run: $run" | git hash-object -w --stdin)
|
||||||
|
if last_note=$(git show-ref -s $NOTES_REF); then
|
||||||
|
git read-tree $last_note
|
||||||
|
p_arg=-p
|
||||||
|
fi
|
||||||
|
git update-index --add --cacheinfo 100644 $blob $commit
|
||||||
|
tree=$(git write-tree)
|
||||||
|
new_note=$(echo "Notes added by post-receive hook" | git commit-tree $tree $p_arg $last_note)
|
||||||
|
git update-ref $NOTES_REF $new_note $last_note
|
||||||
|
done
|
||||||
|
done
|
||||||
52
examples/nginx-ssl-reverse-proxy.conf
Normal file
52
examples/nginx-ssl-reverse-proxy.conf
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
server {
|
||||||
|
listen [::]:80;
|
||||||
|
listen 80;
|
||||||
|
server_name laminar.example.com;
|
||||||
|
|
||||||
|
# rule for letsencrypt ACME challenge requests
|
||||||
|
location ^~ /.well-known/acme-challenge/ {
|
||||||
|
default_type "text/plain";
|
||||||
|
alias /srv/www/acme-challenge/;
|
||||||
|
}
|
||||||
|
|
||||||
|
# redirect all other http to https
|
||||||
|
return 301 https://$server_name$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
# http2 is recommended because browsers will only open a small number of concurrent SSE streams over http1
|
||||||
|
listen [::]:443 ssl http2;
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name laminar.example.com;
|
||||||
|
|
||||||
|
# modern tls only, see https://syslink.pl/cipherlist/ for a more complete example
|
||||||
|
ssl_protocols TLSv1.3;
|
||||||
|
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
|
||||||
|
|
||||||
|
# set according to ACME/letsencrypt client
|
||||||
|
ssl_certificate /path/to/certificate.crt;
|
||||||
|
ssl_certificate_key /path/to/private.key;
|
||||||
|
|
||||||
|
# use "location /" if laminar is to be accessible at the (sub)domain root.
|
||||||
|
# alteratively, use a subdirectory such as "location /my-laminar/" and ensure that
|
||||||
|
# LAMINAR_BASE_URL=/my-laminar/ accordingly.
|
||||||
|
location / {
|
||||||
|
# set proxy_pass according to LAMINAR_BIND_HTTP.
|
||||||
|
# note that the laminar default for LAMINAR_BIND_HTTP is *:8080, which binds on all interfaces
|
||||||
|
# instead of just the loopback device and is almost certainly not what you want if you are using
|
||||||
|
# a reverse proxy. It should be set to 127.0.0.1:8080 at a minimum, or use unix sockets for more
|
||||||
|
# fine-grained control of permissions.
|
||||||
|
# see http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
|
||||||
|
# and https://laminar.ohwg.net/docs.html#Running-on-a-different-HTTP-port-or-Unix-socket
|
||||||
|
proxy_pass http://127.0.0.1:8080/;
|
||||||
|
|
||||||
|
# required to allow laminar's SSE stream to pass correctly
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Connection "";
|
||||||
|
}
|
||||||
|
|
||||||
|
# have nginx serve artefacts directly rather than having laminard do it
|
||||||
|
location /archive/ {
|
||||||
|
alias /var/lib/laminar/archive/;
|
||||||
|
}
|
||||||
|
}
|
||||||
55
examples/notify-email-pretty
Executable file
55
examples/notify-email-pretty
Executable file
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# IMPORTANT: change these to appropriate values, or fetch them, for example
|
||||||
|
# from the environment or from $(git show -s --format='%ae' $rev)
|
||||||
|
TO_EMAIL=engineering@example.com
|
||||||
|
FROM_EMAIL=laminar@example.com
|
||||||
|
|
||||||
|
LAMINAR_URL=${LAMINAR_BASE_URL:-http://localhost:8080}
|
||||||
|
LAMINAR_TITLE=${LAMINAR_TITLE:-Laminar CI}
|
||||||
|
|
||||||
|
if [[ $RESULT = "success" ]]; then
|
||||||
|
SVGICON=$(cat <<-EOF
|
||||||
|
<svg viewBox="0 0 100 100" width="24px">
|
||||||
|
<path fill="#74af77" d="m 23,46 c -6,0 -17,3 -17,11 0,8 9,30 12,32 3,2 14,5 20,-2 6,-6 24,-36
|
||||||
|
56,-71 5,-3 -9,-8 -23,-2 -13,6 -33,42 -41,47 -6,-3 -5,-12 -8,-15 z" />
|
||||||
|
</svg>
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
else
|
||||||
|
SVGICON=$(cat <<-EOF
|
||||||
|
<svg viewBox="0 0 100 100" width="24px">
|
||||||
|
<path fill="#883d3d" d="m 19,20 c 2,8 12,29 15,32 -5,5 -18,21 -21,26 2,3 8,15 11,18 4,-6 17,-21
|
||||||
|
21,-26 5,5 11,15 15,20 8,-2 15,-9 20,-15 -3,-3 -17,-18 -20,-24 3,-5 23,-26 30,-33 -3,-5 -8,-9
|
||||||
|
-12,-12 -6,5 -26,26 -29,30 -6,-8 -11,-15 -15,-23 -3,0 -12,5 -15,7 z" />
|
||||||
|
</svg>
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
sendmail -t <<EOF
|
||||||
|
From: $FROM_EMAIL
|
||||||
|
To: $TO_EMAIL
|
||||||
|
Subject: $JOB #$RUN: $RESULT
|
||||||
|
Mime-Version: 1.0
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
|
<body bgcolor="#efefef" style="margin: 0; font-family: Helvetica Neue, Helvetica, Arial, sans-serif">
|
||||||
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr><td align="center">
|
||||||
|
<table border="0" cellspacing="0" cellpadding="15" bgcolor="#ffffff">
|
||||||
|
<tr bgcolor="#2f3340">
|
||||||
|
<td style="font-size: 28px; color: #ffffff;">$LAMINAR_TITLE</td></tr>
|
||||||
|
<tr>
|
||||||
|
<td style="font-size: 26px">
|
||||||
|
$SVGICON
|
||||||
|
<a href="$LAMINAR_URL/jobs/$JOB/$RUN">$JOB #$RUN</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOF
|
||||||
18
examples/notify-email-text-log
Executable file
18
examples/notify-email-text-log
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# IMPORTANT: change these to appropriate values, or fetch them, for example
|
||||||
|
# from the environment or from $(git show -s --format='%ae' $rev)
|
||||||
|
TO_EMAIL=engineering@example.com
|
||||||
|
FROM_EMAIL=laminar@example.com
|
||||||
|
|
||||||
|
LAMINAR_URL=${LAMINAR_BASE_URL:-http://localhost:8080}
|
||||||
|
|
||||||
|
sendmail -t <<EOF
|
||||||
|
From: $FROM_EMAIL
|
||||||
|
To: $TO_EMAIL
|
||||||
|
Subject: $JOB #$RUN: $RESULT
|
||||||
|
Mime-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
$(curl -s $LAMINAR_URL/log/$JOB/$RUN)
|
||||||
|
EOF
|
||||||
18
examples/notify-telegram
Executable file
18
examples/notify-telegram
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# Sends a message from a specified bot to a specific telegram chat ID.
|
||||||
|
# See https://core.telegram.org/bots
|
||||||
|
|
||||||
|
# IMPORTANT: modify this to your real bot token and chat ID
|
||||||
|
BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
|
||||||
|
CHAT_ID=10000000
|
||||||
|
|
||||||
|
LAMINAR_URL=${LAMINAR_BASE_URL:-http://localhost:8080}
|
||||||
|
|
||||||
|
[[ $(curl -sS https://api.telegram.org/bot$BOT_TOKEN/sendMessage \
|
||||||
|
-d chat_id=$CHAT_ID \
|
||||||
|
-d parse_mode=HTML \
|
||||||
|
-d text="<a href=\"$LAMINAR_URL/jobs/$JOB/$RUN\">$JOB #$RUN</a> $RESULT" \
|
||||||
|
| jq .ok) == true ]]
|
||||||
|
|
||||||
|
|
||||||
46
examples/plot-build-time-dist
Executable file
46
examples/plot-build-time-dist
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env gnuplot
|
||||||
|
|
||||||
|
# Deeper insights can be obtained by querying Laminar's database directly.
|
||||||
|
# This example uses gnuplot to create a graph of the distribution of the
|
||||||
|
# average run time of jobs.
|
||||||
|
|
||||||
|
# The following will output a png...
|
||||||
|
set terminal pngcairo size 800,580 enhanced font 'Helvetica,10'
|
||||||
|
set output 'build-time-distribution.png'
|
||||||
|
# ..comment it out to use an interactive widget
|
||||||
|
|
||||||
|
# plot style
|
||||||
|
set tics font "Helvetica,10"
|
||||||
|
set title font "Helvetica,11"
|
||||||
|
set xtics nomirror
|
||||||
|
set ytics nomirror
|
||||||
|
set border 3 back lt 1 lc rgb "#808080"
|
||||||
|
set grid back lt 0 lc rgb "#d0d0d0" lw 0.5
|
||||||
|
set style line 1 lt 1 lc rgb "#7483af" lw 2
|
||||||
|
|
||||||
|
# Fetch the path to Laminar's sqlite database
|
||||||
|
db = system("echo $LAMINAR_HOME") . '/laminar.sqlite'
|
||||||
|
|
||||||
|
# Label the axes
|
||||||
|
set xtics ("<30s" 0, "30s-1m" 1, "1m-5m" 2, "5m-10m" 3, "10m-20m" 4, "20m-40m" 5, "40m-60m" 6, ">60m" 7)
|
||||||
|
set ylabel "Number of jobs"
|
||||||
|
set xlabel "Average run time"
|
||||||
|
set title "Distribution of average run times"
|
||||||
|
|
||||||
|
plot '< sqlite3 -separator $''\n'' ' . db . ' \
|
||||||
|
"WITH ba AS (SELECT name,AVG(completedAt-startedAt) a FROM builds GROUP BY name) SELECT \
|
||||||
|
COUNT(CASE WHEN a < 30 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 30 AND a < 60 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 60 AND a < 300 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 300 AND a < 600 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 600 AND a < 1200 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 1200 AND a < 2400 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 2400 AND a < 3600 THEN 1 END), \
|
||||||
|
COUNT(CASE WHEN a >= 3600 THEN 1 END) FROM ba;"' \
|
||||||
|
using 0:1 with linespoints title '' ls 1
|
||||||
|
|
||||||
|
# uncomment this if using an interactive window
|
||||||
|
#pause mouse close
|
||||||
|
|
||||||
|
# Release the output
|
||||||
|
set output
|
||||||
@@ -68,6 +68,8 @@ make
|
|||||||
%config(noreplace) %{_sysconfdir}/laminar.conf
|
%config(noreplace) %{_sysconfdir}/laminar.conf
|
||||||
%{_datarootdir}/bash-completion/completions/laminarc
|
%{_datarootdir}/bash-completion/completions/laminarc
|
||||||
%{_datarootdir}/zsh/site-functions/_laminarc
|
%{_datarootdir}/zsh/site-functions/_laminarc
|
||||||
|
%{_mandir}/man8/laminard.8.gz
|
||||||
|
%{_mandir}/man1/laminarc.1.gz
|
||||||
|
|
||||||
%post
|
%post
|
||||||
echo Creating laminar user with home in %{_sharedstatedir}/laminar
|
echo Creating laminar user with home in %{_sharedstatedir}/laminar
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ OUTPUT_DIR=$PWD
|
|||||||
|
|
||||||
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
||||||
|
|
||||||
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty)-1~upstream-debian10
|
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty)-1~upstream-debian11
|
||||||
|
|
||||||
DOCKER_TAG=$(docker build -q - <<EOS
|
DOCKER_TAG=$(docker build -q - <<EOS
|
||||||
FROM debian:10-slim
|
FROM debian:11-slim
|
||||||
RUN apt-get update && apt-get install -y wget cmake g++ capnproto libcapnp-dev rapidjson-dev libsqlite3-dev libboost-dev zlib1g-dev
|
RUN apt-get update && apt-get install -y wget cmake g++ capnproto libcapnp-dev rapidjson-dev libsqlite3-dev libboost-dev zlib1g-dev
|
||||||
EOS
|
EOS
|
||||||
)
|
)
|
||||||
@@ -4,10 +4,10 @@ OUTPUT_DIR=$PWD
|
|||||||
|
|
||||||
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
||||||
|
|
||||||
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty)-1~upstream-debian10
|
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty)-1~upstream-debian11
|
||||||
|
|
||||||
DOCKER_TAG=$(docker build -q - <<EOS
|
DOCKER_TAG=$(docker build -q - <<EOS
|
||||||
FROM debian:10-slim
|
FROM debian:11-slim
|
||||||
RUN dpkg --add-architecture armhf && apt-get update && apt-get install -y wget cmake crossbuild-essential-armhf capnproto libcapnp-dev:armhf rapidjson-dev libsqlite3-dev:armhf libboost-dev:armhf zlib1g-dev:armhf
|
RUN dpkg --add-architecture armhf && apt-get update && apt-get install -y wget cmake crossbuild-essential-armhf capnproto libcapnp-dev:armhf rapidjson-dev libsqlite3-dev:armhf libboost-dev:armhf zlib1g-dev:armhf
|
||||||
EOS
|
EOS
|
||||||
)
|
)
|
||||||
@@ -4,11 +4,11 @@ OUTPUT_DIR=$PWD
|
|||||||
|
|
||||||
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
SOURCE_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)
|
||||||
|
|
||||||
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty | tr - .)~upstream_centos8
|
VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty | tr - .)~upstream_rocky8
|
||||||
|
|
||||||
DOCKER_TAG=$(docker build -q - <<EOS
|
DOCKER_TAG=$(docker build -q - <<EOS
|
||||||
FROM centos:8
|
FROM rockylinux/rockylinux:8
|
||||||
RUN dnf -y install rpm-build cmake make gcc-c++ wget sqlite-devel boost-devel zlib-devel
|
RUN dnf -y update && dnf -y install rpm-build cmake make gcc-c++ wget sqlite-devel boost-devel zlib-devel
|
||||||
EOS
|
EOS
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ tar xzf capnproto.tar.gz
|
|||||||
tar xzf rapidjson.tar.gz
|
tar xzf rapidjson.tar.gz
|
||||||
|
|
||||||
cd /build/capnproto-0.7.0/c++/
|
cd /build/capnproto-0.7.0/c++/
|
||||||
cmake3 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=off .
|
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=off .
|
||||||
make -j4
|
make -j4
|
||||||
make install
|
make install
|
||||||
|
|
||||||
@@ -65,6 +65,8 @@ make
|
|||||||
%config(noreplace) %{_sysconfdir}/laminar.conf
|
%config(noreplace) %{_sysconfdir}/laminar.conf
|
||||||
%{_datarootdir}/bash-completion/completions/laminarc
|
%{_datarootdir}/bash-completion/completions/laminarc
|
||||||
%{_datarootdir}/zsh/site-functions/_laminarc
|
%{_datarootdir}/zsh/site-functions/_laminarc
|
||||||
|
%{_mandir}/man8/laminard.8.gz
|
||||||
|
%{_mandir}/man1/laminarc.1.gz
|
||||||
|
|
||||||
%post
|
%post
|
||||||
echo Creating laminar user with home in %{_sharedstatedir}/laminar
|
echo Creating laminar user with home in %{_sharedstatedir}/laminar
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2020 Oliver Giles
|
/// Copyright 2015-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -87,14 +87,16 @@ static void printTriggerLink(const char* job, uint run) {
|
|||||||
|
|
||||||
static void usage(std::ostream& out) {
|
static void usage(std::ostream& out) {
|
||||||
out << "laminarc version " << laminar_version() << "\n";
|
out << "laminarc version " << laminar_version() << "\n";
|
||||||
out << "Usage: laminarc [-h|--help] COMMAND [PARAMETERS...]]\n";
|
out << "Usage: laminarc [-h|--help] COMMAND\n";
|
||||||
out << " -h|--help show this help message\n";
|
out << " -h|--help show this help message\n";
|
||||||
out << "where COMMAND is:\n";
|
out << "where COMMAND is:\n";
|
||||||
out << " queue JOB_LIST... queues one or more jobs for execution and returns immediately.\n";
|
out << " queue JOB_LIST... queues one or more jobs for execution and returns immediately.\n";
|
||||||
out << " start JOB_LIST... queues one or more jobs for execution and blocks until it starts.\n";
|
out << " start JOB_LIST... queues one or more jobs for execution and blocks until it starts.\n";
|
||||||
out << " run JOB_LIST... queues one or more jobs for execution and blocks until it finishes.\n";
|
out << " run JOB_LIST... queues one or more jobs for execution and blocks until it finishes.\n";
|
||||||
|
out << " JOB_LIST may be prepended with --next, in this case the job will\n";
|
||||||
|
out << " be pushed to the front of the queue instead of the end.\n";
|
||||||
out << " set PARAMETER_LIST... sets the given parameters as environment variables in the currently\n";
|
out << " set PARAMETER_LIST... sets the given parameters as environment variables in the currently\n";
|
||||||
out << " runing job. Fails if run outside of a job context.\n";
|
out << " running job. Fails if run outside of a job context.\n";
|
||||||
out << " abort NAME NUMBER aborts the run identified by NAME and NUMBER.\n";
|
out << " abort NAME NUMBER aborts the run identified by NAME and NUMBER.\n";
|
||||||
out << " show-jobs lists all known jobs.\n";
|
out << " show-jobs lists all known jobs.\n";
|
||||||
out << " show-queued lists currently queued jobs.\n";
|
out << " show-queued lists currently queued jobs.\n";
|
||||||
@@ -132,38 +134,40 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
auto& waitScope = client.getWaitScope();
|
auto& waitScope = client.getWaitScope();
|
||||||
|
|
||||||
if(strcmp(argv[1], "queue") == 0) {
|
int jobNameIndex = 2;
|
||||||
if(argc < 3) {
|
bool frontOfQueue = false;
|
||||||
fprintf(stderr, "Usage %s queue <jobName>\n", argv[0]);
|
|
||||||
|
if(strcmp(argv[1], "queue") == 0 || strcmp(argv[1], "start") == 0 || strcmp(argv[1], "run") == 0) {
|
||||||
|
if(argc < 3 || (strcmp(argv[2], "--next") == 0 && argc < 4)) {
|
||||||
|
fprintf(stderr, "Usage %s %s JOB_LIST...\n", argv[0], argv[1]);
|
||||||
return EXIT_BAD_ARGUMENT;
|
return EXIT_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
int jobNameIndex = 2;
|
if(strcmp(argv[2], "--next") == 0) {
|
||||||
// make a request for each job specified on the commandline
|
frontOfQueue = true;
|
||||||
|
jobNameIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(argv[1], "queue") == 0) {
|
||||||
do {
|
do {
|
||||||
auto req = laminar.queueRequest();
|
auto req = laminar.queueRequest();
|
||||||
req.setJobName(argv[jobNameIndex]);
|
req.setJobName(argv[jobNameIndex]);
|
||||||
|
req.setFrontOfQueue(frontOfQueue);
|
||||||
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
||||||
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::QueueResults> resp){
|
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::QueueResults> resp){
|
||||||
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
||||||
fprintf(stderr, "Failed to queue job '%s'\n", argv[jobNameIndex]);
|
fprintf(stderr, "Failed to queue job '%s'\n", argv[jobNameIndex]);
|
||||||
ret = EXIT_OPERATION_FAILED;
|
ret = EXIT_OPERATION_FAILED;
|
||||||
}
|
} else
|
||||||
|
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
||||||
}));
|
}));
|
||||||
jobNameIndex += n + 1;
|
jobNameIndex += n + 1;
|
||||||
} while(jobNameIndex < argc);
|
} while(jobNameIndex < argc);
|
||||||
} else if(strcmp(argv[1], "start") == 0 || strcmp(argv[1], "trigger") == 0) {
|
} else if(strcmp(argv[1], "start") == 0) {
|
||||||
if(strcmp(argv[1], "trigger") == 0)
|
|
||||||
fprintf(stderr, "Warning: 'trigger' is deprecated, use 'queue' for the old behavior\n");
|
|
||||||
if(argc < 3) {
|
|
||||||
fprintf(stderr, "Usage %s queue <jobName>\n", argv[0]);
|
|
||||||
return EXIT_BAD_ARGUMENT;
|
|
||||||
}
|
|
||||||
kj::Vector<capnp::RemotePromise<LaminarCi::StartResults>> promises;
|
|
||||||
int jobNameIndex = 2;
|
|
||||||
// make a request for each job specified on the commandline
|
|
||||||
do {
|
do {
|
||||||
auto req = laminar.startRequest();
|
auto req = laminar.startRequest();
|
||||||
req.setJobName(argv[jobNameIndex]);
|
req.setJobName(argv[jobNameIndex]);
|
||||||
|
req.setFrontOfQueue(frontOfQueue);
|
||||||
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
||||||
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::StartResults> resp){
|
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::StartResults> resp){
|
||||||
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS) {
|
||||||
@@ -175,21 +179,16 @@ int main(int argc, char** argv) {
|
|||||||
jobNameIndex += n + 1;
|
jobNameIndex += n + 1;
|
||||||
} while(jobNameIndex < argc);
|
} while(jobNameIndex < argc);
|
||||||
} else if(strcmp(argv[1], "run") == 0) {
|
} else if(strcmp(argv[1], "run") == 0) {
|
||||||
if(argc < 3) {
|
|
||||||
fprintf(stderr, "Usage %s run <jobName>\n", argv[0]);
|
|
||||||
return EXIT_BAD_ARGUMENT;
|
|
||||||
}
|
|
||||||
int jobNameIndex = 2;
|
|
||||||
// make a request for each job specified on the commandline
|
|
||||||
do {
|
do {
|
||||||
auto req = laminar.runRequest();
|
auto req = laminar.runRequest();
|
||||||
req.setJobName(argv[jobNameIndex]);
|
req.setJobName(argv[jobNameIndex]);
|
||||||
|
req.setFrontOfQueue(frontOfQueue);
|
||||||
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
int n = setParams(argc - jobNameIndex - 1, &argv[jobNameIndex + 1], req);
|
||||||
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::RunResults> resp){
|
ts.add(req.send().then([&ret,argv,jobNameIndex](capnp::Response<LaminarCi::RunResults> resp){
|
||||||
if(resp.getResult() == LaminarCi::JobResult::UNKNOWN)
|
if(resp.getResult() == LaminarCi::JobResult::UNKNOWN)
|
||||||
fprintf(stderr, "Failed to start job '%s'\n", argv[2]);
|
fprintf(stderr, "Failed to start job '%s'\n", argv[2]);
|
||||||
else
|
else
|
||||||
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
printTriggerLink(argv[jobNameIndex], resp.getBuildNum());
|
||||||
if(resp.getResult() != LaminarCi::JobResult::SUCCESS)
|
if(resp.getResult() != LaminarCi::JobResult::SUCCESS)
|
||||||
ret = EXIT_RUN_FAILED;
|
ret = EXIT_RUN_FAILED;
|
||||||
}));
|
}));
|
||||||
@@ -234,7 +233,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
auto queued = laminar.listQueuedRequest().send().wait(waitScope);
|
auto queued = laminar.listQueuedRequest().send().wait(waitScope);
|
||||||
for(auto it : queued.getResult()) {
|
for(auto it : queued.getResult()) {
|
||||||
printf("%s\n", it.cStr());
|
printf("%s:%d\n", it.getJob().cStr(), it.getBuildNum());
|
||||||
}
|
}
|
||||||
} else if(strcmp(argv[1], "show-running") == 0) {
|
} else if(strcmp(argv[1], "show-running") == 0) {
|
||||||
if(argc != 2) {
|
if(argc != 2) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2019 Oliver Giles
|
/// Copyright 2015-2020 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -19,16 +19,10 @@
|
|||||||
#ifndef LAMINAR_CONTEXT_H_
|
#ifndef LAMINAR_CONTEXT_H_
|
||||||
#define LAMINAR_CONTEXT_H_
|
#define LAMINAR_CONTEXT_H_
|
||||||
|
|
||||||
#include <fnmatch.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
class Run;
|
class Run;
|
||||||
|
|
||||||
// FNM_EXTMATCH isn't supported under musl
|
|
||||||
#if !defined(FNM_EXTMATCH)
|
|
||||||
#define FNM_EXTMATCH 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Represents a context within which a Run will be executed. Allows applying
|
// Represents a context within which a Run will be executed. Allows applying
|
||||||
// a certain environment to a set of Jobs, or setting a limit on the number
|
// a certain environment to a set of Jobs, or setting a limit on the number
|
||||||
// of parallel Runs
|
// of parallel Runs
|
||||||
@@ -39,17 +33,7 @@ public:
|
|||||||
std::string name;
|
std::string name;
|
||||||
int numExecutors;
|
int numExecutors;
|
||||||
int busyExecutors = 0;
|
int busyExecutors = 0;
|
||||||
|
std::set<std::string> jobPatterns;
|
||||||
bool canQueue(std::set<std::string>& patterns) {
|
|
||||||
if(busyExecutors >= numExecutors)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(std::string pattern : patterns) {
|
|
||||||
if(fnmatch(pattern.c_str(), name.c_str(), FNM_EXTMATCH) == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
45
src/http.cpp
45
src/http.cpp
@@ -78,14 +78,14 @@ kj::Maybe<MonitorScope> fromUrl(std::string resource, char* query) {
|
|||||||
return kj::mv(scope);
|
return kj::mv(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resource.substr(0, 5) != "/jobs")
|
if(resource == "/jobs" || resource == "/wallboard") {
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
if(resource.length() == 5) {
|
|
||||||
scope.type = MonitorScope::ALL;
|
scope.type = MonitorScope::ALL;
|
||||||
return kj::mv(scope);
|
return kj::mv(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(resource.substr(0, 5) != "/jobs")
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
resource = resource.substr(5);
|
resource = resource.substr(5);
|
||||||
size_t split = resource.find('/',1);
|
size_t split = resource.find('/',1);
|
||||||
std::string job = resource.substr(1,split-1);
|
std::string job = resource.substr(1,split-1);
|
||||||
@@ -131,9 +131,16 @@ kj::Promise<void> Http::cleanupPeers(kj::Timer& timer)
|
|||||||
{
|
{
|
||||||
return timer.afterDelay(15 * kj::SECONDS).then([&]{
|
return timer.afterDelay(15 * kj::SECONDS).then([&]{
|
||||||
for(EventPeer* p : eventPeers) {
|
for(EventPeer* p : eventPeers) {
|
||||||
// an empty SSE message is a colon followed by two newlines
|
// Even single threaded, if load causes this timeout to be serviced
|
||||||
p->pendingOutput.push_back(":\n\n");
|
// before writeEvents has created a fulfiller, or if an exception
|
||||||
p->fulfiller->fulfill();
|
// caused the destruction of the promise but attach(peer) hasn't yet
|
||||||
|
// removed it from the eventPeers list, we will see a null fulfiller
|
||||||
|
// here
|
||||||
|
if(p->fulfiller) {
|
||||||
|
// an empty SSE message is a colon followed by two newlines
|
||||||
|
p->pendingOutput.push_back(":\n\n");
|
||||||
|
p->fulfiller->fulfill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cleanupPeers(timer);
|
return cleanupPeers(timer);
|
||||||
}).eagerlyEvaluate(nullptr);
|
}).eagerlyEvaluate(nullptr);
|
||||||
@@ -203,6 +210,8 @@ kj::Promise<void> Http::request(kj::HttpMethod method, kj::StringPtr url, const
|
|||||||
if(is_sse) {
|
if(is_sse) {
|
||||||
KJ_IF_MAYBE(s, fromUrl(url.cStr(), queryString)) {
|
KJ_IF_MAYBE(s, fromUrl(url.cStr(), queryString)) {
|
||||||
responseHeaders.set(kj::HttpHeaderId::CONTENT_TYPE, "text/event-stream");
|
responseHeaders.set(kj::HttpHeaderId::CONTENT_TYPE, "text/event-stream");
|
||||||
|
// Disables nginx reverse-proxy's buffering. Necessary for streamed events.
|
||||||
|
responseHeaders.add("X-Accel-Buffering", "no");
|
||||||
auto peer = kj::heap<WithSetRef<EventPeer>>(eventPeers);
|
auto peer = kj::heap<WithSetRef<EventPeer>>(eventPeers);
|
||||||
peer->scope = *s;
|
peer->scope = *s;
|
||||||
std::string st = "data: " + laminar.getStatus(peer->scope) + "\n\n";
|
std::string st = "data: " + laminar.getStatus(peer->scope) + "\n\n";
|
||||||
@@ -219,9 +228,6 @@ kj::Promise<void> Http::request(kj::HttpMethod method, kj::StringPtr url, const
|
|||||||
return stream->write(array.begin(), array.size()).attach(kj::mv(array)).attach(kj::mv(file)).attach(kj::mv(stream));
|
return stream->write(array.begin(), array.size()).attach(kj::mv(array)).attach(kj::mv(file)).attach(kj::mv(stream));
|
||||||
}
|
}
|
||||||
} else if(parseLogEndpoint(url, name, num)) {
|
} else if(parseLogEndpoint(url, name, num)) {
|
||||||
auto lw = kj::heap<WithSetRef<LogWatcher>>(logWatchers);
|
|
||||||
lw->job = name;
|
|
||||||
lw->run = num;
|
|
||||||
bool complete;
|
bool complete;
|
||||||
std::string output;
|
std::string output;
|
||||||
if(laminar.handleLogRequest(name, num, output, complete)) {
|
if(laminar.handleLogRequest(name, num, output, complete)) {
|
||||||
@@ -230,18 +236,17 @@ kj::Promise<void> Http::request(kj::HttpMethod method, kj::StringPtr url, const
|
|||||||
// Disables nginx reverse-proxy's buffering. Necessary for dynamic log output.
|
// Disables nginx reverse-proxy's buffering. Necessary for dynamic log output.
|
||||||
responseHeaders.add("X-Accel-Buffering", "no");
|
responseHeaders.add("X-Accel-Buffering", "no");
|
||||||
auto stream = response.send(200, "OK", responseHeaders, nullptr);
|
auto stream = response.send(200, "OK", responseHeaders, nullptr);
|
||||||
return stream->write(output.data(), output.size()).then([=,s=stream.get(),c=lw.get()]{
|
auto s = stream.get();
|
||||||
|
auto lw = kj::heap<WithSetRef<LogWatcher>>(logWatchers);
|
||||||
|
lw->job = name;
|
||||||
|
lw->run = num;
|
||||||
|
auto promise = writeLogChunk(lw.get(), stream.get()).attach(kj::mv(stream)).attach(kj::mv(lw));
|
||||||
|
return s->write(output.data(), output.size()).attach(kj::mv(output)).then([p=kj::mv(promise),complete]() mutable {
|
||||||
if(complete)
|
if(complete)
|
||||||
return kj::Promise<void>(kj::READY_NOW);
|
return kj::Promise<void>(kj::READY_NOW);
|
||||||
return writeLogChunk(c, s);
|
return kj::mv(p);
|
||||||
}).attach(kj::mv(output)).attach(kj::mv(stream)).attach(kj::mv(lw));
|
});
|
||||||
}
|
}
|
||||||
} else if(url == "/custom/style.css") {
|
|
||||||
responseHeaders.set(kj::HttpHeaderId::CONTENT_TYPE, "text/css; charset=utf-8");
|
|
||||||
responseHeaders.add("Content-Transfer-Encoding", "binary");
|
|
||||||
std::string css = laminar.getCustomCss();
|
|
||||||
auto stream = response.send(200, "OK", responseHeaders, css.size());
|
|
||||||
return stream->write(css.data(), css.size()).attach(kj::mv(css)).attach(kj::mv(stream));
|
|
||||||
} else if(resources->handleRequest(url.cStr(), &start, &end, &content_type)) {
|
} else if(resources->handleRequest(url.cStr(), &start, &end, &content_type)) {
|
||||||
responseHeaders.set(kj::HttpHeaderId::CONTENT_TYPE, content_type);
|
responseHeaders.set(kj::HttpHeaderId::CONTENT_TYPE, content_type);
|
||||||
responseHeaders.add("Content-Encoding", "gzip");
|
responseHeaders.add("Content-Encoding", "gzip");
|
||||||
@@ -292,7 +297,7 @@ void Http::notifyLog(std::string job, uint run, std::string log_chunk, bool eot)
|
|||||||
{
|
{
|
||||||
for(LogWatcher* lw : logWatchers) {
|
for(LogWatcher* lw : logWatchers) {
|
||||||
if(lw->job == job && lw->run == run) {
|
if(lw->job == job && lw->run == run) {
|
||||||
lw->pendingOutput.push_back(kj::mv(log_chunk));
|
lw->pendingOutput.push_back(log_chunk);
|
||||||
lw->fulfiller->fulfill(kj::mv(eot));
|
lw->fulfiller->fulfill(kj::mv(eot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2019 Oliver Giles
|
/// Copyright 2019-2020 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef unsigned long ulong;
|
typedef unsigned long ulong;
|
||||||
|
|
||||||
struct Laminar;
|
class Laminar;
|
||||||
struct Resources;
|
class Resources;
|
||||||
struct LogWatcher;
|
struct LogWatcher;
|
||||||
struct EventPeer;
|
struct EventPeer;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
interface LaminarCi {
|
interface LaminarCi {
|
||||||
|
|
||||||
queue @0 (jobName :Text, params :List(JobParam)) -> (result :MethodResult);
|
queue @0 (jobName :Text, params :List(JobParam), frontOfQueue :Bool) -> (result :MethodResult, buildNum :UInt32);
|
||||||
start @1 (jobName :Text, params :List(JobParam)) -> (result :MethodResult, buildNum :UInt32);
|
start @1 (jobName :Text, params :List(JobParam), frontOfQueue :Bool) -> (result :MethodResult, buildNum :UInt32);
|
||||||
run @2 (jobName :Text, params :List(JobParam)) -> (result :JobResult, buildNum :UInt32);
|
run @2 (jobName :Text, params :List(JobParam), frontOfQueue :Bool) -> (result :JobResult, buildNum :UInt32);
|
||||||
listQueued @3 () -> (result :List(Text));
|
listQueued @3 () -> (result :List(Run));
|
||||||
listRunning @4 () -> (result :List(Run));
|
listRunning @4 () -> (result :List(Run));
|
||||||
listKnown @5 () -> (result :List(Text));
|
listKnown @5 () -> (result :List(Text));
|
||||||
abort @6 (run :Run) -> (result :MethodResult);
|
abort @6 (run :Run) -> (result :MethodResult);
|
||||||
|
|||||||
287
src/laminar.cpp
287
src/laminar.cpp
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2020 Oliver Giles
|
/// Copyright 2015-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
@@ -36,6 +37,11 @@
|
|||||||
#include <rapidjson/stringbuffer.h>
|
#include <rapidjson/stringbuffer.h>
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
|
// FNM_EXTMATCH isn't supported under musl
|
||||||
|
#if !defined(FNM_EXTMATCH)
|
||||||
|
#define FNM_EXTMATCH 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// rapidjson::Writer with a StringBuffer is used a lot in Laminar for
|
// rapidjson::Writer with a StringBuffer is used a lot in Laminar for
|
||||||
// preparing JSON messages to send to HTTP clients. A small wrapper
|
// preparing JSON messages to send to HTTP clients. A small wrapper
|
||||||
// class here reduces verbosity later for this common use case.
|
// class here reduces verbosity later for this common use case.
|
||||||
@@ -67,7 +73,6 @@ inline kj::Path operator/(const std::string& p, const T& ext) {
|
|||||||
typedef std::string str;
|
typedef std::string str;
|
||||||
|
|
||||||
Laminar::Laminar(Server &server, Settings settings) :
|
Laminar::Laminar(Server &server, Settings settings) :
|
||||||
settings(settings),
|
|
||||||
srv(server),
|
srv(server),
|
||||||
homePath(kj::Path::parse(&settings.home[1])),
|
homePath(kj::Path::parse(&settings.home[1])),
|
||||||
fsHome(kj::newDiskFilesystem()->getRoot().openSubdir(homePath, kj::WriteMode::MODIFY)),
|
fsHome(kj::newDiskFilesystem()->getRoot().openSubdir(homePath, kj::WriteMode::MODIFY)),
|
||||||
@@ -90,11 +95,31 @@ Laminar::Laminar(Server &server, Settings settings) :
|
|||||||
db = new Database((homePath/"laminar.sqlite").toString(true).cStr());
|
db = new Database((homePath/"laminar.sqlite").toString(true).cStr());
|
||||||
// Prepare database for first use
|
// Prepare database for first use
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
db->exec("CREATE TABLE IF NOT EXISTS builds("
|
const char *create_table_stmt =
|
||||||
"name TEXT, number INT UNSIGNED, node TEXT, queuedAt INT, "
|
"CREATE TABLE IF NOT EXISTS builds("
|
||||||
"startedAt INT, completedAt INT, result INT, output TEXT, "
|
"name TEXT, number INT UNSIGNED, node TEXT, queuedAt INT, "
|
||||||
"outputLen INT, parentJob TEXT, parentBuild INT, reason TEXT, "
|
"startedAt INT, completedAt INT, result INT, output TEXT, "
|
||||||
"PRIMARY KEY (name, number))");
|
"outputLen INT, parentJob TEXT, parentBuild INT, reason TEXT, "
|
||||||
|
"PRIMARY KEY (name, number DESC))";
|
||||||
|
db->exec(create_table_stmt);
|
||||||
|
|
||||||
|
// Migrate from (name, number) primary key to (name, number DESC).
|
||||||
|
// SQLite does not allow to alter primary key of existing table, so
|
||||||
|
// we have to create a new table.
|
||||||
|
db->stmt("SELECT sql LIKE '%, PRIMARY KEY (name, number))' "
|
||||||
|
"FROM sqlite_master WHERE type = 'table' AND name = 'builds'")
|
||||||
|
.fetch<int>([&](int has_old_index) {
|
||||||
|
if (has_old_index) {
|
||||||
|
LLOG(INFO, "Migrating table to the new primary key");
|
||||||
|
db->exec("BEGIN TRANSACTION");
|
||||||
|
db->exec("ALTER TABLE builds RENAME TO builds_old");
|
||||||
|
db->exec(create_table_stmt);
|
||||||
|
db->exec("INSERT INTO builds SELECT * FROM builds_old");
|
||||||
|
db->exec("DROP TABLE builds_old");
|
||||||
|
db->exec("COMMIT");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
db->exec("CREATE INDEX IF NOT EXISTS idx_completion_time ON builds("
|
db->exec("CREATE INDEX IF NOT EXISTS idx_completion_time ON builds("
|
||||||
"completedAt DESC)");
|
"completedAt DESC)");
|
||||||
|
|
||||||
@@ -136,18 +161,9 @@ void Laminar::loadCustomizations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint Laminar::latestRun(std::string job) {
|
uint Laminar::latestRun(std::string job) {
|
||||||
auto it = activeJobs.byJobName().equal_range(job);
|
if(auto it = buildNums.find(job); it != buildNums.end())
|
||||||
if(it.first == it.second) {
|
return it->second;
|
||||||
uint result = 0;
|
return 0;
|
||||||
db->stmt("SELECT MAX(number) FROM builds WHERE name = ?")
|
|
||||||
.bind(job)
|
|
||||||
.fetch<uint>([&](uint x){
|
|
||||||
result = x;
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
return (*--it.second)->build;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Laminar::handleLogRequest(std::string name, uint num, std::string& output, bool& complete) {
|
bool Laminar::handleLogRequest(std::string name, uint num, std::string& output, bool& complete) {
|
||||||
@@ -207,18 +223,21 @@ std::list<std::string> Laminar::listKnownJobs() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Laminar::populateArtifacts(Json &j, std::string job, uint num) const {
|
void Laminar::populateArtifacts(Json &j, std::string job, uint num, kj::Path subdir) const {
|
||||||
kj::Path runArchive{job,std::to_string(num)};
|
kj::Path runArchive{job,std::to_string(num)};
|
||||||
|
runArchive = runArchive.append(subdir);
|
||||||
KJ_IF_MAYBE(dir, fsHome->tryOpenSubdir("archive"/runArchive)) {
|
KJ_IF_MAYBE(dir, fsHome->tryOpenSubdir("archive"/runArchive)) {
|
||||||
for(kj::StringPtr file : (*dir)->listNames()) {
|
for(kj::StringPtr file : (*dir)->listNames()) {
|
||||||
kj::FsNode::Metadata meta = (*dir)->lstat(kj::Path{file});
|
kj::FsNode::Metadata meta = (*dir)->lstat(kj::Path{file});
|
||||||
if(meta.type != kj::FsNode::Type::FILE)
|
if(meta.type == kj::FsNode::Type::FILE) {
|
||||||
continue;
|
j.StartObject();
|
||||||
j.StartObject();
|
j.set("url", archiveUrl + (runArchive/file).toString().cStr());
|
||||||
j.set("url", archiveUrl + (runArchive/file).toString().cStr());
|
j.set("filename", (subdir/file).toString().cStr());
|
||||||
j.set("filename", file.cStr());
|
j.set("size", meta.size);
|
||||||
j.set("size", meta.size);
|
j.EndObject();
|
||||||
j.EndObject();
|
} else if(meta.type == kj::FsNode::Type::DIRECTORY) {
|
||||||
|
populateArtifacts(j, job, num, subdir/file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,35 +250,29 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.set("time", time(nullptr));
|
j.set("time", time(nullptr));
|
||||||
j.startObject("data");
|
j.startObject("data");
|
||||||
if(scope.type == MonitorScope::RUN) {
|
if(scope.type == MonitorScope::RUN) {
|
||||||
db->stmt("SELECT queuedAt,startedAt,completedAt,result,reason,parentJob,parentBuild FROM builds WHERE name = ? AND number = ?")
|
db->stmt("SELECT queuedAt,startedAt,completedAt,result,reason,parentJob,parentBuild,q.lr IS NOT NULL,q.lr FROM builds "
|
||||||
|
"LEFT JOIN (SELECT name n, MAX(number), completedAt-startedAt lr FROM builds WHERE result IS NOT NULL GROUP BY n) q ON q.n = name "
|
||||||
|
"WHERE name = ? AND number = ?")
|
||||||
.bind(scope.job, scope.num)
|
.bind(scope.job, scope.num)
|
||||||
.fetch<time_t, time_t, time_t, int, std::string, std::string, uint>([&](time_t queued, time_t started, time_t completed, int result, std::string reason, std::string parentJob, uint parentBuild) {
|
.fetch<time_t, time_t, time_t, int, std::string, std::string, uint, uint, uint>([&](time_t queued, time_t started, time_t completed, int result, std::string reason, std::string parentJob, uint parentBuild, uint lastRuntimeKnown, uint lastRuntime) {
|
||||||
j.set("queued", started-queued);
|
j.set("queued", queued);
|
||||||
j.set("started", started);
|
j.set("started", started);
|
||||||
j.set("completed", completed);
|
if(completed)
|
||||||
j.set("result", to_string(RunState(result)));
|
j.set("completed", completed);
|
||||||
|
j.set("result", to_string(completed ? RunState(result) : started ? RunState::RUNNING : RunState::QUEUED));
|
||||||
j.set("reason", reason);
|
j.set("reason", reason);
|
||||||
j.startObject("upstream").set("name", parentJob).set("num", parentBuild).EndObject(2);
|
j.startObject("upstream").set("name", parentJob).set("num", parentBuild).EndObject(2);
|
||||||
|
if(lastRuntimeKnown)
|
||||||
|
j.set("etc", started + lastRuntime);
|
||||||
});
|
});
|
||||||
if(const Run* run = activeRun(scope.job, scope.num)) {
|
|
||||||
j.set("queued", run->startedAt - run->queuedAt);
|
|
||||||
j.set("started", run->startedAt);
|
|
||||||
j.set("result", to_string(RunState::RUNNING));
|
|
||||||
j.set("reason", run->reason());
|
|
||||||
j.startObject("upstream").set("name", run->parentName).set("num", run->parentBuild).EndObject(2);
|
|
||||||
db->stmt("SELECT completedAt - startedAt FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT 1")
|
|
||||||
.bind(run->name)
|
|
||||||
.fetch<uint>([&](uint lastRuntime){
|
|
||||||
j.set("etc", run->startedAt + lastRuntime);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(auto it = buildNums.find(scope.job); it != buildNums.end())
|
if(auto it = buildNums.find(scope.job); it != buildNums.end())
|
||||||
j.set("latestNum", int(it->second));
|
j.set("latestNum", int(it->second));
|
||||||
|
|
||||||
j.startArray("artifacts");
|
j.startArray("artifacts");
|
||||||
populateArtifacts(j, scope.job, scope.num);
|
populateArtifacts(j, scope.job, scope.num);
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
} else if(scope.type == MonitorScope::JOB) {
|
} else if(scope.type == MonitorScope::JOB) {
|
||||||
const uint runsPerPage = 10;
|
const uint runsPerPage = 20;
|
||||||
j.startArray("recent");
|
j.startArray("recent");
|
||||||
// ORDER BY param cannot be bound
|
// ORDER BY param cannot be bound
|
||||||
std::string order_by;
|
std::string order_by;
|
||||||
@@ -274,7 +287,8 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
order_by = "(completedAt-startedAt) " + direction + ", number DESC";
|
order_by = "(completedAt-startedAt) " + direction + ", number DESC";
|
||||||
else
|
else
|
||||||
order_by = "number DESC";
|
order_by = "number DESC";
|
||||||
std::string stmt = "SELECT number,startedAt,completedAt,result,reason FROM builds WHERE name = ? ORDER BY "
|
std::string stmt = "SELECT number,startedAt,completedAt,result,reason FROM builds "
|
||||||
|
"WHERE name = ? AND result IS NOT NULL ORDER BY "
|
||||||
+ order_by + " LIMIT ?,?";
|
+ order_by + " LIMIT ?,?";
|
||||||
db->stmt(stmt.c_str())
|
db->stmt(stmt.c_str())
|
||||||
.bind(scope.job, scope.page * runsPerPage, runsPerPage)
|
.bind(scope.job, scope.page * runsPerPage, runsPerPage)
|
||||||
@@ -288,7 +302,7 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
.EndObject();
|
.EndObject();
|
||||||
});
|
});
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
db->stmt("SELECT COUNT(*),AVG(completedAt-startedAt) FROM builds WHERE name = ?")
|
db->stmt("SELECT COUNT(*),AVG(completedAt-startedAt) FROM builds WHERE name = ? AND result IS NOT NULL")
|
||||||
.bind(scope.job)
|
.bind(scope.job)
|
||||||
.fetch<uint,uint>([&](uint nRuns, uint averageRuntime){
|
.fetch<uint,uint>([&](uint nRuns, uint averageRuntime){
|
||||||
j.set("averageRuntime", averageRuntime);
|
j.set("averageRuntime", averageRuntime);
|
||||||
@@ -312,21 +326,28 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.EndObject();
|
j.EndObject();
|
||||||
}
|
}
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
int nQueued = 0;
|
j.startArray("queued");
|
||||||
for(const auto& run : queuedJobs) {
|
for(const auto& run : queuedJobs) {
|
||||||
if (run->name == scope.job) {
|
if (run->name == scope.job) {
|
||||||
nQueued++;
|
j.StartObject();
|
||||||
|
j.set("number", run->build);
|
||||||
|
j.set("result", to_string(RunState::QUEUED));
|
||||||
|
j.set("reason", run->reason());
|
||||||
|
j.EndObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j.set("nQueued", nQueued);
|
j.EndArray();
|
||||||
db->stmt("SELECT number,startedAt FROM builds WHERE name = ? AND result = ? ORDER BY completedAt DESC LIMIT 1")
|
db->stmt("SELECT number,startedAt FROM builds WHERE name = ? AND result = ? "
|
||||||
|
"ORDER BY completedAt DESC LIMIT 1")
|
||||||
.bind(scope.job, int(RunState::SUCCESS))
|
.bind(scope.job, int(RunState::SUCCESS))
|
||||||
.fetch<int,time_t>([&](int build, time_t started){
|
.fetch<int,time_t>([&](int build, time_t started){
|
||||||
j.startObject("lastSuccess");
|
j.startObject("lastSuccess");
|
||||||
j.set("number", build).set("started", started);
|
j.set("number", build).set("started", started);
|
||||||
j.EndObject();
|
j.EndObject();
|
||||||
});
|
});
|
||||||
db->stmt("SELECT number,startedAt FROM builds WHERE name = ? AND result <> ? ORDER BY completedAt DESC LIMIT 1")
|
db->stmt("SELECT number,startedAt FROM builds "
|
||||||
|
"WHERE name = ? AND result <> ? "
|
||||||
|
"ORDER BY completedAt DESC LIMIT 1")
|
||||||
.bind(scope.job, int(RunState::SUCCESS))
|
.bind(scope.job, int(RunState::SUCCESS))
|
||||||
.fetch<int,time_t>([&](int build, time_t started){
|
.fetch<int,time_t>([&](int build, time_t started){
|
||||||
j.startObject("lastFailed");
|
j.startObject("lastFailed");
|
||||||
@@ -337,14 +358,16 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.set("description", desc == jobDescriptions.end() ? "" : desc->second);
|
j.set("description", desc == jobDescriptions.end() ? "" : desc->second);
|
||||||
} else if(scope.type == MonitorScope::ALL) {
|
} else if(scope.type == MonitorScope::ALL) {
|
||||||
j.startArray("jobs");
|
j.startArray("jobs");
|
||||||
db->stmt("SELECT name,number,startedAt,completedAt,result FROM builds b JOIN (SELECT name n,MAX(number) l FROM builds GROUP BY n) q ON b.name = q.n AND b.number = q.l")
|
db->stmt("SELECT name, number, startedAt, completedAt, result, reason "
|
||||||
.fetch<str,uint,time_t,time_t,int>([&](str name,uint number, time_t started, time_t completed, int result){
|
"FROM builds GROUP BY name HAVING number = MAX(number)")
|
||||||
|
.fetch<str,uint,time_t,time_t,int,str>([&](str name,uint number, time_t started, time_t completed, int result, str reason){
|
||||||
j.StartObject();
|
j.StartObject();
|
||||||
j.set("name", name);
|
j.set("name", name);
|
||||||
j.set("number", number);
|
j.set("number", number);
|
||||||
j.set("result", to_string(RunState(result)));
|
j.set("result", to_string(RunState(result)));
|
||||||
j.set("started", started);
|
j.set("started", started);
|
||||||
j.set("completed", completed);
|
j.set("completed", completed);
|
||||||
|
j.set("reason", reason);
|
||||||
j.EndObject();
|
j.EndObject();
|
||||||
});
|
});
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
@@ -364,15 +387,17 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.EndObject();
|
j.EndObject();
|
||||||
} else { // Home page
|
} else { // Home page
|
||||||
j.startArray("recent");
|
j.startArray("recent");
|
||||||
db->stmt("SELECT * FROM builds ORDER BY completedAt DESC LIMIT 15")
|
db->stmt("SELECT name,number,node,queuedAt,startedAt,completedAt,result,reason FROM builds WHERE completedAt IS NOT NULL ORDER BY completedAt DESC LIMIT 20")
|
||||||
.fetch<str,uint,str,time_t,time_t,time_t,int>([&](str name,uint build,str context,time_t,time_t started,time_t completed,int result){
|
.fetch<str,uint,str,time_t,time_t,time_t,int,str>([&](str name,uint build,str context,time_t queued,time_t started,time_t completed,int result,str reason){
|
||||||
j.StartObject();
|
j.StartObject();
|
||||||
j.set("name", name)
|
j.set("name", name)
|
||||||
.set("number", build)
|
.set("number", build)
|
||||||
.set("context", context)
|
.set("context", context)
|
||||||
|
.set("queued", queued)
|
||||||
.set("started", started)
|
.set("started", started)
|
||||||
.set("completed", completed)
|
.set("completed", completed)
|
||||||
.set("result", to_string(RunState(result)))
|
.set("result", to_string(RunState(result)))
|
||||||
|
.set("reason", reason)
|
||||||
.EndObject();
|
.EndObject();
|
||||||
});
|
});
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
@@ -383,7 +408,9 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.set("number", run->build);
|
j.set("number", run->build);
|
||||||
j.set("context", run->context->name);
|
j.set("context", run->context->name);
|
||||||
j.set("started", run->startedAt);
|
j.set("started", run->startedAt);
|
||||||
db->stmt("SELECT completedAt - startedAt FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT 1")
|
db->stmt("SELECT completedAt - startedAt FROM builds "
|
||||||
|
"WHERE completedAt IS NOT NULL AND name = ? "
|
||||||
|
"ORDER BY completedAt DESC LIMIT 1")
|
||||||
.bind(run->name)
|
.bind(run->name)
|
||||||
.fetch<uint>([&](uint lastRuntime){
|
.fetch<uint>([&](uint lastRuntime){
|
||||||
j.set("etc", run->startedAt + lastRuntime);
|
j.set("etc", run->startedAt + lastRuntime);
|
||||||
@@ -395,6 +422,8 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
for(const auto& run : queuedJobs) {
|
for(const auto& run : queuedJobs) {
|
||||||
j.StartObject();
|
j.StartObject();
|
||||||
j.set("name", run->name);
|
j.set("name", run->name);
|
||||||
|
j.set("number", run->build);
|
||||||
|
j.set("result", to_string(RunState::QUEUED));
|
||||||
j.EndObject();
|
j.EndObject();
|
||||||
}
|
}
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
@@ -428,7 +457,7 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.startObject("timePerJob");
|
j.startObject("timePerJob");
|
||||||
db->stmt("SELECT name, AVG(completedAt-startedAt) av FROM builds WHERE completedAt > ? GROUP BY name ORDER BY av DESC LIMIT 8")
|
db->stmt("SELECT name, AVG(completedAt-startedAt) av FROM builds WHERE completedAt > ? GROUP BY name ORDER BY av DESC LIMIT 8")
|
||||||
.bind(time(nullptr) - 7 * 86400)
|
.bind(time(nullptr) - 7 * 86400)
|
||||||
.fetch<str, uint>([&](str job, uint time){
|
.fetch<str, double>([&](str job, double time){
|
||||||
j.set(job.c_str(), time);
|
j.set(job.c_str(), time);
|
||||||
});
|
});
|
||||||
j.EndObject();
|
j.EndObject();
|
||||||
@@ -466,29 +495,12 @@ std::string Laminar::getStatus(MonitorScope scope) {
|
|||||||
j.EndObject();
|
j.EndObject();
|
||||||
});
|
});
|
||||||
j.EndArray();
|
j.EndArray();
|
||||||
|
j.startObject("completedCounts");
|
||||||
j.startArray("buildTimeDist");
|
db->stmt("SELECT name, COUNT(*) FROM builds WHERE result IS NOT NULL GROUP BY name")
|
||||||
db->stmt("WITH ba AS (SELECT name,AVG(completedAt-startedAt) a FROM builds GROUP BY name) SELECT "
|
.fetch<str, uint>([&](str job, uint count){
|
||||||
"COUNT(CASE WHEN a < 30 THEN 1 END),"
|
j.set(job.c_str(), count);
|
||||||
"COUNT(CASE WHEN a >= 30 AND a < 60 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 60 AND a < 300 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 300 AND a < 600 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 600 AND a < 1200 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 1200 AND a < 2400 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 2400 AND a < 3600 THEN 1 END),"
|
|
||||||
"COUNT(CASE WHEN a >= 3600 THEN 1 END) FROM ba")
|
|
||||||
.fetch<uint,uint,uint,uint,uint,uint,uint,uint>([&](uint c1, uint c2, uint c3, uint c4, uint c5, uint c6, uint c7, uint c8){
|
|
||||||
j.Int(c1);
|
|
||||||
j.Int(c2);
|
|
||||||
j.Int(c3);
|
|
||||||
j.Int(c4);
|
|
||||||
j.Int(c5);
|
|
||||||
j.Int(c6);
|
|
||||||
j.Int(c7);
|
|
||||||
j.Int(c8);
|
|
||||||
});
|
});
|
||||||
j.EndArray();
|
j.EndObject();
|
||||||
|
|
||||||
}
|
}
|
||||||
j.EndObject();
|
j.EndObject();
|
||||||
return j.str();
|
return j.str();
|
||||||
@@ -520,6 +532,16 @@ bool Laminar::loadConfiguration() {
|
|||||||
context->name = name;
|
context->name = name;
|
||||||
context->numExecutors = conf.get<int>("EXECUTORS", 6);
|
context->numExecutors = conf.get<int>("EXECUTORS", 6);
|
||||||
|
|
||||||
|
std::string jobPtns = conf.get<std::string>("JOBS");
|
||||||
|
std::set<std::string> jobPtnsList;
|
||||||
|
if(!jobPtns.empty()) {
|
||||||
|
std::istringstream iss(jobPtns);
|
||||||
|
std::string job;
|
||||||
|
while(std::getline(iss, job, ','))
|
||||||
|
jobPtnsList.insert(job);
|
||||||
|
}
|
||||||
|
context->jobPatterns.swap(jobPtnsList);
|
||||||
|
|
||||||
knownContexts.insert(name);
|
knownContexts.insert(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,14 +574,20 @@ bool Laminar::loadConfiguration() {
|
|||||||
|
|
||||||
std::string ctxPtns = conf.get<std::string>("CONTEXTS");
|
std::string ctxPtns = conf.get<std::string>("CONTEXTS");
|
||||||
|
|
||||||
|
std::set<std::string> ctxPtnList;
|
||||||
if(!ctxPtns.empty()) {
|
if(!ctxPtns.empty()) {
|
||||||
std::istringstream iss(ctxPtns);
|
std::istringstream iss(ctxPtns);
|
||||||
std::set<std::string> ctxPtnList;
|
|
||||||
std::string ctx;
|
std::string ctx;
|
||||||
while(std::getline(iss, ctx, ','))
|
while(std::getline(iss, ctx, ','))
|
||||||
ctxPtnList.insert(ctx);
|
ctxPtnList.insert(ctx);
|
||||||
jobContexts[jobName].swap(ctxPtnList);
|
|
||||||
}
|
}
|
||||||
|
// Must be present both here and in queueJob because otherwise if a context
|
||||||
|
// were created while a job is already queued, the default context would be
|
||||||
|
// dropped when the set of contexts is updated here.
|
||||||
|
if(ctxPtnList.empty())
|
||||||
|
ctxPtnList.insert("default");
|
||||||
|
jobContexts[jobName].swap(ctxPtnList);
|
||||||
|
|
||||||
std::string desc = conf.get<std::string>("DESCRIPTION");
|
std::string desc = conf.get<std::string>("DESCRIPTION");
|
||||||
if(!desc.empty()) {
|
if(!desc.empty()) {
|
||||||
jobDescriptions[jobName] = desc;
|
jobDescriptions[jobName] = desc;
|
||||||
@@ -576,24 +604,35 @@ bool Laminar::loadConfiguration() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Run> Laminar::queueJob(std::string name, ParamMap params) {
|
std::shared_ptr<Run> Laminar::queueJob(std::string name, ParamMap params, bool frontOfQueue) {
|
||||||
if(!fsHome->exists(kj::Path{"cfg","jobs",name+".run"})) {
|
if(!fsHome->exists(kj::Path{"cfg","jobs",name+".run"})) {
|
||||||
LLOG(ERROR, "Non-existent job", name);
|
LLOG(ERROR, "Non-existent job", name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the job has no contexts (maybe there is no .conf file at all), add the default context
|
// jobContexts[name] can be empty if there is no .conf file at all
|
||||||
if(jobContexts[name].empty())
|
if(jobContexts[name].empty())
|
||||||
jobContexts.at(name).insert("default");
|
jobContexts.at(name).insert("default");
|
||||||
|
|
||||||
std::shared_ptr<Run> run = std::make_shared<Run>(name, kj::mv(params), homePath.clone());
|
std::shared_ptr<Run> run = std::make_shared<Run>(name, ++buildNums[name], kj::mv(params), homePath.clone());
|
||||||
queuedJobs.push_back(run);
|
if(frontOfQueue)
|
||||||
|
queuedJobs.push_front(run);
|
||||||
|
else
|
||||||
|
queuedJobs.push_back(run);
|
||||||
|
|
||||||
|
db->stmt("INSERT INTO builds(name,number,queuedAt,parentJob,parentBuild,reason) VALUES(?,?,?,?,?,?)")
|
||||||
|
.bind(run->name, run->build, run->queuedAt, run->parentName, run->parentBuild, run->reason())
|
||||||
|
.exec();
|
||||||
|
|
||||||
// notify clients
|
// notify clients
|
||||||
Json j;
|
Json j;
|
||||||
j.set("type", "job_queued")
|
j.set("type", "job_queued")
|
||||||
.startObject("data")
|
.startObject("data")
|
||||||
.set("name", name)
|
.set("name", name)
|
||||||
|
.set("number", run->build)
|
||||||
|
.set("result", to_string(RunState::QUEUED))
|
||||||
|
.set("queueIndex", frontOfQueue ? 0 : (queuedJobs.size() - 1))
|
||||||
|
.set("reason", run->reason())
|
||||||
.EndObject();
|
.EndObject();
|
||||||
http->notifyEvent(j.str(), name.c_str());
|
http->notifyEvent(j.str(), name.c_str());
|
||||||
|
|
||||||
@@ -613,21 +652,48 @@ void Laminar::abortAll() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Laminar::canQueue(const Context& ctx, const Run& run) const {
|
||||||
|
if(ctx.busyExecutors >= ctx.numExecutors)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// match may be jobs as defined by the context...
|
||||||
|
for(std::string p : ctx.jobPatterns) {
|
||||||
|
if(fnmatch(p.c_str(), run.name.c_str(), FNM_EXTMATCH) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...or context as defined by the job.
|
||||||
|
for(std::string p : jobContexts.at(run.name)) {
|
||||||
|
if(fnmatch(p.c_str(), ctx.name.c_str(), FNM_EXTMATCH) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
|
bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
|
||||||
for(auto& sc : contexts) {
|
for(auto& sc : contexts) {
|
||||||
std::shared_ptr<Context> ctx = sc.second;
|
std::shared_ptr<Context> ctx = sc.second;
|
||||||
|
|
||||||
if(ctx->canQueue(jobContexts.at(run->name))) {
|
if(canQueue(*ctx, *run)) {
|
||||||
kj::Promise<RunState> onRunFinished = run->start(buildNums[run->name] + 1, ctx, *fsHome,[this](kj::Maybe<pid_t>& pid){return srv.onChildExit(pid);});
|
RunState lastResult = RunState::UNKNOWN;
|
||||||
|
|
||||||
ctx->busyExecutors++;
|
// set the last known result if exists. Runs which haven't started yet should
|
||||||
// set the last known result if exists
|
// have completedAt == NULL and thus be at the end of a DESC ordered query
|
||||||
db->stmt("SELECT result FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT 1")
|
db->stmt("SELECT result FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT 1")
|
||||||
.bind(run->name)
|
.bind(run->name)
|
||||||
.fetch<int>([=](int result){
|
.fetch<int>([&](int result){
|
||||||
run->lastResult = RunState(result);
|
lastResult = RunState(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
kj::Promise<RunState> onRunFinished = run->start(lastResult, ctx, *fsHome,[this](kj::Maybe<pid_t>& pid){return srv.onChildExit(pid);});
|
||||||
|
|
||||||
|
db->stmt("UPDATE builds SET node = ?, startedAt = ? WHERE name = ? AND number = ?")
|
||||||
|
.bind(ctx->name, run->startedAt, run->name, run->build)
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
ctx->busyExecutors++;
|
||||||
|
|
||||||
kj::Promise<void> exec = srv.readDescriptor(run->output_fd, [this, run](const char*b, size_t n){
|
kj::Promise<void> exec = srv.readDescriptor(run->output_fd, [this, run](const char*b, size_t n){
|
||||||
// handle log output
|
// handle log output
|
||||||
std::string s(b, n);
|
std::string s(b, n);
|
||||||
@@ -647,16 +713,13 @@ bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
|
|||||||
srv.addTask(kj::mv(exec));
|
srv.addTask(kj::mv(exec));
|
||||||
LLOG(INFO, "Started job", run->name, run->build, ctx->name);
|
LLOG(INFO, "Started job", run->name, run->build, ctx->name);
|
||||||
|
|
||||||
// update next build number
|
|
||||||
buildNums[run->name]++;
|
|
||||||
|
|
||||||
// notify clients
|
// notify clients
|
||||||
Json j;
|
Json j;
|
||||||
j.set("type", "job_started")
|
j.set("type", "job_started")
|
||||||
.startObject("data")
|
.startObject("data")
|
||||||
.set("queueIndex", queueIndex)
|
.set("queueIndex", queueIndex)
|
||||||
.set("name", run->name)
|
.set("name", run->name)
|
||||||
.set("queued", run->startedAt - run->queuedAt)
|
.set("queued", run->queuedAt)
|
||||||
.set("started", run->startedAt)
|
.set("started", run->startedAt)
|
||||||
.set("number", run->build)
|
.set("number", run->build)
|
||||||
.set("reason", run->reason());
|
.set("reason", run->reason());
|
||||||
@@ -705,10 +768,8 @@ void Laminar::handleRunFinished(Run * r) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string reason = r->reason();
|
db->stmt("UPDATE builds SET completedAt = ?, result = ?, output = ?, outputLen = ? WHERE name = ? AND number = ?")
|
||||||
db->stmt("INSERT INTO builds VALUES(?,?,?,?,?,?,?,?,?,?,?,?)")
|
.bind(completedAt, int(r->result), maybeZipped, logsize, r->name, r->build)
|
||||||
.bind(r->name, r->build, ctx->name, r->queuedAt, r->startedAt, completedAt, int(r->result),
|
|
||||||
maybeZipped, logsize, r->parentName, r->parentBuild, reason)
|
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
// notify clients
|
// notify clients
|
||||||
@@ -717,7 +778,7 @@ void Laminar::handleRunFinished(Run * r) {
|
|||||||
.startObject("data")
|
.startObject("data")
|
||||||
.set("name", r->name)
|
.set("name", r->name)
|
||||||
.set("number", r->build)
|
.set("number", r->build)
|
||||||
.set("queued", r->startedAt - r->queuedAt)
|
.set("queued", r->queuedAt)
|
||||||
.set("completed", completedAt)
|
.set("completed", completedAt)
|
||||||
.set("started", r->startedAt)
|
.set("started", r->startedAt)
|
||||||
.set("result", to_string(r->result))
|
.set("result", to_string(r->result))
|
||||||
@@ -750,7 +811,14 @@ void Laminar::handleRunFinished(Run * r) {
|
|||||||
// anyway so hence this (admittedly debatable) optimization.
|
// anyway so hence this (admittedly debatable) optimization.
|
||||||
if(!fsHome->exists(d))
|
if(!fsHome->exists(d))
|
||||||
break;
|
break;
|
||||||
fsHome->remove(d);
|
// must use a try/catch because remove will throw if deletion fails. Using
|
||||||
|
// tryRemove does not help because it still throws an exception for some
|
||||||
|
// errors such as EACCES
|
||||||
|
try {
|
||||||
|
fsHome->remove(d);
|
||||||
|
} catch(kj::Exception& e) {
|
||||||
|
LLOG(ERROR, "Could not remove directory", e.getDescription());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fsHome->symlink(kj::Path{"archive", r->name, "latest"}, std::to_string(r->build), kj::WriteMode::CREATE|kj::WriteMode::MODIFY);
|
fsHome->symlink(kj::Path{"archive", r->name, "latest"}, std::to_string(r->build), kj::WriteMode::CREATE|kj::WriteMode::MODIFY);
|
||||||
@@ -765,7 +833,7 @@ kj::Maybe<kj::Own<const kj::ReadableFile>> Laminar::getArtefact(std::string path
|
|||||||
|
|
||||||
bool Laminar::handleBadgeRequest(std::string job, std::string &badge) {
|
bool Laminar::handleBadgeRequest(std::string job, std::string &badge) {
|
||||||
RunState rs = RunState::UNKNOWN;
|
RunState rs = RunState::UNKNOWN;
|
||||||
db->stmt("SELECT result FROM builds WHERE name = ? ORDER BY number DESC LIMIT 1")
|
db->stmt("SELECT result FROM builds WHERE name = ? AND result IS NOT NULL ORDER BY number DESC LIMIT 1")
|
||||||
.bind(job)
|
.bind(job)
|
||||||
.fetch<int>([&](int result){
|
.fetch<int>([&](int result){
|
||||||
rs = RunState(result);
|
rs = RunState(result);
|
||||||
@@ -807,16 +875,3 @@ R"x(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: deprecate
|
|
||||||
std::string Laminar::getCustomCss() {
|
|
||||||
KJ_IF_MAYBE(cssFile, fsHome->tryOpenFile(kj::Path{"custom","style.css"})) {
|
|
||||||
static bool warningShown = false;
|
|
||||||
if(!warningShown) {
|
|
||||||
LLOG(WARNING, "Custom CSS has been deprecated and will be removed from a future release. Use a custom HTML template instead.");
|
|
||||||
warningShown = true;
|
|
||||||
}
|
|
||||||
return (*cssFile)->readAllText().cStr();
|
|
||||||
} else {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2019 Oliver Giles
|
/// Copyright 2015-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
// Context name to context object map
|
// Context name to context object map
|
||||||
typedef std::unordered_map<std::string, std::shared_ptr<Context>> ContextMap;
|
typedef std::unordered_map<std::string, std::shared_ptr<Context>> ContextMap;
|
||||||
|
|
||||||
struct Server;
|
class Server;
|
||||||
class Json;
|
class Json;
|
||||||
|
|
||||||
class Http;
|
class Http;
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
// Queues a job, returns immediately. Return value will be nullptr if
|
// Queues a job, returns immediately. Return value will be nullptr if
|
||||||
// the supplied name is not a known job.
|
// the supplied name is not a known job.
|
||||||
std::shared_ptr<Run> queueJob(std::string name, ParamMap params = ParamMap());
|
std::shared_ptr<Run> queueJob(std::string name, ParamMap params = ParamMap(), bool frontOfQueue = false);
|
||||||
|
|
||||||
// Return the latest known number of the named job
|
// Return the latest known number of the named job
|
||||||
uint latestRun(std::string job);
|
uint latestRun(std::string job);
|
||||||
@@ -90,11 +90,6 @@ public:
|
|||||||
// if the job is unknown.
|
// if the job is unknown.
|
||||||
bool handleBadgeRequest(std::string job, std::string& badge);
|
bool handleBadgeRequest(std::string job, std::string& badge);
|
||||||
|
|
||||||
// Fetches the content of $LAMINAR_HOME/custom/style.css or an empty
|
|
||||||
// string. Ideally, this would instead be served by a proper web server
|
|
||||||
// which handles this url.
|
|
||||||
std::string getCustomCss();
|
|
||||||
|
|
||||||
// Aborts a single job
|
// Aborts a single job
|
||||||
bool abort(std::string job, uint buildNum);
|
bool abort(std::string job, uint buildNum);
|
||||||
|
|
||||||
@@ -105,10 +100,11 @@ private:
|
|||||||
bool loadConfiguration();
|
bool loadConfiguration();
|
||||||
void loadCustomizations();
|
void loadCustomizations();
|
||||||
void assignNewJobs();
|
void assignNewJobs();
|
||||||
|
bool canQueue(const Context& ctx, const Run& run) const;
|
||||||
bool tryStartRun(std::shared_ptr<Run> run, int queueIndex);
|
bool tryStartRun(std::shared_ptr<Run> run, int queueIndex);
|
||||||
void handleRunFinished(Run*);
|
void handleRunFinished(Run*);
|
||||||
// expects that Json has started an array
|
// expects that Json has started an array
|
||||||
void populateArtifacts(Json& out, std::string job, uint num) const;
|
void populateArtifacts(Json& out, std::string job, uint num, kj::Path subdir = kj::Path::parse(".")) const;
|
||||||
|
|
||||||
Run* activeRun(const std::string name, uint num) {
|
Run* activeRun(const std::string name, uint num) {
|
||||||
auto it = activeJobs.byNameNumber().find(boost::make_tuple(name, num));
|
auto it = activeJobs.byNameNumber().find(boost::make_tuple(name, num));
|
||||||
@@ -125,7 +121,6 @@ private:
|
|||||||
|
|
||||||
std::unordered_map<std::string, std::string> jobGroups;
|
std::unordered_map<std::string, std::string> jobGroups;
|
||||||
|
|
||||||
Settings settings;
|
|
||||||
RunSet activeJobs;
|
RunSet activeJobs;
|
||||||
Database* db;
|
Database* db;
|
||||||
Server& srv;
|
Server& srv;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <dirent.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -45,6 +46,39 @@ struct Script {
|
|||||||
bool runOnAbort;
|
bool runOnAbort;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void aggressive_recursive_kill(pid_t parent) {
|
||||||
|
DIR* proc = opendir("/proc");
|
||||||
|
if(!proc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while(struct dirent* de = readdir(proc)) {
|
||||||
|
if(!isdigit(*de->d_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char status_file[640];
|
||||||
|
sprintf(status_file, "/proc/%s/status", de->d_name);
|
||||||
|
|
||||||
|
FILE* status_fp = fopen(status_file, "rb");
|
||||||
|
if(!status_fp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char status_buffer[512];
|
||||||
|
int n = fread(status_buffer, 1, 512, status_fp);
|
||||||
|
if(char* p = (char*)memmem(status_buffer, n, "PPid:\t", 6)) {
|
||||||
|
pid_t ppid = strtol(p + 6, NULL, 10);
|
||||||
|
if(ppid == parent) {
|
||||||
|
pid_t pid = atoi(de->d_name);
|
||||||
|
aggressive_recursive_kill(pid);
|
||||||
|
fprintf(stderr, "[laminar] sending SIGKILL to pid %d\n", pid);
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(status_fp);
|
||||||
|
}
|
||||||
|
closedir(proc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Leader final : public kj::TaskSet::ErrorHandler {
|
class Leader final : public kj::TaskSet::ErrorHandler {
|
||||||
public:
|
public:
|
||||||
Leader(kj::AsyncIoContext& ioContext, kj::Filesystem& fs, const char* jobName, uint runNumber);
|
Leader(kj::AsyncIoContext& ioContext, kj::Filesystem& fs, const char* jobName, uint runNumber);
|
||||||
@@ -67,6 +101,7 @@ private:
|
|||||||
pid_t currentScriptPid;
|
pid_t currentScriptPid;
|
||||||
std::queue<Script> scripts;
|
std::queue<Script> scripts;
|
||||||
int setEnvPipe[2];
|
int setEnvPipe[2];
|
||||||
|
bool aborting;
|
||||||
};
|
};
|
||||||
|
|
||||||
Leader::Leader(kj::AsyncIoContext &ioContext, kj::Filesystem &fs, const char *jobName, uint runNumber) :
|
Leader::Leader(kj::AsyncIoContext &ioContext, kj::Filesystem &fs, const char *jobName, uint runNumber) :
|
||||||
@@ -76,7 +111,8 @@ Leader::Leader(kj::AsyncIoContext &ioContext, kj::Filesystem &fs, const char *jo
|
|||||||
home(fs.getCurrent()),
|
home(fs.getCurrent()),
|
||||||
rootPath(fs.getCurrentPath()),
|
rootPath(fs.getCurrentPath()),
|
||||||
jobName(jobName),
|
jobName(jobName),
|
||||||
runNumber(runNumber)
|
runNumber(runNumber),
|
||||||
|
aborting(false)
|
||||||
{
|
{
|
||||||
tasks.add(ioContext.unixEventPort.onSignal(SIGTERM).then([this](siginfo_t) {
|
tasks.add(ioContext.unixEventPort.onSignal(SIGTERM).then([this](siginfo_t) {
|
||||||
while(scripts.size() && (!scripts.front().runOnAbort))
|
while(scripts.size() && (!scripts.front().runOnAbort))
|
||||||
@@ -84,8 +120,8 @@ Leader::Leader(kj::AsyncIoContext &ioContext, kj::Filesystem &fs, const char *jo
|
|||||||
// TODO: probably shouldn't do this if we are already in a runOnAbort script
|
// TODO: probably shouldn't do this if we are already in a runOnAbort script
|
||||||
kill(-currentGroupId, SIGTERM);
|
kill(-currentGroupId, SIGTERM);
|
||||||
return this->ioContext.provider->getTimer().afterDelay(2*kj::SECONDS).then([this]{
|
return this->ioContext.provider->getTimer().afterDelay(2*kj::SECONDS).then([this]{
|
||||||
fprintf(stderr, "[laminar] sending SIGKILL to process group %d\n", currentGroupId);
|
aborting = true;
|
||||||
kill(-currentGroupId, SIGKILL);
|
aggressive_recursive_kill(getpid());
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -223,14 +259,18 @@ kj::Promise<void> Leader::reapChildProcesses()
|
|||||||
// waiting for is done
|
// waiting for is done
|
||||||
return reapChildProcesses();
|
return reapChildProcesses();
|
||||||
}
|
}
|
||||||
|
// we were aborted by the primary process already, just wait until all
|
||||||
|
// SIGKILLs are processed
|
||||||
|
if(aborting) {
|
||||||
|
return reapChildProcesses();
|
||||||
|
}
|
||||||
// Otherwise, reparented orphans are on borrowed time
|
// Otherwise, reparented orphans are on borrowed time
|
||||||
// TODO list wayward processes?
|
// TODO list wayward processes?
|
||||||
fprintf(stderr, "[laminar] sending SIGHUP to adopted child processes\n");
|
fprintf(stderr, "[laminar] sending SIGHUP to adopted child processes\n");
|
||||||
kill(-currentGroupId, SIGHUP);
|
kill(-currentGroupId, SIGHUP);
|
||||||
return ioContext.provider->getTimer().afterDelay(5*kj::SECONDS).then([this]{
|
return ioContext.provider->getTimer().afterDelay(5*kj::SECONDS).then([this]{
|
||||||
fprintf(stderr, "[laminar] sending SIGKILL to process group %d\n", currentGroupId);
|
|
||||||
// TODO: should we mark the job as failed if we had to kill reparented processes?
|
// TODO: should we mark the job as failed if we had to kill reparented processes?
|
||||||
kill(-currentGroupId, SIGKILL);
|
aggressive_recursive_kill(getpid());
|
||||||
return reapChildProcesses();
|
return reapChildProcesses();
|
||||||
}).exclusiveJoin(reapChildProcesses());
|
}).exclusiveJoin(reapChildProcesses());
|
||||||
} else if(pid == currentScriptPid) {
|
} else if(pid == currentScriptPid) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <kj/async-unix.h>
|
#include <kj/async-unix.h>
|
||||||
#include <kj/filesystem.h>
|
#include <kj/filesystem.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@@ -53,6 +54,13 @@ static void usage(std::ostream& out) {
|
|||||||
out << " -v enable verbose output\n";
|
out << " -v enable verbose output\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void on_sighup(int)
|
||||||
|
{
|
||||||
|
constexpr const char msg[] = "Laminar received and ignored SIGHUP\n";
|
||||||
|
// write(2) is safe to call inside signal handler.
|
||||||
|
write(STDERR_FILENO, msg, sizeof(msg) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if(argv[0][0] == '{')
|
if(argv[0][0] == '{')
|
||||||
return leader_main();
|
return leader_main();
|
||||||
@@ -92,6 +100,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
signal(SIGINT, &laminar_quit);
|
signal(SIGINT, &laminar_quit);
|
||||||
signal(SIGTERM, &laminar_quit);
|
signal(SIGTERM, &laminar_quit);
|
||||||
|
signal(SIGHUP, &on_sighup);
|
||||||
|
|
||||||
printf("laminard version %s started\n", laminar_version());
|
printf("laminard version %s started\n", laminar_version());
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ Resources::Resources()
|
|||||||
INIT_RESOURCE("/js/app.js", js_app_js, CONTENT_TYPE_JS);
|
INIT_RESOURCE("/js/app.js", js_app_js, CONTENT_TYPE_JS);
|
||||||
INIT_RESOURCE("/js/ansi_up.js", js_ansi_up_js, CONTENT_TYPE_JS);
|
INIT_RESOURCE("/js/ansi_up.js", js_ansi_up_js, CONTENT_TYPE_JS);
|
||||||
INIT_RESOURCE("/js/vue.min.js", js_vue_min_js, CONTENT_TYPE_JS);
|
INIT_RESOURCE("/js/vue.min.js", js_vue_min_js, CONTENT_TYPE_JS);
|
||||||
INIT_RESOURCE("/js/vue-router.min.js", js_vue_router_min_js, CONTENT_TYPE_JS);
|
|
||||||
INIT_RESOURCE("/js/ansi_up.js", js_ansi_up_js, CONTENT_TYPE_JS);
|
INIT_RESOURCE("/js/ansi_up.js", js_ansi_up_js, CONTENT_TYPE_JS);
|
||||||
INIT_RESOURCE("/js/Chart.min.js", js_Chart_min_js, CONTENT_TYPE_JS);
|
INIT_RESOURCE("/js/Chart.min.js", js_Chart_min_js, CONTENT_TYPE_JS);
|
||||||
INIT_RESOURCE("/style.css", style_css, CONTENT_TYPE_CSS);
|
INIT_RESOURCE("/style.css", style_css, CONTENT_TYPE_CSS);
|
||||||
@@ -122,7 +121,7 @@ inline bool beginsWith(std::string haystack, const char* needle) {
|
|||||||
bool Resources::handleRequest(std::string path, const char** start, const char** end, const char** content_type) {
|
bool Resources::handleRequest(std::string path, const char** start, const char** end, const char** content_type) {
|
||||||
// need to keep the list of "application links" synchronised with the angular
|
// need to keep the list of "application links" synchronised with the angular
|
||||||
// application. We cannot return a 404 for any of these
|
// application. We cannot return a 404 for any of these
|
||||||
auto it = beginsWith(path,"/jobs")
|
auto it = beginsWith(path,"/jobs") || path == "/wallboard"
|
||||||
? resources.find("/")
|
? resources.find("/")
|
||||||
: resources.find(path);
|
: resources.find(path);
|
||||||
|
|
||||||
|
|||||||
@@ -11,26 +11,29 @@
|
|||||||
<link rel="manifest" href="/manifest.webmanifest">
|
<link rel="manifest" href="/manifest.webmanifest">
|
||||||
<title>Laminar</title>
|
<title>Laminar</title>
|
||||||
<script src="js/vue.min.js"></script>
|
<script src="js/vue.min.js"></script>
|
||||||
<script src="js/vue-router.min.js"></script>
|
|
||||||
<script src="js/ansi_up.js"></script>
|
<script src="js/ansi_up.js"></script>
|
||||||
<script src="js/Chart.min.js"></script>
|
<script src="js/Chart.min.js"></script>
|
||||||
<script src="js/app.js" defer></script>
|
<script src="js/app.js" defer></script>
|
||||||
|
|
||||||
<link href="style.css" rel="stylesheet">
|
<link href="style.css" rel="stylesheet">
|
||||||
<link href="custom/style.css" rel="stylesheet">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<template id="home"><div id="page-home-main">
|
<template id="home"><div id="page-home-main">
|
||||||
<nav>
|
<nav>
|
||||||
<table class="table striped">
|
<table class="table striped">
|
||||||
<tr v-for="job in jobsQueued">
|
<tr v-for="job in jobsQueued">
|
||||||
<td><router-link :to="'/jobs/'+job.name">{{job.name}}</router-link> <i>queued</i></td>
|
<td>
|
||||||
|
<span v-html="runIcon(job.result)"></span>
|
||||||
|
<router-link :to="'jobs/'+job.name">{{job.name}}</router-link>
|
||||||
|
<router-link :to="'jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link>
|
||||||
|
<i>queued</i>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="job in jobsRunning">
|
<tr v-for="job in jobsRunning">
|
||||||
<td>
|
<td>
|
||||||
<span v-html="runIcon(job.result)"></span>
|
<span v-html="runIcon(job.result)"></span>
|
||||||
<router-link :to="'/jobs/'+job.name">{{job.name}}</router-link>
|
<router-link :to="'jobs/'+job.name">{{job.name}}</router-link>
|
||||||
<router-link :to="'/jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link>
|
<router-link :to="'jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link>
|
||||||
<small style="float:right;">{{formatDuration(job.started, job.completed)}}</small>
|
<small style="float:right;">{{formatDuration(job.started, job.completed)}}</small>
|
||||||
<div class="progress" style="margin-top: 5px;">
|
<div class="progress" style="margin-top: 5px;">
|
||||||
<div class="progress-bar" :class="{overtime:job.overtime,indeterminate:!job.etc}" :style="job.etc && {width:job.progress+'%'}"></div>
|
<div class="progress-bar" :class="{overtime:job.overtime,indeterminate:!job.etc}" :style="job.etc && {width:job.progress+'%'}"></div>
|
||||||
@@ -40,8 +43,8 @@
|
|||||||
<tr v-for="job in jobsRecent">
|
<tr v-for="job in jobsRecent">
|
||||||
<td>
|
<td>
|
||||||
<span v-html="runIcon(job.result)"></span>
|
<span v-html="runIcon(job.result)"></span>
|
||||||
<router-link :to="'/jobs/'+job.name">{{job.name}}</router-link>
|
<router-link :to="'jobs/'+job.name">{{job.name}}</router-link>
|
||||||
<router-link :to="'/jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link><br>
|
<router-link :to="'jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link><br>
|
||||||
<small>Took {{formatDuration(job.started, job.completed)}} at {{formatDate(job.started)}}</small>
|
<small>Took {{formatDuration(job.started, job.completed)}} at {{formatDate(job.started)}}</small>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -52,13 +55,13 @@
|
|||||||
<div>
|
<div>
|
||||||
<h3>Recent regressions</h3>
|
<h3>Recent regressions</h3>
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="job in resultChanged" v-if="job.lastFailure>job.lastSuccess"><td><router-link :to="'/jobs/'+job.name+'/'+job.lastFailure">{{job.name}} #{{job.lastFailure}}</router-link> since <router-link :to="'/jobs/'+job.name+'/'+job.lastSuccess">#{{job.lastSuccess}}</router-link></tr>
|
<tr v-for="job in resultChanged" v-if="job.lastFailure>job.lastSuccess"><td><router-link :to="'jobs/'+job.name+'/'+job.lastFailure">{{job.name}} #{{job.lastFailure}}</router-link> since <router-link :to="'jobs/'+job.name+'/'+job.lastSuccess">#{{job.lastSuccess}}</router-link></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3>Low pass rates</h3>
|
<h3>Low pass rates</h3>
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="job in lowPassRates"><td><router-link :to="'/jobs/'+job.name">{{job.name}}</router-link></td><td>{{Math.round(job.passRate*100)}} %</td></tr>
|
<tr v-for="job in lowPassRates"><td><router-link :to="'jobs/'+job.name">{{job.name}}</router-link></td><td>{{Math.round(job.passRate*100)}} %</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -66,14 +69,11 @@
|
|||||||
<div><canvas id="chartUtil"></canvas></div>
|
<div><canvas id="chartUtil"></canvas></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div id="page-home-plots">
|
||||||
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 5px; padding: 5px;">
|
<div><canvas id="chartBpd"></canvas></div>
|
||||||
<div><canvas id="chartBpd"></canvas></div>
|
<div><canvas id="chartBpj"></canvas></div>
|
||||||
<div><canvas id="chartBpj"></canvas></div>
|
<div><canvas id="chartTpj"></canvas></div>
|
||||||
<div><canvas id="chartTpj"></canvas></div>
|
<div><canvas id="chartBuildTimeChanges"></canvas></div>
|
||||||
<div><canvas id="chartBuildTimeChanges"></canvas></div>
|
|
||||||
<div><canvas id="chartBuildTimeDist"></canvas></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div></template>
|
</div></template>
|
||||||
@@ -84,27 +84,47 @@
|
|||||||
<a v-show="ungrouped.length" :class="{'active':group==null}" href v-on:click.prevent="group = null">Ungrouped Jobs</a>
|
<a v-show="ungrouped.length" :class="{'active':group==null}" href v-on:click.prevent="group = null">Ungrouped Jobs</a>
|
||||||
<a v-for="g in Object.keys(groups)" :class="{'active':g==group}" href v-on:click.prevent="group = g">{{g}}</a>
|
<a v-for="g in Object.keys(groups)" :class="{'active':g==group}" href v-on:click.prevent="group = g">{{g}}</a>
|
||||||
</div>
|
</div>
|
||||||
<input class="form-control" id="jobFilter" v-model="search" placeholder="Filter...">
|
<div style="display: grid; grid-auto-flow: column; align-items: center; gap: 15px">
|
||||||
|
<router-link :to="wallboardLink()" style="display: inherit;" title="Wallboard">
|
||||||
|
<svg width="18" viewBox="0 0 13 13">
|
||||||
|
<g fill="#728494">
|
||||||
|
<rect x="0" y="2" width="6" height="4" />
|
||||||
|
<rect x="0" y="7" width="6" height="4" />
|
||||||
|
<rect x="7" y="2" width="6" height="4" />
|
||||||
|
<rect x="7" y="7" width="6" height="4" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</router-link>
|
||||||
|
<input class="form-control" id="jobFilter" v-model="search" placeholder="Filter...">
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<table class="striped" id="job-list">
|
<table class="striped" id="job-list">
|
||||||
<tr v-for="job in filteredJobs()">
|
<tr v-for="job in filteredJobs()">
|
||||||
<td><router-link :to="'/jobs/'+job.name">{{job.name}}</router-link></td>
|
<td><router-link :to="'jobs/'+job.name">{{job.name}}</router-link></td>
|
||||||
<td style="white-space: nowrap;"><span v-html="runIcon(job.result)"></span> <router-link :to="'/jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link></td>
|
<td style="white-space: nowrap;"><span v-html="runIcon(job.result)"></span> <router-link :to="'jobs/'+job.name+'/'+job.number">#{{job.number}}</router-link></td>
|
||||||
<td>{{formatDate(job.started)}}</td>
|
<td>{{formatDate(job.started)}}</td>
|
||||||
<td>{{formatDuration(job.started,job.completed)}}</td>
|
<td>{{formatDuration(job.started,job.completed)}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div></template>
|
</div></template>
|
||||||
|
|
||||||
|
<template id="wallboard"><div class="wallboard">
|
||||||
|
<router-link :to="'jobs/'+job.name+'/'+job.number" tag="div" v-for="job in wallboardJobs()" :data-result="job.result">
|
||||||
|
<span style="font-size: 36px; font-weight: bold;">{{job.name}} #{{job.number}}</span><br>
|
||||||
|
<span style="font-size: 30px;">{{formatDate(job.started)}}</span><br>
|
||||||
|
<span style="font-size: 26px;">{{job.reason}}</span>
|
||||||
|
</router-link>
|
||||||
|
</div></template>
|
||||||
|
|
||||||
<template id="job"><div id="page-job-main">
|
<template id="job"><div id="page-job-main">
|
||||||
<div style="padding: 15px;">
|
<div style="padding: 15px;">
|
||||||
<h2>{{$route.params.name}}</h2>
|
<h2>{{route.params.name}}</h2>
|
||||||
<div v-html="description"></div>
|
<div v-html="description"></div>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>Last Successful Run</dt>
|
<dt>Last Successful Run</dt>
|
||||||
<dd><router-link v-if="lastSuccess" :to="'/jobs/'+$route.params.name+'/'+lastSuccess.number">#{{lastSuccess.number}}</router-link> {{lastSuccess?' - at '+formatDate(lastSuccess.started):'never'}}</dd>
|
<dd><router-link v-if="lastSuccess" :to="'jobs/'+route.params.name+'/'+lastSuccess.number">#{{lastSuccess.number}}</router-link> {{lastSuccess?' - at '+formatDate(lastSuccess.started):'never'}}</dd>
|
||||||
<dt>Last Failed Run</dt>
|
<dt>Last Failed Run</dt>
|
||||||
<dd><router-link v-if="lastFailed" :to="'/jobs/'+$route.params.name+'/'+lastFailed.number">#{{lastFailed.number}}</router-link> {{lastFailed?' - at '+formatDate(lastFailed.started):'never'}}</dd>
|
<dd><router-link v-if="lastFailed" :to="'jobs/'+route.params.name+'/'+lastFailed.number">#{{lastFailed.number}}</router-link> {{lastFailed?' - at '+formatDate(lastFailed.started):'never'}}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: grid; justify-content: center; padding: 15px;">
|
<div style="display: grid; justify-content: center; padding: 15px;">
|
||||||
@@ -119,14 +139,11 @@
|
|||||||
<th class="text-center">Duration <a class="sort" :class="(sort.field=='duration'?sort.order:'')" v-on:click="do_sort('duration')"> </a></th>
|
<th class="text-center">Duration <a class="sort" :class="(sort.field=='duration'?sort.order:'')" v-on:click="do_sort('duration')"> </a></th>
|
||||||
<th class="text-center vp-sm-hide">Reason <a class="sort" :class="(sort.field=='reason'?sort.order:'')" v-on:click="do_sort('reason')"> </a></th>
|
<th class="text-center vp-sm-hide">Reason <a class="sort" :class="(sort.field=='reason'?sort.order:'')" v-on:click="do_sort('reason')"> </a></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tr v-show="nQueued">
|
<tr v-for="job in jobsQueued.concat(jobsRunning).concat(jobsRecent)" track-by="$index">
|
||||||
<td colspan="5"><i>{{nQueued}} run(s) queued</i></td>
|
|
||||||
</tr>
|
|
||||||
<tr v-for="job in jobsRunning.concat(jobsRecent)" track-by="$index">
|
|
||||||
<td style="width:1px"><span v-html="runIcon(job.result)"></span></td>
|
<td style="width:1px"><span v-html="runIcon(job.result)"></span></td>
|
||||||
<td><router-link :to="'/jobs/'+$route.params.name+'/'+job.number">#{{job.number}}</router-link></td>
|
<td><router-link :to="'jobs/'+route.params.name+'/'+job.number">#{{job.number}}</router-link></td>
|
||||||
<td class="text-center">{{formatDate(job.started)}}</td>
|
<td class="text-center"><span v-if="job.result!='queued'">{{formatDate(job.started)}}</span></td>
|
||||||
<td class="text-center">{{formatDuration(job.started, job.completed)}}</td>
|
<td class="text-center"><span v-if="job.result!='queued'">{{formatDuration(job.started, job.completed)}}</span></td>
|
||||||
<td class="text-center vp-sm-hide">{{job.reason}}</td>
|
<td class="text-center vp-sm-hide">{{job.reason}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -140,25 +157,24 @@
|
|||||||
|
|
||||||
<template id="run"><div style="display: grid; grid-template-rows: auto 1fr">
|
<template id="run"><div style="display: grid; grid-template-rows: auto 1fr">
|
||||||
<div style="padding: 15px">
|
<div style="padding: 15px">
|
||||||
<div style="display: grid; grid-template-columns: auto 1fr 400px auto auto; gap: 5px; align-items: center">
|
<div style="display: grid; grid-template-columns: auto 25px auto auto 1fr 400px; gap: 5px; align-items: center">
|
||||||
<h2 style="white-space: nowrap"><span v-html="runIcon(job.result)"></span> {{$route.params.name}} #{{$route.params.number}}</h2>
|
<h2 style="white-space: nowrap"><span v-html="runIcon(job.result)"></span> <router-link :to="'jobs/'+route.params.name">{{route.params.name}}</router-link> #{{route.params.number}}</h2>
|
||||||
<span></span>
|
<span></span>
|
||||||
<div><!-- extra div to preserve grid columns when v-show hides the progress bar -->
|
<router-link :disabled="route.params.number == 1" :to="'jobs/'+route.params.name+'/'+(route.params.number-1)" tag="button">«</router-link>
|
||||||
<div class="progress" v-show="job.result == 'running'">
|
<router-link :disabled="route.params.number == latestNum" :to="'jobs/'+route.params.name+'/'+(parseInt(route.params.number)+1)" tag="button">»</router-link>
|
||||||
<div class="progress-bar" :class="{overtime:job.overtime,indeterminate:!job.etc}" :style="job.etc && {width:job.progress+'%'}"></div>
|
<span></span>
|
||||||
</div>
|
<div class="progress" v-show="job.result == 'running'">
|
||||||
|
<div class="progress-bar" :class="{overtime:job.overtime,indeterminate:!job.etc}" :style="job.etc && {width:job.progress+'%'}"></div>
|
||||||
</div>
|
</div>
|
||||||
<router-link :disabled="$route.params.number == 1" :to="'/jobs/'+$route.params.name+'/'+($route.params.number-1)" tag="button">«</router-link>
|
|
||||||
<router-link :disabled="$route.params.number == latestNum" :to="'/jobs/'+$route.params.name+'/'+(parseInt($route.params.number)+1)" tag="button">»</router-link>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="page-run-detail">
|
<div id="page-run-detail">
|
||||||
<dl>
|
<dl>
|
||||||
<dt>Reason</dt><dd>{{job.reason}}</dd>
|
<dt>Reason</dt><dd>{{job.reason}}</dd>
|
||||||
<dt v-show="job.upstream.num > 0">Upstream</dt><dd v-show="job.upstream.num > 0"><router-link :to="'/jobs/'+job.upstream.name">{{job.upstream.name}}</router-link> <router-link :to="'/jobs/'+job.upstream.name+'/'+job.upstream.num">#{{job.upstream.num}}</router-link></li></dd>
|
<dt v-show="job.upstream.num > 0">Upstream</dt><dd v-show="job.upstream.num > 0"><router-link :to="'jobs/'+job.upstream.name">{{job.upstream.name}}</router-link> <router-link :to="'jobs/'+job.upstream.name+'/'+job.upstream.num">#{{job.upstream.num}}</router-link></li></dd>
|
||||||
<dt>Queued for</dt><dd>{{job.queued}}s</dd>
|
<dt>Queued for</dt><dd>{{formatDuration(job.queued, job.started ? job.started : Math.floor(Date.now()/1000))}}</dd>
|
||||||
<dt>Started</dt><dd>{{formatDate(job.started)}}</dd>
|
<dt v-show="job.started">Started</dt><dd v-show="job.started">{{formatDate(job.started)}}</dd>
|
||||||
<dt v-show="runComplete(job)">Completed</dt><dd v-show="job.completed">{{formatDate(job.completed)}}</dd>
|
<dt v-show="runComplete(job)">Completed</dt><dd v-show="job.completed">{{formatDate(job.completed)}}</dd>
|
||||||
<dt>Duration</dt><dd>{{formatDuration(job.started, job.completed)}}</dd>
|
<dt v-show="job.started">Duration</dt><dd v-show="job.started">{{formatDuration(job.started, job.completed)}}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl v-show="job.artifacts.length">
|
<dl v-show="job.artifacts.length">
|
||||||
<dt>Artifacts</dt>
|
<dt>Artifacts</dt>
|
||||||
@@ -171,19 +187,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="console-log">
|
<div class="console-log">
|
||||||
<code v-html="log"></code>
|
<code></code>
|
||||||
<span v-show="job.result == 'running'" v-html="runIcon('running')" style="display: block;"></span>
|
<span v-show="!logComplete" v-html="runIcon('running')" style="display: block;"></span>
|
||||||
</div>
|
</div>
|
||||||
</div></template>
|
</div></template>
|
||||||
|
|
||||||
<main id="app" style="display: grid; grid-template-rows: auto 1fr auto; height: 100%;">
|
<main id="app" style="display: grid; grid-template-rows: auto 1fr auto; height: 100%;">
|
||||||
<nav id="nav-top" style="display: grid; grid-template-columns: auto auto 1fr auto auto; grid-gap: 15px;">
|
<nav id="nav-top" style="display: grid; grid-template-columns: auto auto 1fr auto auto; grid-gap: 15px;">
|
||||||
<router-link to="/" style="display: grid; grid-auto-flow: column; align-items: center; margin: 5px; font-size: 20px;">
|
<router-link to="." style="display: grid; grid-auto-flow: column; align-items: center; margin: 5px; font-size: 20px;">
|
||||||
<img src="icon.png"> {{title}}
|
<img src="icon.png"> {{title}}
|
||||||
</router-link>
|
</router-link>
|
||||||
<div id="nav-top-links" style="display: grid; grid-auto-flow: column; justify-content: start; gap: 15px; padding: 0 15px; align-items: center; font-size: 16px;">
|
<div id="nav-top-links" style="display: grid; grid-auto-flow: column; justify-content: start; gap: 15px; padding: 0 15px; align-items: center; font-size: 16px;">
|
||||||
<router-link to="/jobs">Jobs</router-link>
|
<router-link to="jobs">Jobs</router-link>
|
||||||
<router-link v-for="(crumb,i) in _route.path.slice(1).split('/').slice(1,-1)" :to="_route.path.split('/').slice(0,i+3).join('/')">{{crumb}}</router-link>
|
<router-link v-for="(crumb,i) in route.path.slice(1).split('/').slice(1,-1)" :to="route.path.split('/').slice(0,i+3).join('/')">{{crumb}}</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div></div>
|
<div></div>
|
||||||
<span class="version">{{version}}</span>
|
<span class="version">{{version}}</span>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,8 +12,6 @@
|
|||||||
--running: #4786ab;
|
--running: #4786ab;
|
||||||
--warning: #de9a34;
|
--warning: #de9a34;
|
||||||
--link-fg: #2f4579;
|
--link-fg: #2f4579;
|
||||||
--console-bg: #313235;
|
|
||||||
--console-fg: #fff;
|
|
||||||
--alt-row-bg: #fafafa;
|
--alt-row-bg: #fafafa;
|
||||||
--border-grey: #d0d0d0;
|
--border-grey: #d0d0d0;
|
||||||
}
|
}
|
||||||
@@ -84,7 +82,9 @@ canvas {
|
|||||||
}
|
}
|
||||||
svg.success path { fill: var(--success); }
|
svg.success path { fill: var(--success); }
|
||||||
svg.failed path { fill: var(--failure); }
|
svg.failed path { fill: var(--failure); }
|
||||||
svg.running circle { stroke: var(--running); }
|
svg.running circle { stroke: var(--running); }
|
||||||
|
svg.queued circle { fill: var(--nav-fg); }
|
||||||
|
svg.queued path { stroke: white; }
|
||||||
|
|
||||||
/* sort indicators */
|
/* sort indicators */
|
||||||
a.sort {
|
a.sort {
|
||||||
@@ -119,10 +119,46 @@ a.sort:not(.dsc):hover:after { border-top-color: var(--main-fg); }
|
|||||||
a.active { color: var(--main-fg); }
|
a.active { color: var(--main-fg); }
|
||||||
a.active:hover { text-decoration: none; }
|
a.active:hover { text-decoration: none; }
|
||||||
|
|
||||||
/* run console output */
|
/* run console ansi colors (based on base16-default-dark and base16-bright) */
|
||||||
.console-log { padding: 15px; background-color: var(--console-bg); }
|
:root {
|
||||||
.console-log code { white-space: pre-wrap; color: var(--console-fg); }
|
--ansi-black: #181818;
|
||||||
.console-log a { color: var(--console-fg); }
|
--ansi-red: #f8f8f8;
|
||||||
|
--ansi-green: #a1b56c;
|
||||||
|
--ansi-yellow: #f7ca88;
|
||||||
|
--ansi-blue: #7cafc2;
|
||||||
|
--ansi-magenta: #ba8baf;
|
||||||
|
--ansi-cyan: #86c1b9;
|
||||||
|
--ansi-white: #d8d8d8;
|
||||||
|
--ansi-brightblack: #000000;
|
||||||
|
--ansi-brightred: #fb0120;
|
||||||
|
--ansi-brightgreen: #a1c659;
|
||||||
|
--ansi-brightyellow: #fda331;
|
||||||
|
--ansi-brightblue: #6fb3d2;
|
||||||
|
--ansi-brightmagenta: #d381c3;
|
||||||
|
--ansi-brightcyan: #76c7b7;
|
||||||
|
--ansi-brightwhite: #e0e0e0;
|
||||||
|
}
|
||||||
|
.ansi-black-fg { color: var(--ansi-black); } .ansi-black-bg { background-color: var(--ansi-black); }
|
||||||
|
.ansi-red-fg { color: var(--ansi-red); } .ansi-red-bg { background-color: var(--ansi-red); }
|
||||||
|
.ansi-green-fg { color: var(--ansi-green); } .ansi-green-bg { background-color: var(--ansi-green); }
|
||||||
|
.ansi-yellow-fg { color: var(--ansi-yellow); } .ansi-yellow-bg { background-color: var(--ansi-yellow); }
|
||||||
|
.ansi-blue-fg { color: var(--ansi-blue); } .ansi-blue-bg { background-color: var(--ansi-blue); }
|
||||||
|
.ansi-magenta-fg { color: var(--ansi-magenta); } .ansi-magenta-bg { background-color: var(--ansi-magenta); }
|
||||||
|
.ansi-cyan-fg { color: var(--ansi-cyan); } .ansi-cyan-bg { background-color: var(--ansi-cyan); }
|
||||||
|
.ansi-white-fg { color: var(--ansi-white); } .ansi-white-bg { background-color: var(--ansi-white); }
|
||||||
|
.ansi-bright-black-fg { color: var(--ansi-brightblack); } .ansi-bright-black-bg { background-color: var(--ansi-brightblack); }
|
||||||
|
.ansi-bright-red-fg { color: var(--ansi-brightred); } .ansi-bright-red-bg { background-color: var(--ansi-brightred); }
|
||||||
|
.ansi-bright-green-fg { color: var(--ansi-brightgreen); } .ansi-bright-green-bg { background-color: var(--ansi-brightgreen); }
|
||||||
|
.ansi-bright-yellow-fg { color: var(--ansi-brightyellow); } .ansi-bright-yellow-bg { background-color: var(--ansi-brightyellow); }
|
||||||
|
.ansi-bright-blue-fg { color: var(--ansi-brightblue); } .ansi-bright-blue-bg { background-color: var(--ansi-brightblue); }
|
||||||
|
.ansi-bright-magenta-fg { color: var(--ansi-brightmagenta); } .ansi-bright-magenta-bg { background-color: var(--ansi-brightmagenta); }
|
||||||
|
.ansi-bright-cyan-fg { color: var(--ansi-brightcyan); } .ansi-bright-cyan-bg { background-color: var(--ansi-brightcyan); }
|
||||||
|
.ansi-bright-white-fg { color: var(--ansi-brightwhite); } .ansi-bright-white-bg { background-color: var(--ansi-brightwhite); }
|
||||||
|
|
||||||
|
/* run console */
|
||||||
|
.console-log { padding: 15px; background-color: var(--ansi-black); }
|
||||||
|
.console-log code { white-space: pre-wrap; color: var(--ansi-white); }
|
||||||
|
.console-log a { color: var(--ansi-brightwhite); }
|
||||||
|
|
||||||
/* text input (job filtering) */
|
/* text input (job filtering) */
|
||||||
input { padding: 5px 8px; }
|
input { padding: 5px 8px; }
|
||||||
@@ -163,7 +199,6 @@ button:not([disabled]) { cursor: pointer; color: var(--main-fg); }
|
|||||||
}
|
}
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
|
||||||
background-color: var(--running);
|
background-color: var(--running);
|
||||||
background-image: linear-gradient(45deg, transparent 35%, rgba(255,255,255,0.18) 35% 65%, transparent 65%);
|
background-image: linear-gradient(45deg, transparent 35%, rgba(255,255,255,0.18) 35% 65%, transparent 65%);
|
||||||
background-size: 1rem;
|
background-size: 1rem;
|
||||||
@@ -177,6 +212,41 @@ button:not([disabled]) { cursor: pointer; color: var(--main-fg); }
|
|||||||
from { background-position: 1rem 0; } to { background-position: 0 0; }
|
from { background-position: 1rem 0; } to { background-position: 0 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* wallboard */
|
||||||
|
.wallboard {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap-reverse;
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
gap: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
position: fixed;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: #000
|
||||||
|
}
|
||||||
|
.wallboard > div {
|
||||||
|
padding: 30px;
|
||||||
|
flex-grow: 1;
|
||||||
|
background-color: var(--failure);
|
||||||
|
color: var(--nav-fg-light);
|
||||||
|
}
|
||||||
|
.wallboard > div:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.wallboard > div[data-result="running"] {
|
||||||
|
animation: wallboard-bg-fade 2s ease infinite;
|
||||||
|
}
|
||||||
|
@keyframes wallboard-bg-fade {
|
||||||
|
from { background-color: #4786ab; }
|
||||||
|
50% { background-color: #446597; }
|
||||||
|
to { background-color: #4786ab; }
|
||||||
|
}
|
||||||
|
.wallboard > div[data-result="success"] {
|
||||||
|
background-color: var(--success);
|
||||||
|
color: var(--main-fg);
|
||||||
|
}
|
||||||
|
|
||||||
/* connecting overlay */
|
/* connecting overlay */
|
||||||
#connecting-overlay {
|
#connecting-overlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -214,6 +284,8 @@ button:not([disabled]) { cursor: pointer; color: var(--main-fg); }
|
|||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
|
max-width: 1600px;
|
||||||
|
margin: auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@media (max-width: 650px) {
|
@media (max-width: 650px) {
|
||||||
@@ -221,6 +293,19 @@ button:not([disabled]) { cursor: pointer; color: var(--main-fg); }
|
|||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#page-home-plots {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
padding: 5px;
|
||||||
|
gap: 5px;
|
||||||
|
max-width: 1600px;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
@media (max-width: 1095px) {
|
||||||
|
#page-home-plots {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
#page-job-main {
|
#page-job-main {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template: auto 1fr / minmax(550px, 1fr) 1fr;
|
grid-template: auto 1fr / minmax(550px, 1fr) 1fr;
|
||||||
|
|||||||
21
src/rpc.cpp
21
src/rpc.cpp
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2019 Oliver Giles
|
/// Copyright 2015-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -53,10 +53,13 @@ public:
|
|||||||
kj::Promise<void> queue(QueueContext context) override {
|
kj::Promise<void> queue(QueueContext context) override {
|
||||||
std::string jobName = context.getParams().getJobName();
|
std::string jobName = context.getParams().getJobName();
|
||||||
LLOG(INFO, "RPC queue", jobName);
|
LLOG(INFO, "RPC queue", jobName);
|
||||||
LaminarCi::MethodResult result = laminar.queueJob(jobName, params(context.getParams().getParams()))
|
std::shared_ptr<Run> run = laminar.queueJob(jobName, params(context.getParams().getParams()), context.getParams().getFrontOfQueue());
|
||||||
? LaminarCi::MethodResult::SUCCESS
|
if(Run* r = run.get()) {
|
||||||
: LaminarCi::MethodResult::FAILED;
|
context.getResults().setResult(LaminarCi::MethodResult::SUCCESS);
|
||||||
context.getResults().setResult(result);
|
context.getResults().setBuildNum(r->build);
|
||||||
|
} else {
|
||||||
|
context.getResults().setResult(LaminarCi::MethodResult::FAILED);
|
||||||
|
}
|
||||||
return kj::READY_NOW;
|
return kj::READY_NOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +67,7 @@ public:
|
|||||||
kj::Promise<void> start(StartContext context) override {
|
kj::Promise<void> start(StartContext context) override {
|
||||||
std::string jobName = context.getParams().getJobName();
|
std::string jobName = context.getParams().getJobName();
|
||||||
LLOG(INFO, "RPC start", jobName);
|
LLOG(INFO, "RPC start", jobName);
|
||||||
std::shared_ptr<Run> run = laminar.queueJob(jobName, params(context.getParams().getParams()));
|
std::shared_ptr<Run> run = laminar.queueJob(jobName, params(context.getParams().getParams()), context.getParams().getFrontOfQueue());
|
||||||
if(Run* r = run.get()) {
|
if(Run* r = run.get()) {
|
||||||
return r->whenStarted().then([context,r]() mutable {
|
return r->whenStarted().then([context,r]() mutable {
|
||||||
context.getResults().setResult(LaminarCi::MethodResult::SUCCESS);
|
context.getResults().setResult(LaminarCi::MethodResult::SUCCESS);
|
||||||
@@ -80,7 +83,7 @@ public:
|
|||||||
kj::Promise<void> run(RunContext context) override {
|
kj::Promise<void> run(RunContext context) override {
|
||||||
std::string jobName = context.getParams().getJobName();
|
std::string jobName = context.getParams().getJobName();
|
||||||
LLOG(INFO, "RPC run", jobName);
|
LLOG(INFO, "RPC run", jobName);
|
||||||
std::shared_ptr<Run> run = laminar.queueJob(jobName, params(context.getParams().getParams()));
|
std::shared_ptr<Run> run = laminar.queueJob(jobName, params(context.getParams().getParams()), context.getParams().getFrontOfQueue());
|
||||||
if(run) {
|
if(run) {
|
||||||
return run->whenFinished().then([context,run](RunState state) mutable {
|
return run->whenFinished().then([context,run](RunState state) mutable {
|
||||||
context.getResults().setResult(fromRunState(state));
|
context.getResults().setResult(fromRunState(state));
|
||||||
@@ -98,7 +101,9 @@ public:
|
|||||||
auto res = context.getResults().initResult(queue.size());
|
auto res = context.getResults().initResult(queue.size());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(auto it : queue) {
|
for(auto it : queue) {
|
||||||
res.set(i++, it->name);
|
res[i].setJob(it->name);
|
||||||
|
res[i].setBuildNum(it->build);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return kj::READY_NOW;
|
return kj::READY_NOW;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2019 Oliver Giles
|
/// Copyright 2019-2020 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
#include <capnp/rpc-twoparty.h>
|
#include <capnp/rpc-twoparty.h>
|
||||||
#include <capnp/rpc.capnp.h>
|
#include <capnp/rpc.capnp.h>
|
||||||
|
|
||||||
struct Laminar;
|
class Laminar;
|
||||||
|
|
||||||
class Rpc {
|
class Rpc {
|
||||||
public:
|
public:
|
||||||
|
|||||||
13
src/run.cpp
13
src/run.cpp
@@ -33,7 +33,7 @@ inline kj::Path operator/(const kj::Path& p, const T& ext) {
|
|||||||
|
|
||||||
std::string to_string(const RunState& rs) {
|
std::string to_string(const RunState& rs) {
|
||||||
switch(rs) {
|
switch(rs) {
|
||||||
case RunState::PENDING: return "pending";
|
case RunState::QUEUED: return "queued";
|
||||||
case RunState::RUNNING: return "running";
|
case RunState::RUNNING: return "running";
|
||||||
case RunState::ABORTED: return "aborted";
|
case RunState::ABORTED: return "aborted";
|
||||||
case RunState::FAILED: return "failed";
|
case RunState::FAILED: return "failed";
|
||||||
@@ -44,10 +44,10 @@ std::string to_string(const RunState& rs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Run::Run(std::string name, ParamMap pm, kj::Path&& rootPath) :
|
Run::Run(std::string name, uint num, ParamMap pm, kj::Path&& rootPath) :
|
||||||
result(RunState::SUCCESS),
|
result(RunState::SUCCESS),
|
||||||
lastResult(RunState::UNKNOWN),
|
|
||||||
name(name),
|
name(name),
|
||||||
|
build(num),
|
||||||
params(kj::mv(pm)),
|
params(kj::mv(pm)),
|
||||||
queuedAt(time(nullptr)),
|
queuedAt(time(nullptr)),
|
||||||
rootPath(kj::mv(rootPath)),
|
rootPath(kj::mv(rootPath)),
|
||||||
@@ -84,7 +84,7 @@ static void setEnvFromFile(const kj::Path& rootPath, kj::Path file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<RunState> Run::start(uint buildNum, std::shared_ptr<Context> ctx, const kj::Directory &fsHome, std::function<kj::Promise<int>(kj::Maybe<pid_t>&)> getPromise)
|
kj::Promise<RunState> Run::start(RunState lastResult, std::shared_ptr<Context> ctx, const kj::Directory &fsHome, std::function<kj::Promise<int>(kj::Maybe<pid_t>&)> getPromise)
|
||||||
{
|
{
|
||||||
kj::Path cfgDir{"cfg"};
|
kj::Path cfgDir{"cfg"};
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ kj::Promise<RunState> Run::start(uint buildNum, std::shared_ptr<Context> ctx, co
|
|||||||
PATH.append(p);
|
PATH.append(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string runNumStr = std::to_string(buildNum);
|
std::string runNumStr = std::to_string(build);
|
||||||
|
|
||||||
setenv("PATH", PATH.c_str(), true);
|
setenv("PATH", PATH.c_str(), true);
|
||||||
setenv("RUN", runNumStr.c_str(), true);
|
setenv("RUN", runNumStr.c_str(), true);
|
||||||
@@ -152,14 +152,13 @@ kj::Promise<RunState> Run::start(uint buildNum, std::shared_ptr<Context> ctx, co
|
|||||||
// enough. Instead, we'll just exec ourselves and handle that in laminard's
|
// enough. Instead, we'll just exec ourselves and handle that in laminard's
|
||||||
// main() by calling leader_main()
|
// main() by calling leader_main()
|
||||||
char* procName;
|
char* procName;
|
||||||
if(asprintf(&procName, "{laminar} %s:%d", name.data(), buildNum) > 0)
|
if(asprintf(&procName, "{laminar} %s:%d", name.data(), build) > 0)
|
||||||
execl("/proc/self/exe", procName, NULL); // does not return
|
execl("/proc/self/exe", procName, NULL); // does not return
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All good, we've "started"
|
// All good, we've "started"
|
||||||
startedAt = time(nullptr);
|
startedAt = time(nullptr);
|
||||||
build = buildNum;
|
|
||||||
context = ctx;
|
context = ctx;
|
||||||
|
|
||||||
output_fd = plog[0];
|
output_fd = plog[0];
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ typedef unsigned int uint;
|
|||||||
|
|
||||||
enum class RunState {
|
enum class RunState {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
PENDING,
|
QUEUED,
|
||||||
RUNNING,
|
RUNNING,
|
||||||
ABORTED,
|
ABORTED,
|
||||||
FAILED,
|
FAILED,
|
||||||
@@ -50,14 +50,14 @@ typedef std::unordered_map<std::string, std::string> ParamMap;
|
|||||||
// Represents an execution of a job.
|
// Represents an execution of a job.
|
||||||
class Run {
|
class Run {
|
||||||
public:
|
public:
|
||||||
Run(std::string name, ParamMap params, kj::Path&& rootPath);
|
Run(std::string name, uint num, ParamMap params, kj::Path&& rootPath);
|
||||||
~Run();
|
~Run();
|
||||||
|
|
||||||
// copying this class would be asking for trouble...
|
// copying this class would be asking for trouble...
|
||||||
Run(const Run&) = delete;
|
Run(const Run&) = delete;
|
||||||
Run& operator=(const Run&) = delete;
|
Run& operator=(const Run&) = delete;
|
||||||
|
|
||||||
kj::Promise<RunState> start(uint buildNum, std::shared_ptr<Context> ctx, const kj::Directory &fsHome, std::function<kj::Promise<int>(kj::Maybe<pid_t>&)> getPromise);
|
kj::Promise<RunState> start(RunState lastResult, std::shared_ptr<Context> ctx, const kj::Directory &fsHome, std::function<kj::Promise<int>(kj::Maybe<pid_t>&)> getPromise);
|
||||||
|
|
||||||
// aborts this run
|
// aborts this run
|
||||||
bool abort();
|
bool abort();
|
||||||
@@ -69,7 +69,6 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<Context> context;
|
std::shared_ptr<Context> context;
|
||||||
RunState result;
|
RunState result;
|
||||||
RunState lastResult;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string parentName;
|
std::string parentName;
|
||||||
int parentBuild = 0;
|
int parentBuild = 0;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2019 Oliver Giles
|
/// Copyright 2015-2021 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
// Size of buffer used to read from file descriptors. Should be
|
// Size of buffer used to read from file descriptors. Should be
|
||||||
// a multiple of sizeof(struct signalfd_siginfo) == 128
|
// a multiple of sizeof(struct signalfd_siginfo) == 128
|
||||||
@@ -95,7 +96,7 @@ kj::Promise<int> Server::onChildExit(kj::Maybe<pid_t> &pid) {
|
|||||||
|
|
||||||
Server::PathWatcher& Server::watchPaths(std::function<void()> fn)
|
Server::PathWatcher& Server::watchPaths(std::function<void()> fn)
|
||||||
{
|
{
|
||||||
struct PathWatcherImpl : public PathWatcher {
|
struct PathWatcherImpl final : public PathWatcher {
|
||||||
PathWatcher& addPath(const char* path) override {
|
PathWatcher& addPath(const char* path) override {
|
||||||
inotify_add_watch(fd, path, IN_ONLYDIR | IN_CLOSE_WRITE | IN_CREATE | IN_DELETE);
|
inotify_add_watch(fd, path, IN_ONLYDIR | IN_CLOSE_WRITE | IN_CREATE | IN_DELETE);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -117,8 +118,11 @@ void Server::listenRpc(Rpc &rpc, kj::StringPtr rpcBindAddress)
|
|||||||
if(rpcBindAddress.startsWith("unix:"))
|
if(rpcBindAddress.startsWith("unix:"))
|
||||||
unlink(rpcBindAddress.slice(strlen("unix:")).cStr());
|
unlink(rpcBindAddress.slice(strlen("unix:")).cStr());
|
||||||
listeners->add(ioContext.provider->getNetwork().parseAddress(rpcBindAddress)
|
listeners->add(ioContext.provider->getNetwork().parseAddress(rpcBindAddress)
|
||||||
.then([this,&rpc](kj::Own<kj::NetworkAddress>&& addr) {
|
.then([this,&rpc,rpcBindAddress](kj::Own<kj::NetworkAddress>&& addr) {
|
||||||
return acceptRpcClient(rpc, addr->listen());
|
kj::Own<kj::ConnectionReceiver> listener = addr->listen();
|
||||||
|
if(rpcBindAddress.startsWith("unix:"))
|
||||||
|
chmod(rpcBindAddress.slice(strlen("unix:")).cStr(), 0660);
|
||||||
|
return acceptRpcClient(rpc, kj::mv(listener));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -128,8 +132,19 @@ void Server::listenHttp(Http &http, kj::StringPtr httpBindAddress)
|
|||||||
if(httpBindAddress.startsWith("unix:"))
|
if(httpBindAddress.startsWith("unix:"))
|
||||||
unlink(httpBindAddress.slice(strlen("unix:")).cStr());
|
unlink(httpBindAddress.slice(strlen("unix:")).cStr());
|
||||||
listeners->add(ioContext.provider->getNetwork().parseAddress(httpBindAddress)
|
listeners->add(ioContext.provider->getNetwork().parseAddress(httpBindAddress)
|
||||||
.then([this,&http](kj::Own<kj::NetworkAddress>&& addr) {
|
.then([this,&http,httpBindAddress](kj::Own<kj::NetworkAddress>&& addr) {
|
||||||
return http.startServer(ioContext.lowLevelProvider->getTimer(), addr->listen());
|
kj::Own<kj::ConnectionReceiver> listener = addr->listen();
|
||||||
|
if(httpBindAddress.startsWith("unix:"))
|
||||||
|
chmod(httpBindAddress.slice(strlen("unix:")).cStr(), 0660);
|
||||||
|
return http.startServer(ioContext.lowLevelProvider->getTimer(), kj::mv(listener));
|
||||||
|
}).catch_([this,&http,httpBindAddress](kj::Exception&&e) mutable -> kj::Promise<void> {
|
||||||
|
if(e.getType() == kj::Exception::Type::DISCONNECTED) {
|
||||||
|
LLOG(ERROR, "HTTP disconnect, restarting server", e.getDescription());
|
||||||
|
listenHttp(http, httpBindAddress);
|
||||||
|
return kj::READY_NOW;
|
||||||
|
}
|
||||||
|
// otherwise propagate the exception
|
||||||
|
return kj::mv(e);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2015-2017 Oliver Giles
|
/// Copyright 2015-2020 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
struct Laminar;
|
class Laminar;
|
||||||
struct Http;
|
class Http;
|
||||||
struct Rpc;
|
class Rpc;
|
||||||
|
|
||||||
// This class manages the program's asynchronous event loop
|
// This class manages the program's asynchronous event loop
|
||||||
class Server final : public kj::TaskSet::ErrorHandler {
|
class Server final : public kj::TaskSet::ErrorHandler {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2019-2020 Oliver Giles
|
/// Copyright 2019-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -33,20 +33,26 @@
|
|||||||
class LaminarFixture : public ::testing::Test {
|
class LaminarFixture : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
LaminarFixture() {
|
LaminarFixture() {
|
||||||
bind_rpc = std::string("unix:/") + tmp.path.toString(true).cStr() + "/rpc.sock";
|
|
||||||
bind_http = std::string("unix:/") + tmp.path.toString(true).cStr() + "/http.sock";
|
|
||||||
home = tmp.path.toString(true).cStr();
|
home = tmp.path.toString(true).cStr();
|
||||||
tmp.fs->openSubdir(kj::Path{"cfg", "jobs"}, kj::WriteMode::CREATE | kj::WriteMode::CREATE_PARENT);
|
bind_rpc = std::string("unix:/") + home + "/rpc.sock";
|
||||||
|
bind_http = std::string("unix:/") + home + "/http.sock";
|
||||||
settings.home = home.c_str();
|
settings.home = home.c_str();
|
||||||
settings.bind_rpc = bind_rpc.c_str();
|
settings.bind_rpc = bind_rpc.c_str();
|
||||||
settings.bind_http = bind_http.c_str();
|
settings.bind_http = bind_http.c_str();
|
||||||
settings.archive_url = "/test-archive/";
|
settings.archive_url = "/test-archive/";
|
||||||
|
}
|
||||||
|
~LaminarFixture() noexcept(true) {}
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
tmp.init();
|
||||||
server = new Server(*ioContext);
|
server = new Server(*ioContext);
|
||||||
laminar = new Laminar(*server, settings);
|
laminar = new Laminar(*server, settings);
|
||||||
}
|
}
|
||||||
~LaminarFixture() noexcept(true) {
|
|
||||||
|
void TearDown() override {
|
||||||
delete server;
|
delete server;
|
||||||
delete laminar;
|
delete laminar;
|
||||||
|
tmp.clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Own<EventSource> eventSource(const char* path) {
|
kj::Own<EventSource> eventSource(const char* path) {
|
||||||
@@ -92,6 +98,14 @@ public:
|
|||||||
return { res.getResult(), kj::mv(log) };
|
return { res.getResult(), kj::mv(log) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setNumExecutors(int nexec) {
|
||||||
|
KJ_IF_MAYBE(f, tmp.fs->tryOpenFile(kj::Path{"cfg", "contexts", "default.conf"},
|
||||||
|
kj::WriteMode::CREATE | kj::WriteMode::MODIFY | kj::WriteMode::CREATE_PARENT)) {
|
||||||
|
std::string content = "EXECUTORS=" + std::to_string(nexec);
|
||||||
|
(*f)->writeAll(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
kj::String stripLaminarLogLines(const kj::String& str) {
|
kj::String stripLaminarLogLines(const kj::String& str) {
|
||||||
auto out = kj::heapString(str.size());
|
auto out = kj::heapString(str.size());
|
||||||
char *o = out.begin();
|
char *o = out.begin();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2019 Oliver Giles
|
/// Copyright 2019-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -45,7 +45,6 @@ TEST_F(LaminarFixture, EmptyStatusMessageStructure) {
|
|||||||
EXPECT_TRUE(data.HasMember("resultChanged"));
|
EXPECT_TRUE(data.HasMember("resultChanged"));
|
||||||
EXPECT_TRUE(data.HasMember("lowPassRates"));
|
EXPECT_TRUE(data.HasMember("lowPassRates"));
|
||||||
EXPECT_TRUE(data.HasMember("buildTimeChanges"));
|
EXPECT_TRUE(data.HasMember("buildTimeChanges"));
|
||||||
EXPECT_TRUE(data.HasMember("buildTimeDist"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LaminarFixture, JobNotifyHomePage) {
|
TEST_F(LaminarFixture, JobNotifyHomePage) {
|
||||||
@@ -134,7 +133,7 @@ TEST_F(LaminarFixture, ParamsToEnv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LaminarFixture, Abort) {
|
TEST_F(LaminarFixture, Abort) {
|
||||||
defineJob("job1", "yes");
|
defineJob("job1", "sleep inf");
|
||||||
auto req = client().runRequest();
|
auto req = client().runRequest();
|
||||||
req.setJobName("job1");
|
req.setJobName("job1");
|
||||||
auto res = req.send();
|
auto res = req.send();
|
||||||
@@ -163,3 +162,27 @@ TEST_F(LaminarFixture, JobDescription) {
|
|||||||
ASSERT_TRUE(data.HasMember("description"));
|
ASSERT_TRUE(data.HasMember("description"));
|
||||||
EXPECT_STREQ("bar", data["description"].GetString());
|
EXPECT_STREQ("bar", data["description"].GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(LaminarFixture, QueueFront) {
|
||||||
|
setNumExecutors(0);
|
||||||
|
defineJob("foo", "true");
|
||||||
|
defineJob("bar", "true");
|
||||||
|
auto es = eventSource("/");
|
||||||
|
auto req1 = client().queueRequest();
|
||||||
|
req1.setJobName("foo");
|
||||||
|
auto res1 = req1.send();
|
||||||
|
auto req2 = client().queueRequest();
|
||||||
|
req2.setFrontOfQueue(true);
|
||||||
|
req2.setJobName("bar");
|
||||||
|
auto res2 = req2.send();
|
||||||
|
ioContext->waitScope.poll();
|
||||||
|
setNumExecutors(2);
|
||||||
|
ioContext->waitScope.poll();
|
||||||
|
ASSERT_GE(es->messages().size(), 5);
|
||||||
|
auto started1 = es->messages().at(3).GetObject();
|
||||||
|
EXPECT_STREQ("job_started", started1["type"].GetString());
|
||||||
|
EXPECT_STREQ("bar", started1["data"]["name"].GetString());
|
||||||
|
auto started2 = es->messages().at(4).GetObject();
|
||||||
|
EXPECT_STREQ("job_started", started2["type"].GetString());
|
||||||
|
EXPECT_STREQ("foo", started2["data"]["name"].GetString());
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2018-2020 Oliver Giles
|
/// Copyright 2018-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@@ -28,12 +28,25 @@ class TempDir {
|
|||||||
public:
|
public:
|
||||||
TempDir() :
|
TempDir() :
|
||||||
path(mkdtemp()),
|
path(mkdtemp()),
|
||||||
fs(kj::newDiskFilesystem()->getRoot().openSubdir(path, kj::WriteMode::CREATE|kj::WriteMode::MODIFY))
|
fs(kj::newDiskFilesystem()->getRoot().openSubdir(path, kj::WriteMode::MODIFY))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~TempDir() noexcept {
|
~TempDir() noexcept {
|
||||||
kj::newDiskFilesystem()->getRoot().remove(path);
|
kj::newDiskFilesystem()->getRoot().remove(path);
|
||||||
}
|
}
|
||||||
|
void init() {
|
||||||
|
// set up empty directory structure
|
||||||
|
fs->openSubdir(kj::Path{"cfg"}, kj::WriteMode::CREATE);
|
||||||
|
fs->openSubdir(kj::Path{"cfg", "jobs"}, kj::WriteMode::CREATE);
|
||||||
|
fs->openSubdir(kj::Path{"cfg", "contexts"}, kj::WriteMode::CREATE);
|
||||||
|
}
|
||||||
|
void clean() {
|
||||||
|
// rm -rf in config folder
|
||||||
|
for(kj::StringPtr name : fs->listNames()) {
|
||||||
|
fs->remove(kj::Path{name});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
kj::Path path;
|
kj::Path path;
|
||||||
kj::Own<const kj::Directory> fs;
|
kj::Own<const kj::Directory> fs;
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user