Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for metadata for job runs #208

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations" )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What caused this? If it is not related to this change it should be dealt with separately. Also consider that only Debug builds get -Werror, so if this is really needed then it should be put in CMAKE_CXX_FLAGS_DEBUG

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG")

# Allow passing in the version string, for e.g. patched/packaged versions
Expand Down Expand Up @@ -142,6 +143,7 @@ set(LAMINARD_CORE_SOURCES
src/run.cpp
src/server.cpp
src/version.cpp
src/json.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary to break this out into a separate file - see later comments for explanation

laminar.capnp.c++
index_html_size.h
)
Expand Down Expand Up @@ -206,4 +208,4 @@ if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
install(FILES etc/laminar.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/etc)
configure_file(etc/laminar.service.in laminar.service @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/laminar.service DESTINATION ${CMAKE_INSTALL_PREFIX}${SYSTEMD_UNITDIR})
endif()
endif()
16 changes: 16 additions & 0 deletions UserManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,22 @@ TIMEOUT=120

---

# Adding metadata to runs

With the `laminarc tag` command the build scripts can augment runs with metadata.
This can be SCM-oriented information like the used branch or release-version.
The metadata is a list of key/value pairs.
The metadata is automatically shown in the run-view of a job in the web UI.

Each call of `laminarc tag` can assign one key/value pair.

Example:
```
laminarc tag $JOBNAME $NUMBER Branch "$(git -C $WORKSPACE branch --show-current)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only intend this to be called from within the run, laminarc can handle reading $JOBNAME and $NUMBER, see for example what set does

```

---

# Contexts

In Laminar, each run of a job is associated with a context. The context defines an integer number of *executors*, which is the amount of runs which the context will accept simultaneously. A context may also provide additional environment variables.
Expand Down
4 changes: 3 additions & 1 deletion pkg/debian11-amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ VERSION=$(cd "$SOURCE_DIR" && git describe --tags --abbrev=8 --dirty)-1~upstream

DOCKER_TAG=$(docker build -q - <<EOS
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 pkg-config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

EOS
)

Expand All @@ -34,6 +34,8 @@ Depends: libcapnp-0.7.0, libsqlite3-0, zlib1g
Description: Lightweight Continuous Integration Service
EOF
echo /etc/laminar.conf > laminar/DEBIAN/conffiles
mkdir -p laminar/etc
mv laminar/usr/etc/laminar.conf laminar/etc/laminar.conf
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug introduced elsewhere and this is not the right place to fix it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here 8c3d7f6

cat <<EOF > laminar/DEBIAN/postinst
#!/bin/bash
echo Creating laminar user with home in /var/lib/laminar
Expand Down
38 changes: 27 additions & 11 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ static void usage(std::ostream& out) {
out << "Usage: laminarc [-h|--help] COMMAND\n";
out << " -h|--help show this help message\n";
out << "where COMMAND is:\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 << " 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 << " 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 << " show-jobs lists all known jobs.\n";
out << " show-queued lists currently queued jobs.\n";
out << " show-running lists currently running jobs.\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 << " 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 << " 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 << " tag NAME NUMBER KEY VALUE sets an key/value pair in the metadata for an run by NAME and NUMBER.\n";
out << " This is intended to be used by the build scripts, not the user.\n";
out << " show-jobs lists all known jobs.\n";
out << " show-queued lists currently queued jobs.\n";
out << " show-running lists currently running jobs.\n";
out << "JOB_LIST is of the form:\n";
out << " [JOB_NAME [PARAMETER_LIST...]]...\n";
out << "PARAMETER_LIST is of the form:\n";
Expand Down Expand Up @@ -244,6 +246,20 @@ int main(int argc, char** argv) {
for(auto it : running.getResult()) {
printf("%s:%d\n", it.getJob().cStr(), it.getBuildNum());
}
} else if(strcmp(argv[1], "tag") == 0) {
if(argc != 6) {
fprintf(stderr, "Usage %s tag <jobName> <jobNumber> <metaKey> <metaValue>\n", argv[0]);
return EXIT_BAD_ARGUMENT;
}
auto req = laminar.tagRequest();
req.getRun().setJob(argv[2]);
req.getRun().setBuildNum(atoi(argv[3]));
req.setMetaKey( argv[4] );
req.setMetaValue( argv[5] );
ts.add(req.send().then([&ret](capnp::Response<LaminarCi::TagResults> resp){
if(resp.getResult() != LaminarCi::MethodResult::SUCCESS)
ret = EXIT_OPERATION_FAILED;
}));
} else {
fprintf(stderr, "Unknown command %s\n", argv[1]);
return EXIT_BAD_ARGUMENT;
Expand Down
39 changes: 39 additions & 0 deletions src/json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
///
/// Copyright 2015-2022 Oliver Giles
///
/// This file is part of Laminar
///
/// Laminar is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// Laminar is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/>
///
#include "json.h"

template<> Json& Json::set(const char* key, double value) { String(key); Double(value); return *this; }
template<> Json& Json::set(const char* key, const char* value) { String(key); String(value); return *this; }
template<> Json& Json::set(const char* key, std::string value) { String(key); String(value.c_str()); return *this; }

Json& Json::setJsonObject(const char* key, const std::string& object)
{
String(key);
if( object.length() )
{
RawValue(object.c_str(), object.length(), rapidjson::kObjectType);
}
else
{
StartObject();
EndObject();
}
return *this;
}

47 changes: 47 additions & 0 deletions src/json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
///
/// Copyright 2015-2022 Oliver Giles
///
/// This file is part of Laminar
///
/// Laminar is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// Laminar is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Laminar. If not, see <http://www.gnu.org/licenses/>
///
#ifndef LAMINAR_JSON_H_
#define LAMINAR_JSON_H_

#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <string>

// rapidjson::Writer with a StringBuffer is used a lot in Laminar for
// preparing JSON messages to send to HTTP clients. A small wrapper
// class here reduces verbosity later for this common use case.
class Json : public rapidjson::Writer<rapidjson::StringBuffer> {
public:
Json() : rapidjson::Writer<rapidjson::StringBuffer>(buf) { StartObject(); }
template<typename T>
Json& set(const char* key, T value) { String(key); Int64(value); return *this; }
Json& startObject(const char* key) { String(key); StartObject(); return *this; }
Json& startArray(const char* key) { String(key); StartArray(); return *this; }
Json& setJsonObject(const char* key, const std::string& object);
const char* str() { EndObject(); return buf.GetString(); }
private:
rapidjson::StringBuffer buf;
};

template<> Json& Json::set(const char* key, double value);
template<> Json& Json::set(const char* key, const char* value);
template<> Json& Json::set(const char* key, std::string value);


#endif // ? ! LAMINAR_LAMINAR_H_
1 change: 1 addition & 0 deletions src/laminar.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface LaminarCi {
listRunning @4 () -> (result :List(Run));
listKnown @5 () -> (result :List(Text));
abort @6 (run :Run) -> (result :MethodResult);
tag @7 (run :Run, metaKey :Text, metaValue: Text) -> (result :MethodResult);

struct Run {
job @0 :Text;
Expand Down
Loading