all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API.
@ 2017-07-30 10:07 Mathieu Othacehe
  2017-07-31 14:57 ` Ludovic Courtès
  2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
  0 siblings, 2 replies; 16+ messages in thread
From: Mathieu Othacehe @ 2017-07-30 10:07 UTC (permalink / raw)
  To: 27876

* bin/evaluate.in (fill-job): New procedure.
(main): Use it to fill informations (nix-name, system) that will later be
added to database.
* doc/cuirass.texi (Sections)[Web API]: New section describing the HTTP API.
(Database)[Derivation]: Add system and nix_name fields.
(Database)[Builds]: Add id, status, timestamp, starttime and stoptime
fields. Remove output field.
(Database)[Outputs]: New table describing the build outputs.
* src/cuirass/base.scm (build-packages): Add new fields to build object before
adding it to database.
* src/cuirass/database.scm (db-get-build, db-get-builds): New procedures to get
a build by id from database and a list of builds using filter parameters
respectively.
* src/cuirass/http.scm (spec->json-string): Move it to utils.scm and rename it
  object->json-string.
(object->json-scm): Move it utils.scm.
(handle-*-request): New helpers procedures.
(request-parameters): New procedure to parse a request query.
(url-handler): Add new API's.
* src/cuirass/utils.scm (object->json-scm, object->json-string): Exported
procedures moved from http.scm.
* src/schema.sql (Outputs) : New table.
(Derivations): Add system and nix_name columns.
(Builds): Remove output column and add id, status, timestamp, starttime and
stoptime columns.
---

Hi,

Here's a first draft adding partial support for Hydra API in Cuirass.
It can be tested using curl or, better, with Emacs Guix.

The following elisp will change hydra url to a local running Cuirass server.

(setq guix-hydra-url "http://127.0.0.1:8080/")

Then, it should be possible to use M-x guix-hydra-latest-builds.
The commands guix-hydra-jobsets and guix-hydra-queued-builds won't function
because the associated API's are not implemented yet.

There's a problem with /build/:build-id/log/raw API because it is trying to fork
while multiple threads are running (because of decompressed-port function). It seems
to work but a warning message is printed.

Thanks,

Mathieu

 bin/evaluate.in          |  18 +++-
 doc/cuirass.texi         | 242 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/cuirass/base.scm     |  43 ++++++---
 src/cuirass/database.scm | 139 ++++++++++++++++++++++++---
 src/cuirass/http.scm     | 137 +++++++++++++++++++++------
 src/cuirass/utils.scm    |  22 ++++-
 src/schema.sql           |  17 +++-
 7 files changed, 558 insertions(+), 60 deletions(-)

diff --git a/bin/evaluate.in b/bin/evaluate.in
index d1d0767..858c34e 100644
--- a/bin/evaluate.in
+++ b/bin/evaluate.in
@@ -28,9 +28,22 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
 (use-modules (cuirass)
              (ice-9 match)
              (ice-9 pretty-print)
+             (srfi srfi-26)
              (guix build utils)
+             (guix derivations)
              (guix store))
 
+(define (fill-job job eval-id)
+  "Given JOB assoc list, add EVAL-ID to it. Also process #:nix-name and
+  #:system from derivation stored in JOB."
+  (let ((drv (read-derivation-from-file
+              (assq-ref job #:derivation))))
+    ((compose
+      (cut acons #:eval-id eval-id <>)
+      (cut acons #:nix-name (derivation-name drv) <>)
+      (cut acons #:system (derivation-system drv) <>))
+     job)))
+
 (define* (main #:optional (args (command-line)))
   (match args
     ((command load-path guix-package-path cachedir specstr database)
@@ -73,8 +86,9 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
              (pretty-print
               (map (lambda (thunk)
                      (let* ((job  (call-with-time-display thunk))
-                            ;; Keep track of SPEC id in the returned jobs.
-                            (job* (acons #:eval-id eval-id job)))
+                            ;; Fill job with informations that will later be
+                            ;; added to database.
+                            (job* (fill-job job eval-id)))
                        (db-add-derivation db job*)
                        job*))
                    thunks)
diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index 12bc02f..2392e2f 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -11,6 +11,7 @@ This manual is for Cuirass version @value{VERSION}, a build automation
 server.
 
 Copyright @copyright{} 2016, 2017 Mathieu Lirzin
+Copyright @copyright{} 2017 Mathieu Othacehe
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -56,6 +57,7 @@ Tutorial sections:
 Reference sections:
 * Invocation::                  How to run Cuirass.
 * Database::                    About the database schema.
+* Web API::                     Description of the Web API.
 
 * Contributing::                Your help needed!
 * GNU Free Documentation License::  The license of this manual.
@@ -312,6 +314,13 @@ This field holds the @code{id} of an evaluation from the
 
 @item job_name
 This text field holds the name of the job.
+
+@item system
+This text field holds the system name of the derivation.
+
+@item nix_name
+This text field holds the name of the derivation.
+
 @end table
 
 @section Builds
@@ -322,6 +331,9 @@ that builds are not in a one to one relationship with derivations in
 order to keep track of non-deterministic compilations.
 
 @table @code
+@item id
+This is an automatically incrementing numeric identifier.
+
 @item derivation
 This text field holds the absolute name of the derivation file that
 resulted in this build.
@@ -334,11 +346,233 @@ belongs.
 @item log
 This text field holds the absolute file name of the build log file.
 
-@item output
-This text field holds the absolute directory name of the build output or
-@code{NULL} if the build failed.
+@item status
+This integer field holds the build status of the derivation.
+
+@item timestamp
+This integer field holds a timestamp taken at build creation time.
+
+@item starttime
+This integer field holds a timestamp taken at build start time.
+Currently, it has the same value as the @code{timestamp} above.
+
+@item stoptime
+This integer field holds a timestamp taken at build stop time.
+Currently, it has the same value as the @code{timestamp} above.
+
+@end table
+
+@section Outputs
+@cindex outputs, database
+
+This table keep tracks for every eventual build outputs. Each build
+stored in @code{Builds} table may have zero (if it has failed), one or
+multiple outputs.
+
+@table @code
+@item build
+This field holds the @code{id} of a build from the
+@code{Builds} table.
+
+@item name
+This text field holds the name of the output.
+
+@item path
+This text field holds the path of the output.
+
+@end table
+
+@c *********************************************************************
+@node Web API
+@chapter Web API
+@cindex web api
+
+Cuirass web API is derived from Hydra one, see @url{https://github.com/NixOS/hydra/blob/master/doc/manual/api.xml, Hydra API description}.
+
+For now only a subset of this API is implemented.
+
+@section API description.
+@cindex description, json
+
+@subsection Build informations.
+
+It is possible to query Cuirass web server for build informations. The
+dedicated API is @code{"/build/:build-id"} where @code{build-id} is the
+unique id associated to the build in database.
+
+For instance, querying a local Cuirass web server can be done with
+@code{curl} and @code{jq} to format the JSON response :
+
+@example
+$ curl -s "http://localhost:8080/build/2" | jq
+
+@{
+  "id": 2,
+  "project": "guix",
+  "jobset": "master",
+  "job": "acpica-20150410-job",
+  "timestamp": 1501347493,
+  "starttime": 1501347493,
+  "stoptime": 1501347493,
+  "buildoutputs": @{
+    "out": @{
+      "path": "/gnu/store/6g3njhfzqpdm335s7qhvmwvs5l7gcbq1-acpica-20150410"
+    @}
+  @},
+  "system": "x86_64-linux",
+  "nixname": "acpica-20150410",
+  "buildstatus": 0,
+  "busy": 0,
+  "priority": 0,
+  "finished": 1,
+  "buildproducts": null,
+  "releasename": null,
+  "buildinputs_builds": null
+@}
+@end example
+
+If requested @code{build-id} is not known, the HTTP code 404 is
+answered with a JSON error message. For example :
+
+@example
+$ curl -s "http://localhost:8080/build/fff"
+
+@{"error" : "Build with ID fff doesn't exist."@}
+@end example
+
+The nominal output is a JSON object whose fields are described
+hereafter.
+
+@table @code
+@item id
+The unique build id.
+
+@item project
+The associated specification name, as a string.
+
+@item jobset
+The associated specification branch, as a string.
+
+@item job
+The associated job-name, as a string.
+
+@item timestamp
+Timestamp taken at build creation time.
+
+@item starttime
+Timestamp taken at build start time.
+
+@item stoptime
+Timestamp taken at build stop time.
+
+@item buildoutputs
+Build outputs as a JSON object. The keys names are referring to the
+eventual output names. The associated value is another JSON object which
+only key is @code{path}. @code{path} value is the output directory in
+store as a string.
+
+@item system
+System name of the build, as a string.
+
+@item nixname
+Derivation name, as a string.
+
+@item buildstatus
+Build status, as an integer. Possible values are :
+
+@example
+0 -> succeded
+1 -> failed
+2 -> failed dependency
+3 -> failed other
+4 -> cancelled
+@end example
+
+@item busy
+Whether the build is pending, as an integer (not implemented yet).
+
+@item priority
+Build priority, as an integer (not implemented yet).
+
+@item finished
+Build finished, as an integer (not implemented yet : always 1).
+
+@item buildproducts
+Build products in store as a JSON object (not implemented yet).
+
+@item releasename
+Unknown, not implemented yet.
+
+@item buildinputs_builds
+Inputs used for the build, as a JSON object (not implemented yet).
+
 @end table
 
+@subsection Build raw log output.
+
+It is possible to ask Cuirass for the raw build output log with the API
+@code{"/build/:build-id/log/raw"} where @code{build-id} is the
+unique id associated to the build in database.
+
+The output is a raw text, for example :
+
+@example
+$ curl http://localhost:8080/build/2/log/raw
+
+starting phase `set-SOURCE-DATE-EPOCH'
+phase `set-SOURCE-DATE-EPOCH' succeeded after 0.0 seconds
+starting phase `set-paths'
+...
+@end example
+
+If requested @code{build-id} is not known, the HTTP code 404 is
+answered with a JSON error message. For example :
+
+@example
+$ curl -s "http://localhost:8080/build/fff/log/raw"
+
+@{"error" : "Build with ID fff doesn't exist."@}
+@end example
+
+@subsection Latest builds.
+
+The list of latest builds can be obtained with the API
+@code{"/api/latestbuilds"}.  The output is a JSON array of
+builds. Builds are represented as in @code{"/build/:build-id"} API.
+
+This request accepts a mandatory parameter and multiple optional ones.
+
+@table @code
+@item nr
+Limit query result to nr elements. This parameter is @emph{mandatory}.
+
+@item project
+Filter query result to builds with the given @code{project}.
+
+@item jobset
+Filter query result to builds with the given @code{jobset}.
+
+@item job
+Filter query result to builds with the given @code{job} name.
+
+@item system
+Filter query result to builds with the given @code{system}.
+
+@end table
+
+For example, to ask for the ten last builds :
+
+@example
+$ curl "http://localhost:8080/api/latestbuilds?nr=10"
+@end example
+
+or the five last builds which project is ``guix'' and jobset ``master' :
+
+@example
+$ curl "http://localhost:8080/api/latestbuilds?nr=5&project=guix&jobset=master"
+@end example
+
+If no builds matching given parameters are found and empty JSON array is returned.
 
 @c *********************************************************************
 @node Contributing
@@ -346,7 +580,7 @@ This text field holds the absolute directory name of the build output or
 
 Everyone is welcome to contribute to Cuirass.  You can report bugs, send
 patches and share your ideas with others by sending emails the
-@email{bug-cuirass@@framalistes.org, mailing list}.
+@email{guix-devel@@gnu.org, mailing list}.
 
 Development is done using the Git distributed version control system.
 Thus, access to the repository is not strictly necessary.  We welcome
diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm
index 326a530..15d2284 100644
--- a/src/cuirass/base.scm
+++ b/src/cuirass/base.scm
@@ -30,6 +30,7 @@
   #:use-module (ice-9 popen)
   #:use-module (ice-9 rdelim)
   #:use-module (ice-9 receive)
+  #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-19)
   #:use-module (srfi srfi-34)
   #:export (;; Procedures.
@@ -154,25 +155,41 @@ directory and the sha1 of the top level commit in this directory."
 
 (define (build-packages store db jobs)
   "Build JOBS and return a list of Build results."
+
+  (define hydra-build-status
+    ;; Build status as expected by hydra compatible API's.
+    '((succeeded         . 0)
+      (failed            . 1)
+      (failed-dependency . 2)
+      (failed-other      . 3)
+      (cancelled         . 4)))
+
   (define (register job)
     (let* ((name     (assq-ref job #:job-name))
            (drv      (assq-ref job #:derivation))
            (eval-id  (assq-ref job #:eval-id))
            ;; XXX: How to keep logs from several attempts?
            (log      (log-file store drv))
-           (outputs  (match (derivation-path->output-paths drv)
-                       (((names . items) ...)
-                        (filter (lambda (item)
-                                  (valid-path? store item))
-                                items)))))
-      (for-each (lambda (output)
-                  (let ((build `((#:derivation . ,drv)
-                                 (#:eval-id . ,eval-id)
-                                 (#:log . ,log)
-                                 (#:output . ,output))))
-                    (db-add-build db build)))
-                outputs)
-      (format #t "~{~A ~}\n" outputs)
+           (outputs  (filter-map (lambda (res)
+                                   (match res
+                                     ((name . path)
+                                      (and (valid-path? store path)
+                                           `(,name . ,path)))))
+                                 (derivation-path->output-paths drv)))
+           (cur-time (time-second (current-time time-utc))))
+      (let ((build `((#:derivation . ,drv)
+                     (#:eval-id . ,eval-id)
+                     (#:log . ,log)
+                     (#:status .
+                      ,(match (length outputs)
+                         (0 (assq-ref hydra-build-status 'failed))
+                         (_ (assq-ref hydra-build-status 'succeeded))))
+                     (#:outputs . ,outputs)
+                     ;;; XXX: For now, we do not know start/stop build time.
+                     (#:timestamp . ,cur-time)
+                     (#:starttime . ,cur-time)
+                     (#:stoptime . ,cur-time))))
+        (db-add-build db build))
       build))
 
   ;; Pass all the jobs at once so we benefit from as much parallelism as
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 804b8c2..5f60fac 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -1,5 +1,6 @@
 ;;; database.scm -- store evaluation and build results
 ;;; Copyright © 2016, 2017 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of Cuirass.
 ;;;
@@ -21,6 +22,7 @@
   #:use-module (cuirass utils)
   #:use-module (ice-9 match)
   #:use-module (ice-9 rdelim)
+  #:use-module (srfi srfi-1)
   #:use-module (sqlite3)
   #:export (;; Procedures.
             assq-refs
@@ -35,6 +37,8 @@
             db-add-derivation
             db-get-derivation
             db-add-build
+            db-get-build
+            db-get-builds
             read-sql-file
             read-quoted-string
             sqlite-exec
@@ -147,10 +151,12 @@ INSERT OR IGNORE INTO Specifications (repo_name, url, load_path, file, \
 (define (db-add-derivation db job)
   "Store a derivation result in database DB and return its ID."
   (sqlite-exec db "\
-INSERT OR IGNORE INTO Derivations (derivation, job_name, evaluation)\
-  VALUES ('~A', '~A', '~A');"
+INSERT OR IGNORE INTO Derivations (derivation, job_name, system, nix_name, evaluation)\
+  VALUES ('~A', '~A', '~A', '~A', '~A');"
                (assq-ref job #:derivation)
                (assq-ref job #:job-name)
+               (assq-ref job #:system)
+               (assq-ref job #:nix-name)
                (assq-ref job #:eval-id)))
 
 (define (db-get-derivation db id)
@@ -182,15 +188,126 @@ string."
             (else (loop (cons char chars)))))))
 
 (define (db-add-build db build)
-  "Store BUILD in database DB."
-  (sqlite-exec db "\
-INSERT INTO Builds (derivation, evaluation, log, output)\
-  VALUES ('~A', '~A', '~A', '~A');"
-               (assq-ref build #:derivation)
-               (assq-ref build #:eval-id)
-               (assq-ref build #:log)
-               (assq-ref build #:output))
-  (last-insert-rowid db))
+  "Store BUILD in database DB. BUILS eventual outputs are stored
+in the OUTPUTS table."
+  (let* ((build-exec
+          (sqlite-exec db "\
+INSERT INTO Builds (derivation, evaluation, log, status, timestamp, starttime, stoptime)\
+  VALUES ('~A', '~A', '~A', '~A', '~A', '~A', '~A');"
+                       (assq-ref build #:derivation)
+                       (assq-ref build #:eval-id)
+                       (assq-ref build #:log)
+                       (assq-ref build #:status)
+                       (assq-ref build #:timestamp)
+                       (assq-ref build #:starttime)
+                       (assq-ref build #:stoptime)))
+         (build-id (last-insert-rowid db)))
+    (for-each (lambda (output)
+                (match output
+                  ((name . path)
+                   (sqlite-exec db "\
+INSERT INTO Outputs (build, name, path) VALUES ('~A', '~A', '~A');"
+                                build-id name path))))
+              (assq-ref build #:outputs))
+    build-id))
+
+(define (db-get-outputs db build-id)
+  "Retrieve the OUTPUTS of the build identified by BUILD-ID in DB database."
+  (let loop ((rows
+              (sqlite-exec db "SELECT name, path FROM Outputs WHERE build='~A';"
+                           build-id))
+             (outputs '()))
+    (match rows
+      (() outputs)
+      ((#(name path)
+        . rest)
+       (loop rest
+             (cons `(,name . ((#:path . ,path)))
+                   outputs))))))
+
+(define db-build-request "\
+SELECT Builds.id, Builds.timestamp, Builds.starttime, Builds.stoptime, Builds.log, Builds.status,\
+Derivations.job_name, Derivations.system, Derivations.nix_name,\
+Specifications.repo_name, Specifications.branch \
+FROM Builds \
+INNER JOIN Derivations ON Builds.derivation = Derivations.derivation and Builds.evaluation = Derivations.evaluation \
+INNER JOIN Evaluations ON Derivations.evaluation = Evaluations.id \
+INNER JOIN Specifications ON Evaluations.specification = Specifications.repo_name")
+
+(define (db-format-build db build)
+  (match build
+    (#(id timestamp starttime stoptime log status job-name system
+          nix-name repo-name branch)
+       `((#:id        . ,id)
+         (#:timestamp . ,timestamp)
+         (#:starttime . ,starttime)
+         (#:stoptime  . ,stoptime)
+         (#:log       . ,log)
+         (#:status    . ,status)
+         (#:job-name  . ,job-name)
+         (#:system    . ,system)
+         (#:nix-name  . ,nix-name)
+         (#:repo-name . ,repo-name)
+         (#:outputs   . ,(db-get-outputs db id))
+         (#:branch    . ,branch)))))
+
+(define (db-get-build db id)
+  "Retrieve a build in database DB which corresponds to ID."
+  (let ((res (sqlite-exec db (string-append db-build-request
+                                            " WHERE Builds.id='~A';") id)))
+    (match res
+      ((build)
+       (db-format-build db build))
+      (() #f))))
+
+(define (db-get-builds db filters)
+  "Retrieve all builds in database DB which are matched by given FILTERS.
+FILTERS is an assoc list which possible keys are 'project | 'jobset | 'job |
+'system | 'nr."
+
+  (define (format-where-clause filters)
+    (let ((where-clause
+           (filter-map
+            (lambda (param)
+              (match param
+                (('project project)
+                 (format #f "Specifications.repo_name='~A'" project))
+                (('jobset jobset)
+                 (format #f "Specifications.branch='~A'" jobset))
+                (('job job)
+                 (format #f "Derivations.job_name='~A'" job))
+                (('system system)
+                 (format #f "Derivations.system='~A'" system))
+                (_ #f)))
+            filters)))
+      (if (> (length where-clause) 0)
+          (string-append
+           "WHERE "
+           (string-join where-clause " AND "))
+          "")))
+
+  (define (format-order-clause filters)
+    (any
+     (lambda (param)
+       (match param
+         (('nr number)
+          (format #f "ORDER BY Builds.id DESC LIMIT '~A';" number))
+         (_ #f)))
+     filters))
+
+  (let loop ((rows
+              (sqlite-exec db (string-append
+                               db-build-request
+                               " "
+                               (format-where-clause filters)
+                               " "
+                               (format-order-clause filters))))
+             (outputs '()))
+    (match rows
+      (() outputs)
+      ((row . rest)
+       (loop rest
+             (cons (db-format-build db row) outputs))))))
 
 (define (db-get-stamp db spec)
   "Return a stamp corresponding to specification SPEC in database DB."
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 33cd37b..976e24c 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -1,5 +1,6 @@
 ;;;; http.scm -- HTTP API
 ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of Cuirass.
 ;;;
@@ -19,52 +20,134 @@
 (define-module (cuirass http)
   #:use-module (cuirass database)
   #:use-module (cuirass utils)
-  #:use-module (ice-9 hash-table)
+  #:use-module (guix build utils)
+  #:use-module (guix utils)
   #:use-module (ice-9 match)
   #:use-module (json)
   #:use-module (web request)
   #:use-module (web response)
   #:use-module (web server)
   #:use-module (web uri)
-  #:export (spec->json-string
-            run-cuirass-server))
+  #:export (run-cuirass-server))
 
-;;;
-;;; JSON format.
-;;;
+(define (build->hydra-build build)
+  "Convert BUILD to an assoc list matching hydra API format."
+  `((#:id . ,(assq-ref build #:id))
+    (#:project . ,(assq-ref build #:repo-name))
+    (#:jobset . ,(assq-ref build #:branch))
+    (#:job . ,(assq-ref build #:job-name))
+    (#:timestamp . ,(assq-ref build #:timestamp))
+    (#:starttime . ,(assq-ref build #:starttime))
+    (#:stoptime . ,(assq-ref build #:stoptime))
+    (#:buildoutputs . ,(assq-ref build #:outputs))
+    (#:system . ,(assq-ref build #:system))
+    (#:nixname . ,(assq-ref build #:nix-name))
+    (#:buildstatus . ,(assq-ref build #:status))
+
+    ;; TODO: Fill the fields above with correct values.
+    (#:busy . 0)
+    (#:priority . 0)
+    (#:finished . 1)
+    (#:buildproducts . #nil)
+    (#:releasename . #nil)
+    (#:buildinputs_builds . #nil)))
+
+(define (handle-build-request db build-id)
+  "Retrieve build identified by BUILD-ID in DB and convert it to hydra
+  format. Return #f is not build was found."
+  (let ((build (db-get-build db build-id)))
+    (and=> build build->hydra-build)))
 
-(define (object->json-scm obj)
-  "Prepare OBJ for JSON usage."
-  (cond ((string? obj)  obj)
-        ((number? obj)  obj)
-        ((boolean? obj) obj)
-        ((null? obj)    obj)
-        ((symbol? obj)  (symbol->string obj))
-        ((keyword? obj) (object->json-scm (keyword->symbol obj)))
-        ((alist? obj)   (alist->hash-table (map object->json-scm obj)))
-        ((pair? obj)    (cons (object->json-scm (car obj))
-                              (object->json-scm (cdr obj))))
-        (else           (object->string obj))))
-
-(define* (spec->json-string spec #:key pretty)
-  "Return SPEC as a JSON object."
-  (scm->json-string (object->json-scm spec) #:pretty pretty))
+(define (handle-builds-request db filters)
+  "Retrieve all builds matched by FILTERS in DB and convert them to hydra
+  format."
+  (let ((builds (db-get-builds db filters)))
+    (map build->hydra-build builds)))
+
+(define (handle-log-request db build-id)
+  "Retrieve the log file of the build identified by BUILD-ID in DB. Return a
+  lambda which PORT argument is an input port from which the content of the
+  log file can be read or #f if the log file is not readable."
+  (let* ((build (db-get-build db build-id))
+         (log (assq-ref build #:log))
+         (access (and (string? log)
+                      (access? log R_OK))))
+    (and access
+         (lambda (port)
+           (dump-port (decompressed-port 'bzip2 (open-input-file log))
+                      port)))))
+
+(define (request-parameters request)
+  "Parse the REQUEST query parameters and return them under the form
+  '((parameter value) ...)."
+  (let* ((uri (request-uri request))
+         (query (uri-query uri)))
+    (and query
+         (map (lambda (param)
+                (match (string-split param #\=)
+                  ((key param)
+                   (list (string->symbol key) param))))
+              (string-split query #\&)))))
 
 \f
 ;;;
 ;;; Web server.
 ;;;
+;;; The api is derived from the hydra one. It is partially described here :
+;;;
+;;; https://github.com/NixOS/hydra/blob/master/doc/manual/api.xml
+;;;
 
 (define (request-path-components request)
   (split-and-decode-uri-path (uri-path (request-uri request))))
 
 (define (url-handler request body db)
+
   (define* (respond response #:key body (db db))
     (values response body db))
+
+  (define-syntax-rule (respond-json body ...)
+    (respond '((content-type . (application/json)))
+             #:body body ...))
+
+  (define-syntax-rule (respond-text body ...)
+    (respond '((content-type . (text/plain)))
+             #:body body ...))
+
+  (define-syntax-rule (respond-json-with-error error-code message)
+    (respond
+     (build-response #:headers '((content-type . (application/json)))
+                     #:code error-code)
+     #:body
+     (object->json-string
+      `((error . ,message)))))
+
+  (define (respond-build-not-found build)
+    (respond-json-with-error
+     404
+     (format #f "Build with ID ~a doesn't exist." build)))
+
   (match (request-path-components request)
     (((or "jobsets" "specifications") . rest)
-     (respond '((content-type . (application/json)))
-              #:body (spec->json-string (car (db-get-specifications db)))))
+     (respond-json (object->json-string (car (db-get-specifications db)))))
+    (("build" build)
+     (let ((hydra-build (handle-build-request db build)))
+       (if hydra-build
+           (respond-json (object->json-string hydra-build))
+           (respond-build-not-found build))))
+    (("build" build "log" "raw")
+     (let ((log-response (handle-log-request db build)))
+       (if log-response
+           (respond-text log-response)
+           (respond-build-not-found build))))
+    (("api" "latestbuilds")
+     (let* ((params (request-parameters request))
+            ;; 'nr parameter is mandatory to limit query size.
+            (valid-params? (assq-ref params 'nr)))
+       (if valid-params?
+           (respond-json (object->json-string
+                          (handle-builds-request db params)))
+           (respond-json-with-error 500 "Parameter not defined!"))))
     (_
      (respond (build-response #:code 404)
               #:body (string-append "Resource not found: "
@@ -73,6 +156,6 @@
 (define* (run-cuirass-server db #:key (port 8080))
   (format (current-error-port) "listening on port ~A~%" port)
   (run-server url-handler
-              'http                     ;server implementation
-              `(#:port ,port)           ;implementation parameters
-              db))                      ;state
+              'http
+              `(#:port ,port)
+              db))
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index d966543..a932674 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -21,9 +21,29 @@
 (define-module (cuirass utils)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
-  #:export (alist?))
+  #:use-module (json)
+  #:export (alist?
+            object->json-scm
+            object->json-string))
 
 (define (alist? obj)
   "Return #t if OBJ is an alist."
   (and (list? obj)
        (every pair? obj)))
+
+(define (object->json-scm obj)
+  "Prepare OBJ for JSON usage."
+  (cond ((string? obj)  obj)
+        ((number? obj)  obj)
+        ((boolean? obj) obj)
+        ((null? obj)    obj)
+        ((symbol? obj)  (symbol->string obj))
+        ((keyword? obj) (object->json-scm (keyword->symbol obj)))
+        ((alist? obj)   (map object->json-scm obj))
+        ((pair? obj)    (cons (object->json-scm (car obj))
+                              (object->json-scm (cdr obj))))
+        (else           (object->string obj))))
+
+(define* (object->json-string object #:key pretty)
+  "Return OBJECT as a JSON object."
+  (scm->json-string (object->json-scm object) #:pretty pretty))
diff --git a/src/schema.sql b/src/schema.sql
index 329d89d..0ee428c 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -31,18 +31,31 @@ CREATE TABLE Derivations (
   derivation    TEXT NOT NULL,
   evaluation    INTEGER NOT NULL,
   job_name      TEXT NOT NULL,
+  system        TEXT NOT NULL,
+  nix_name      TEXT NOT NULL,
   PRIMARY KEY (derivation, evaluation),
   FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
 );
 
+CREATE TABLE Outputs (
+  build INTEGER NOT NULL,
+  name TEXT NOT NULL,
+  path TEXT NOT NULL,
+  PRIMARY KEY (build, name),
+  FOREIGN KEY (build) REFERENCES Builds (id)
+);
+
 -- Builds are not in a one to one relationship with derivations in order to
 -- keep track of non deterministic compilations.
 CREATE TABLE Builds (
+  id            INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
   derivation    TEXT NOT NULL,
   evaluation    INTEGER NOT NULL,
   log           TEXT NOT NULL,
-  output        TEXT,		-- NULL if build failed
-  PRIMARY KEY (derivation, evaluation, output),
+  status        INTEGER NOT NULL,
+  timestamp     INTEGER NOT NULL,
+  starttime     INTEGER NOT NULL,
+  stoptime      INTEGER NOT NULL,
   FOREIGN KEY (derivation) REFERENCES Derivations (derivation),
   FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
 );
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API.
  2017-07-30 10:07 [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
@ 2017-07-31 14:57 ` Ludovic Courtès
  2017-08-01 19:48   ` Mathieu Othacehe
  2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
  1 sibling, 1 reply; 16+ messages in thread
From: Ludovic Courtès @ 2017-07-31 14:57 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876

Hey!

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> * bin/evaluate.in (fill-job): New procedure.
> (main): Use it to fill informations (nix-name, system) that will later be
> added to database.
> * doc/cuirass.texi (Sections)[Web API]: New section describing the HTTP API.
> (Database)[Derivation]: Add system and nix_name fields.
> (Database)[Builds]: Add id, status, timestamp, starttime and stoptime
> fields. Remove output field.
> (Database)[Outputs]: New table describing the build outputs.
> * src/cuirass/base.scm (build-packages): Add new fields to build object before
> adding it to database.
> * src/cuirass/database.scm (db-get-build, db-get-builds): New procedures to get
> a build by id from database and a list of builds using filter parameters
> respectively.
> * src/cuirass/http.scm (spec->json-string): Move it to utils.scm and rename it
>   object->json-string.
> (object->json-scm): Move it utils.scm.
> (handle-*-request): New helpers procedures.
> (request-parameters): New procedure to parse a request query.
> (url-handler): Add new API's.
> * src/cuirass/utils.scm (object->json-scm, object->json-string): Exported
> procedures moved from http.scm.
> * src/schema.sql (Outputs) : New table.
> (Derivations): Add system and nix_name columns.
> (Builds): Remove output column and add id, status, timestamp, starttime and
> stoptime columns.
> ---
>
> Hi,
>
> Here's a first draft adding partial support for Hydra API in Cuirass.
> It can be tested using curl or, better, with Emacs Guix.
>
> The following elisp will change hydra url to a local running Cuirass server.
>
> (setq guix-hydra-url "http://127.0.0.1:8080/")
>
> Then, it should be possible to use M-x guix-hydra-latest-builds.

Woow!

> The commands guix-hydra-jobsets and guix-hydra-queued-builds won't function
> because the associated API's are not implemented yet.
>
> There's a problem with /build/:build-id/log/raw API because it is trying to fork
> while multiple threads are running (because of decompressed-port function). It seems
> to work but a warning message is printed.

I think libbz2 and libz have the same API, so we could probably adapt
(guix zlib) so that it supports libbz2 as well, which would solve this
problem.

That said, there’s only one place where we work, which is where we spawn
the ‘evaluate’ command.  It may be that spawning it with ‘open-pipe’
from (ice-9 popen) would sidestep the problem because ‘open-pipe’ is
specifically written to permit this.

Some comments follow.

> +@section API description.
> +@cindex description, json
> +
> +@subsection Build informations.

“Information” is always singular (uncountable).  Also, no trailing
period in section names.

> +@example
> +0 -> succeded
            ^
“succeeded”

> +@subsection Build raw log output.
> +
> +It is possible to ask Cuirass for the raw build output log with the API
> +@code{"/build/:build-id/log/raw"} where @code{build-id} is the
                 ^                         ^^^^^^
Nitpick: we should probably write @var{build-id} (and remove the colon).

> +unique id associated to the build in database.
> +
> +The output is a raw text, for example :
> +
> +@example
> +$ curl http://localhost:8080/build/2/log/raw

Initially I was thinking about having something similar in ‘guix
publish’, but that would not include the “/build” part anyway, so it’s
good to have this in Cuirass.

> +(define (db-get-builds db filters)
> +  "Retrieve all builds in database DB which are matched by given FILTERS.
> +FILTERS is an assoc list which possible keys are 'project | 'jobset | 'job |
> +'system | 'nr."

Perhaps the database part of this change could have been a separate
commit (first commit: store the relevant info in the DB and provide
procedures to access it; second commit: implement the HTTP API to access
the DB.)

> +    (("build" build)
> +     (let ((hydra-build (handle-build-request db build)))
> +       (if hydra-build
> +           (respond-json (object->json-string hydra-build))
> +           (respond-build-not-found build))))
> +    (("build" build "log" "raw")
> +     (let ((log-response (handle-log-request db build)))
> +       (if log-response
> +           (respond-text log-response)
> +           (respond-build-not-found build))))
> +    (("api" "latestbuilds")
> +     (let* ((params (request-parameters request))
> +            ;; 'nr parameter is mandatory to limit query size.
> +            (valid-params? (assq-ref params 'nr)))
> +       (if valid-params?
> +           (respond-json (object->json-string
> +                          (handle-builds-request db params)))
> +           (respond-json-with-error 500 "Parameter not defined!"))))

Nice.  :-)

I think it would be nice to have a couple of tests for the HTTP API.
There are helpers in tests/publish.scm and (guix tests http) that could
probably be borrowed here.  WDYT?

Anyway, awesome work!  It’s a really important gap that you’re filling
here.

In the future it would be nice to have an API to add jobsets, trigger an
evaluation, things like that.  That’s probably more difficult though
because we’ll need an authentication mechanism.

Also we should consider Fiberizing the whole thing eventually, so that
Cuirass can actually perform all its activities concurrently.

Thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API.
  2017-07-31 14:57 ` Ludovic Courtès
@ 2017-08-01 19:48   ` Mathieu Othacehe
  2017-08-02  9:22     ` Ludovic Courtès
  0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-08-01 19:48 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 27876


Hi Ludo !

I'll submit a v2 soon, here are some answers to your remarks.

> That said, there’s only one place where we work, which is where we spawn
> the ‘evaluate’ command.  It may be that spawning it with ‘open-pipe’
> from (ice-9 popen) would sidestep the problem because ‘open-pipe’ is
> specifically written to permit this.

The open-pipe solution seems fine indeed !

> I think it would be nice to have a couple of tests for the HTTP API.
> There are helpers in tests/publish.scm and (guix tests http) that could
> probably be borrowed here.  WDYT?

Sure, I'll add some new tests on the new API.

> Anyway, awesome work!  It’s a really important gap that you’re filling
> here.

Thank you ;)

> In the future it would be nice to have an API to add jobsets, trigger an
> evaluation, things like that.  That’s probably more difficult though
> because we’ll need an authentication mechanism.
>
> Also we should consider Fiberizing the whole thing eventually, so that
> Cuirass can actually perform all its activities concurrently.

Yes my planning is the following :

1. Fiberizing the whole thing to make it scalable.
2. Add build start/stop detection : I think the ideal would be wip-ui
branch to get merged before, so that I can use the same mechanism to
parse build output :)
3. Add authentification, and the other API you're describing.

Still plenty of work !!

Mathieu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-07-30 10:07 [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
  2017-07-31 14:57 ` Ludovic Courtès
@ 2017-08-01 19:51 ` Mathieu Othacehe
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
                     ` (2 more replies)
  1 sibling, 3 replies; 16+ messages in thread
From: Mathieu Othacehe @ 2017-08-01 19:51 UTC (permalink / raw)
  To: 27876

* bin/evaluate.in (fill-job): New procedure.
(main): Use it to fill informations (nix-name, system) that will later be
added to database.
* doc/cuirass.texi (Database)[Derivation]: Add system and nix_name fields.
(Database)[Builds]: Add id, status, timestamp, starttime and stoptime
fields. Remove output field.
(Database)[Outputs]: New table describing the build outputs.
* src/cuirass/base.scm (build-packages): Add new fields to build object before
adding it to database.
* src/cuirass/database.scm (db-get-build, db-get-builds): New procedures to get
a build by id from database and a list of builds using filter parameters
respectively.
* src/schema.sql (Outputs) : New table.
(Derivations): Add system and nix_name columns.
(Builds): Remove output column and add id, status, timestamp, starttime and
stoptime columns.
---
 bin/evaluate.in          |  18 +++++-
 doc/cuirass.texi         |  49 ++++++++++++++++-
 src/cuirass/base.scm     |  43 ++++++++++-----
 src/cuirass/database.scm | 139 +++++++++++++++++++++++++++++++++++++++++++----
 src/schema.sql           |  17 +++++-
 5 files changed, 235 insertions(+), 31 deletions(-)

diff --git a/bin/evaluate.in b/bin/evaluate.in
index d1d0767..858c34e 100644
--- a/bin/evaluate.in
+++ b/bin/evaluate.in
@@ -28,9 +28,22 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
 (use-modules (cuirass)
              (ice-9 match)
              (ice-9 pretty-print)
+             (srfi srfi-26)
              (guix build utils)
+             (guix derivations)
              (guix store))
 
+(define (fill-job job eval-id)
+  "Given JOB assoc list, add EVAL-ID to it. Also process #:nix-name and
+  #:system from derivation stored in JOB."
+  (let ((drv (read-derivation-from-file
+              (assq-ref job #:derivation))))
+    ((compose
+      (cut acons #:eval-id eval-id <>)
+      (cut acons #:nix-name (derivation-name drv) <>)
+      (cut acons #:system (derivation-system drv) <>))
+     job)))
+
 (define* (main #:optional (args (command-line)))
   (match args
     ((command load-path guix-package-path cachedir specstr database)
@@ -73,8 +86,9 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
              (pretty-print
               (map (lambda (thunk)
                      (let* ((job  (call-with-time-display thunk))
-                            ;; Keep track of SPEC id in the returned jobs.
-                            (job* (acons #:eval-id eval-id job)))
+                            ;; Fill job with informations that will later be
+                            ;; added to database.
+                            (job* (fill-job job eval-id)))
                        (db-add-derivation db job*)
                        job*))
                    thunks)
diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index 2899ffb..443b53c 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -11,6 +11,7 @@ This manual is for Cuirass version @value{VERSION}, a build automation
 server.
 
 Copyright @copyright{} 2016, 2017 Mathieu Lirzin
+Copyright @copyright{} 2017 Mathieu Othacehe
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -312,6 +313,13 @@ This field holds the @code{id} of an evaluation from the
 
 @item job_name
 This text field holds the name of the job.
+
+@item system
+This text field holds the system name of the derivation.
+
+@item nix_name
+This text field holds the name of the derivation.
+
 @end table
 
 @section Builds
@@ -322,6 +330,9 @@ that builds are not in a one to one relationship with derivations in
 order to keep track of non-deterministic compilations.
 
 @table @code
+@item id
+This is an automatically incrementing numeric identifier.
+
 @item derivation
 This text field holds the absolute name of the derivation file that
 resulted in this build.
@@ -334,9 +345,41 @@ belongs.
 @item log
 This text field holds the absolute file name of the build log file.
 
-@item output
-This text field holds the absolute directory name of the build output or
-@code{NULL} if the build failed.
+@item status
+This integer field holds the build status of the derivation.
+
+@item timestamp
+This integer field holds a timestamp taken at build creation time.
+
+@item starttime
+This integer field holds a timestamp taken at build start time.
+Currently, it has the same value as the @code{timestamp} above.
+
+@item stoptime
+This integer field holds a timestamp taken at build stop time.
+Currently, it has the same value as the @code{timestamp} above.
+
+@end table
+
+@section Outputs
+@cindex outputs, database
+
+This table keep tracks for every eventual build outputs. Each build
+stored in @code{Builds} table may have zero (if it has failed), one or
+multiple outputs.
+
+@table @code
+@item build
+This field holds the @code{id} of a build from the
+@code{Builds} table.
+
+@item name
+This text field holds the name of the output.
+
+@item path
+This text field holds the path of the output.
+
+@end table
 @end table
 
 
diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm
index 6abf871..8068539 100644
--- a/src/cuirass/base.scm
+++ b/src/cuirass/base.scm
@@ -31,6 +31,7 @@
   #:use-module (ice-9 popen)
   #:use-module (ice-9 rdelim)
   #:use-module (ice-9 receive)
+  #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-19)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
@@ -180,25 +181,41 @@ directory and the sha1 of the top level commit in this directory."
 
 (define (build-packages store db jobs)
   "Build JOBS and return a list of Build results."
+
+  (define hydra-build-status
+    ;; Build status as expected by hydra compatible API's.
+    '((succeeded         . 0)
+      (failed            . 1)
+      (failed-dependency . 2)
+      (failed-other      . 3)
+      (cancelled         . 4)))
+
   (define (register job)
     (let* ((name     (assq-ref job #:job-name))
            (drv      (assq-ref job #:derivation))
            (eval-id  (assq-ref job #:eval-id))
            ;; XXX: How to keep logs from several attempts?
            (log      (log-file store drv))
-           (outputs  (match (derivation-path->output-paths drv)
-                       (((names . items) ...)
-                        (filter (lambda (item)
-                                  (valid-path? store item))
-                                items)))))
-      (for-each (lambda (output)
-                  (let ((build `((#:derivation . ,drv)
-                                 (#:eval-id . ,eval-id)
-                                 (#:log . ,log)
-                                 (#:output . ,output))))
-                    (db-add-build db build)))
-                outputs)
-      (format #t "~{~A ~}\n" outputs)
+           (outputs  (filter-map (lambda (res)
+                                   (match res
+                                     ((name . path)
+                                      (and (valid-path? store path)
+                                           `(,name . ,path)))))
+                                 (derivation-path->output-paths drv)))
+           (cur-time (time-second (current-time time-utc))))
+      (let ((build `((#:derivation . ,drv)
+                     (#:eval-id . ,eval-id)
+                     (#:log . ,log)
+                     (#:status .
+                      ,(match (length outputs)
+                         (0 (assq-ref hydra-build-status 'failed))
+                         (_ (assq-ref hydra-build-status 'succeeded))))
+                     (#:outputs . ,outputs)
+                     ;;; XXX: For now, we do not know start/stop build time.
+                     (#:timestamp . ,cur-time)
+                     (#:starttime . ,cur-time)
+                     (#:stoptime . ,cur-time))))
+        (db-add-build db build))
       build))
 
   ;; Pass all the jobs at once so we benefit from as much parallelism as
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 804b8c2..5f60fac 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -1,5 +1,6 @@
 ;;; database.scm -- store evaluation and build results
 ;;; Copyright © 2016, 2017 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of Cuirass.
 ;;;
@@ -21,6 +22,7 @@
   #:use-module (cuirass utils)
   #:use-module (ice-9 match)
   #:use-module (ice-9 rdelim)
+  #:use-module (srfi srfi-1)
   #:use-module (sqlite3)
   #:export (;; Procedures.
             assq-refs
@@ -35,6 +37,8 @@
             db-add-derivation
             db-get-derivation
             db-add-build
+            db-get-build
+            db-get-builds
             read-sql-file
             read-quoted-string
             sqlite-exec
@@ -147,10 +151,12 @@ INSERT OR IGNORE INTO Specifications (repo_name, url, load_path, file, \
 (define (db-add-derivation db job)
   "Store a derivation result in database DB and return its ID."
   (sqlite-exec db "\
-INSERT OR IGNORE INTO Derivations (derivation, job_name, evaluation)\
-  VALUES ('~A', '~A', '~A');"
+INSERT OR IGNORE INTO Derivations (derivation, job_name, system, nix_name, evaluation)\
+  VALUES ('~A', '~A', '~A', '~A', '~A');"
                (assq-ref job #:derivation)
                (assq-ref job #:job-name)
+               (assq-ref job #:system)
+               (assq-ref job #:nix-name)
                (assq-ref job #:eval-id)))
 
 (define (db-get-derivation db id)
@@ -182,15 +188,126 @@ string."
             (else (loop (cons char chars)))))))
 
 (define (db-add-build db build)
-  "Store BUILD in database DB."
-  (sqlite-exec db "\
-INSERT INTO Builds (derivation, evaluation, log, output)\
-  VALUES ('~A', '~A', '~A', '~A');"
-               (assq-ref build #:derivation)
-               (assq-ref build #:eval-id)
-               (assq-ref build #:log)
-               (assq-ref build #:output))
-  (last-insert-rowid db))
+  "Store BUILD in database DB. BUILS eventual outputs are stored
+in the OUTPUTS table."
+  (let* ((build-exec
+          (sqlite-exec db "\
+INSERT INTO Builds (derivation, evaluation, log, status, timestamp, starttime, stoptime)\
+  VALUES ('~A', '~A', '~A', '~A', '~A', '~A', '~A');"
+                       (assq-ref build #:derivation)
+                       (assq-ref build #:eval-id)
+                       (assq-ref build #:log)
+                       (assq-ref build #:status)
+                       (assq-ref build #:timestamp)
+                       (assq-ref build #:starttime)
+                       (assq-ref build #:stoptime)))
+         (build-id (last-insert-rowid db)))
+    (for-each (lambda (output)
+                (match output
+                  ((name . path)
+                   (sqlite-exec db "\
+INSERT INTO Outputs (build, name, path) VALUES ('~A', '~A', '~A');"
+                                build-id name path))))
+              (assq-ref build #:outputs))
+    build-id))
+
+(define (db-get-outputs db build-id)
+  "Retrieve the OUTPUTS of the build identified by BUILD-ID in DB database."
+  (let loop ((rows
+              (sqlite-exec db "SELECT name, path FROM Outputs WHERE build='~A';"
+                           build-id))
+             (outputs '()))
+    (match rows
+      (() outputs)
+      ((#(name path)
+        . rest)
+       (loop rest
+             (cons `(,name . ((#:path . ,path)))
+                   outputs))))))
+
+(define db-build-request "\
+SELECT Builds.id, Builds.timestamp, Builds.starttime, Builds.stoptime, Builds.log, Builds.status,\
+Derivations.job_name, Derivations.system, Derivations.nix_name,\
+Specifications.repo_name, Specifications.branch \
+FROM Builds \
+INNER JOIN Derivations ON Builds.derivation = Derivations.derivation and Builds.evaluation = Derivations.evaluation \
+INNER JOIN Evaluations ON Derivations.evaluation = Evaluations.id \
+INNER JOIN Specifications ON Evaluations.specification = Specifications.repo_name")
+
+(define (db-format-build db build)
+  (match build
+    (#(id timestamp starttime stoptime log status job-name system
+          nix-name repo-name branch)
+       `((#:id        . ,id)
+         (#:timestamp . ,timestamp)
+         (#:starttime . ,starttime)
+         (#:stoptime  . ,stoptime)
+         (#:log       . ,log)
+         (#:status    . ,status)
+         (#:job-name  . ,job-name)
+         (#:system    . ,system)
+         (#:nix-name  . ,nix-name)
+         (#:repo-name . ,repo-name)
+         (#:outputs   . ,(db-get-outputs db id))
+         (#:branch    . ,branch)))))
+
+(define (db-get-build db id)
+  "Retrieve a build in database DB which corresponds to ID."
+  (let ((res (sqlite-exec db (string-append db-build-request
+                                            " WHERE Builds.id='~A';") id)))
+    (match res
+      ((build)
+       (db-format-build db build))
+      (() #f))))
+
+(define (db-get-builds db filters)
+  "Retrieve all builds in database DB which are matched by given FILTERS.
+FILTERS is an assoc list which possible keys are 'project | 'jobset | 'job |
+'system | 'nr."
+
+  (define (format-where-clause filters)
+    (let ((where-clause
+           (filter-map
+            (lambda (param)
+              (match param
+                (('project project)
+                 (format #f "Specifications.repo_name='~A'" project))
+                (('jobset jobset)
+                 (format #f "Specifications.branch='~A'" jobset))
+                (('job job)
+                 (format #f "Derivations.job_name='~A'" job))
+                (('system system)
+                 (format #f "Derivations.system='~A'" system))
+                (_ #f)))
+            filters)))
+      (if (> (length where-clause) 0)
+          (string-append
+           "WHERE "
+           (string-join where-clause " AND "))
+          "")))
+
+  (define (format-order-clause filters)
+    (any
+     (lambda (param)
+       (match param
+         (('nr number)
+          (format #f "ORDER BY Builds.id DESC LIMIT '~A';" number))
+         (_ #f)))
+     filters))
+
+  (let loop ((rows
+              (sqlite-exec db (string-append
+                               db-build-request
+                               " "
+                               (format-where-clause filters)
+                               " "
+                               (format-order-clause filters))))
+             (outputs '()))
+    (match rows
+      (() outputs)
+      ((row . rest)
+       (loop rest
+             (cons (db-format-build db row) outputs))))))
 
 (define (db-get-stamp db spec)
   "Return a stamp corresponding to specification SPEC in database DB."
diff --git a/src/schema.sql b/src/schema.sql
index 329d89d..0ee428c 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -31,18 +31,31 @@ CREATE TABLE Derivations (
   derivation    TEXT NOT NULL,
   evaluation    INTEGER NOT NULL,
   job_name      TEXT NOT NULL,
+  system        TEXT NOT NULL,
+  nix_name      TEXT NOT NULL,
   PRIMARY KEY (derivation, evaluation),
   FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
 );
 
+CREATE TABLE Outputs (
+  build INTEGER NOT NULL,
+  name TEXT NOT NULL,
+  path TEXT NOT NULL,
+  PRIMARY KEY (build, name),
+  FOREIGN KEY (build) REFERENCES Builds (id)
+);
+
 -- Builds are not in a one to one relationship with derivations in order to
 -- keep track of non deterministic compilations.
 CREATE TABLE Builds (
+  id            INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
   derivation    TEXT NOT NULL,
   evaluation    INTEGER NOT NULL,
   log           TEXT NOT NULL,
-  output        TEXT,		-- NULL if build failed
-  PRIMARY KEY (derivation, evaluation, output),
+  status        INTEGER NOT NULL,
+  timestamp     INTEGER NOT NULL,
+  starttime     INTEGER NOT NULL,
+  stoptime      INTEGER NOT NULL,
   FOREIGN KEY (derivation) REFERENCES Derivations (derivation),
   FOREIGN KEY (evaluation) REFERENCES Evaluations (id)
 );
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API.
  2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
@ 2017-08-01 19:51   ` Mathieu Othacehe
  2017-09-08 16:00     ` Ludovic Courtès
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new " Mathieu Othacehe
  2017-09-08 15:59   ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Ludovic Courtès
  2 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-08-01 19:51 UTC (permalink / raw)
  To: 27876

* doc/cuirass.texi (Sections)[Web API]: New section describing the HTTP API.
* src/cuirass/http.scm (spec->json-string): Move it to utils.scm and rename it
  object->json-string.
(object->json-scm): Move it utils.scm.
(handle-*-request): New helpers procedures.
(request-parameters): New procedure to parse a request query.
(url-handler): Add new API's.
* src/cuirass/utils.scm (object->json-scm, object->json-string): Exported
procedures moved from http.scm.
---
 doc/cuirass.texi         | 191 +++++++++++++++++++++++++++++++++++++++++++++++
 src/cuirass/database.scm |  29 +++----
 src/cuirass/http.scm     | 150 ++++++++++++++++++++++++++++++-------
 src/cuirass/utils.scm    |  22 +++++-
 4 files changed, 350 insertions(+), 42 deletions(-)

diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index 443b53c..bac2e54 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -57,6 +57,7 @@ Tutorial sections:
 Reference sections:
 * Invocation::                  How to run Cuirass.
 * Database::                    About the database schema.
+* Web API::                     Description of the Web API.
 
 * Contributing::                Your help needed!
 * GNU Free Documentation License::  The license of this manual.
@@ -380,8 +381,198 @@ This text field holds the name of the output.
 This text field holds the path of the output.
 
 @end table
+
+@c *********************************************************************
+@node Web API
+@chapter Web API
+@cindex web api
+
+Cuirass web API is derived from Hydra one, see @url{https://github.com/NixOS/hydra/blob/master/doc/manual/api.xml, Hydra API description}.
+
+For now only a subset of this API is implemented.
+
+@section API description
+@cindex description, json
+
+@subsection Build information
+
+It is possible to query Cuirass web server for build informations. The
+dedicated API is "/build/@var{build-id}" where @var{build-id} is the
+unique id associated to the build in database.
+
+For instance, querying a local Cuirass web server can be done with
+@code{curl} and @code{jq} to format the JSON response :
+
+@example
+$ curl -s "http://localhost:8080/build/2" | jq
+
+@{
+  "id": 2,
+  "project": "guix",
+  "jobset": "master",
+  "job": "acpica-20150410-job",
+  "timestamp": 1501347493,
+  "starttime": 1501347493,
+  "stoptime": 1501347493,
+  "buildoutputs": @{
+    "out": @{
+      "path": "/gnu/store/6g3njhfzqpdm335s7qhvmwvs5l7gcbq1-acpica-20150410"
+    @}
+  @},
+  "system": "x86_64-linux",
+  "nixname": "acpica-20150410",
+  "buildstatus": 0,
+  "busy": 0,
+  "priority": 0,
+  "finished": 1,
+  "buildproducts": null,
+  "releasename": null,
+  "buildinputs_builds": null
+@}
+@end example
+
+If requested @var{build-id} is not known, the HTTP code 404 is
+answered with a JSON error message. For example :
+
+@example
+$ curl -s "http://localhost:8080/build/fff"
+
+@{"error" : "Build with ID fff doesn't exist."@}
+@end example
+
+The nominal output is a JSON object whose fields are described
+hereafter.
+
+@table @code
+@item id
+The unique build id.
+
+@item project
+The associated specification name, as a string.
+
+@item jobset
+The associated specification branch, as a string.
+
+@item job
+The associated job-name, as a string.
+
+@item timestamp
+Timestamp taken at build creation time.
+
+@item starttime
+Timestamp taken at build start time.
+
+@item stoptime
+Timestamp taken at build stop time.
+
+@item buildoutputs
+Build outputs as a JSON object. The keys names are referring to the
+eventual output names. The associated value is another JSON object which
+only key is @code{path}. @code{path} value is the output directory in
+store as a string.
+
+@item system
+System name of the build, as a string.
+
+@item nixname
+Derivation name, as a string.
+
+@item buildstatus
+Build status, as an integer. Possible values are :
+
+@example
+0 -> succeeded
+1 -> failed
+2 -> failed dependency
+3 -> failed other
+4 -> cancelled
+@end example
+
+@item busy
+Whether the build is pending, as an integer (not implemented yet).
+
+@item priority
+Build priority, as an integer (not implemented yet).
+
+@item finished
+Build finished, as an integer (not implemented yet : always 1).
+
+@item buildproducts
+Build products in store as a JSON object (not implemented yet).
+
+@item releasename
+Unknown, not implemented yet.
+
+@item buildinputs_builds
+Inputs used for the build, as a JSON object (not implemented yet).
+
+@end table
+
+@subsection Build raw log output
+
+It is possible to ask Cuirass for the raw build output log with the API
+"/build/@var{build-id}/log/raw" where @var{build-id} is the
+unique id associated to the build in database.
+
+The output is a raw text, for example :
+
+@example
+$ curl http://localhost:8080/build/2/log/raw
+
+starting phase `set-SOURCE-DATE-EPOCH'
+phase `set-SOURCE-DATE-EPOCH' succeeded after 0.0 seconds
+starting phase `set-paths'
+...
+@end example
+
+If requested @var{build-id} is not known, the HTTP code 404 is
+answered with a JSON error message. For example :
+
+@example
+$ curl -s "http://localhost:8080/build/fff/log/raw"
+
+@{"error" : "Build with ID fff doesn't exist."@}
+@end example
+
+@subsection Latest builds
+
+The list of latest builds can be obtained with the API
+"/api/latestbuilds".  The output is a JSON array of
+builds. Builds are represented as in "/build/@var{build-id} API.
+
+This request accepts a mandatory parameter and multiple optional ones.
+
+@table @code
+@item nr
+Limit query result to nr elements. This parameter is @emph{mandatory}.
+
+@item project
+Filter query result to builds with the given @code{project}.
+
+@item jobset
+Filter query result to builds with the given @code{jobset}.
+
+@item job
+Filter query result to builds with the given @code{job} name.
+
+@item system
+Filter query result to builds with the given @code{system}.
+
 @end table
 
+For example, to ask for the ten last builds :
+
+@example
+$ curl "http://localhost:8080/api/latestbuilds?nr=10"
+@end example
+
+or the five last builds which project is ``guix'' and jobset ``master' :
+
+@example
+$ curl "http://localhost:8080/api/latestbuilds?nr=5&project=guix&jobset=master"
+@end example
+
+If no builds matching given parameters are found and empty JSON array is returned.
 
 @c *********************************************************************
 @node Contributing
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 5f60fac..6b84a48 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -226,7 +226,7 @@ INSERT INTO Outputs (build, name, path) VALUES ('~A', '~A', '~A');"
                    outputs))))))
 
 (define db-build-request "\
-SELECT Builds.id, Builds.timestamp, Builds.starttime, Builds.stoptime, Builds.log, Builds.status,\
+SELECT Builds.id, Builds.timestamp, Builds.starttime, Builds.stoptime, Builds.log, Builds.status, Builds.derivation,\
 Derivations.job_name, Derivations.system, Derivations.nix_name,\
 Specifications.repo_name, Specifications.branch \
 FROM Builds \
@@ -236,20 +236,21 @@ INNER JOIN Specifications ON Evaluations.specification = Specifications.repo_nam
 
 (define (db-format-build db build)
   (match build
-    (#(id timestamp starttime stoptime log status job-name system
+    (#(id timestamp starttime stoptime log status derivation job-name system
           nix-name repo-name branch)
-       `((#:id        . ,id)
-         (#:timestamp . ,timestamp)
-         (#:starttime . ,starttime)
-         (#:stoptime  . ,stoptime)
-         (#:log       . ,log)
-         (#:status    . ,status)
-         (#:job-name  . ,job-name)
-         (#:system    . ,system)
-         (#:nix-name  . ,nix-name)
-         (#:repo-name . ,repo-name)
-         (#:outputs   . ,(db-get-outputs db id))
-         (#:branch    . ,branch)))))
+     `((#:id         . ,id)
+       (#:timestamp  . ,timestamp)
+       (#:starttime  . ,starttime)
+       (#:stoptime   . ,stoptime)
+       (#:log        . ,log)
+       (#:status     . ,status)
+       (#:derivation . ,derivation)
+       (#:job-name   . ,job-name)
+       (#:system     . ,system)
+       (#:nix-name   . ,nix-name)
+       (#:repo-name  . ,repo-name)
+       (#:outputs    . ,(db-get-outputs db id))
+       (#:branch     . ,branch)))))
 
 (define (db-get-build db id)
   "Retrieve a build in database DB which corresponds to ID."
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 33cd37b..23c3ad7 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -1,5 +1,6 @@
 ;;;; http.scm -- HTTP API
 ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of Cuirass.
 ;;;
@@ -19,52 +20,147 @@
 (define-module (cuirass http)
   #:use-module (cuirass database)
   #:use-module (cuirass utils)
-  #:use-module (ice-9 hash-table)
+  #:use-module (guix config)
+  #:use-module (guix build utils)
+  #:use-module (guix utils)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 popen)
   #:use-module (json)
   #:use-module (web request)
   #:use-module (web response)
   #:use-module (web server)
   #:use-module (web uri)
-  #:export (spec->json-string
-            run-cuirass-server))
+  #:export (run-cuirass-server))
 
-;;;
-;;; JSON format.
-;;;
+(define (build->hydra-build build)
+  "Convert BUILD to an assoc list matching hydra API format."
+  `((#:id . ,(assq-ref build #:id))
+    (#:project . ,(assq-ref build #:repo-name))
+    (#:jobset . ,(assq-ref build #:branch))
+    (#:job . ,(assq-ref build #:job-name))
+    (#:timestamp . ,(assq-ref build #:timestamp))
+    (#:starttime . ,(assq-ref build #:starttime))
+    (#:stoptime . ,(assq-ref build #:stoptime))
+    (#:buildoutputs . ,(assq-ref build #:outputs))
+    (#:system . ,(assq-ref build #:system))
+    (#:nixname . ,(assq-ref build #:nix-name))
+    (#:buildstatus . ,(assq-ref build #:status))
+
+    ;; TODO: Fill the fields above with correct values.
+    (#:busy . 0)
+    (#:priority . 0)
+    (#:finished . 1)
+    (#:buildproducts . #nil)
+    (#:releasename . #nil)
+    (#:buildinputs_builds . #nil)))
+
+(define (handle-build-request db build-id)
+  "Retrieve build identified by BUILD-ID in DB and convert it to hydra
+  format. Return #f is not build was found."
+  (let ((build (db-get-build db build-id)))
+    (and=> build build->hydra-build)))
 
-(define (object->json-scm obj)
-  "Prepare OBJ for JSON usage."
-  (cond ((string? obj)  obj)
-        ((number? obj)  obj)
-        ((boolean? obj) obj)
-        ((null? obj)    obj)
-        ((symbol? obj)  (symbol->string obj))
-        ((keyword? obj) (object->json-scm (keyword->symbol obj)))
-        ((alist? obj)   (alist->hash-table (map object->json-scm obj)))
-        ((pair? obj)    (cons (object->json-scm (car obj))
-                              (object->json-scm (cdr obj))))
-        (else           (object->string obj))))
-
-(define* (spec->json-string spec #:key pretty)
-  "Return SPEC as a JSON object."
-  (scm->json-string (object->json-scm spec) #:pretty pretty))
+(define (handle-builds-request db filters)
+  "Retrieve all builds matched by FILTERS in DB and convert them to hydra
+  format."
+  (let ((builds (db-get-builds db filters)))
+    (map build->hydra-build builds)))
+
+(define (handle-log-request db build)
+  "Retrieve the log file of BUILD. Return a lambda which PORT argument is an
+  input port from which the content of the log file can be read or #f if the
+  log file is not readable."
+  (let* ((log (assq-ref build #:log))
+         (access (and (string? log)
+                      (access? log R_OK))))
+    (and access
+         (lambda (out-port)
+           (let ((in-pipe-port
+                  (open-input-pipe
+                   (format #f "~a -dc ~a" %bzip2 log))))
+             (dump-port in-pipe-port out-port)
+             (close-pipe in-pipe-port))))))
+
+(define (request-parameters request)
+  "Parse the REQUEST query parameters and return them under the form
+  '((parameter value) ...)."
+  (let* ((uri (request-uri request))
+         (query (uri-query uri)))
+    (and query
+         (map (lambda (param)
+                (match (string-split param #\=)
+                  ((key param)
+                   (list (string->symbol key) param))))
+              (string-split query #\&)))))
 
 \f
 ;;;
 ;;; Web server.
 ;;;
+;;; The api is derived from the hydra one. It is partially described here :
+;;;
+;;; https://github.com/NixOS/hydra/blob/master/doc/manual/api.xml
+;;;
 
 (define (request-path-components request)
   (split-and-decode-uri-path (uri-path (request-uri request))))
 
 (define (url-handler request body db)
+
   (define* (respond response #:key body (db db))
     (values response body db))
+
+  (define-syntax-rule (respond-json body ...)
+    (respond '((content-type . (application/json)))
+             #:body body ...))
+
+  (define-syntax-rule (respond-text body ...)
+    (respond '((content-type . (text/plain)))
+             #:body body ...))
+
+  (define-syntax-rule (respond-json-with-error error-code message)
+    (respond
+     (build-response #:headers '((content-type . (application/json)))
+                     #:code error-code)
+     #:body
+     (object->json-string
+      `((error . ,message)))))
+
+  (define (respond-build-not-found build-id)
+    (respond-json-with-error
+     404
+     (format #f "Build with ID ~a doesn't exist." build-id)))
+
+  (define (respond-build-log-not-found build)
+    (let ((drv (assq-ref build #:derivation)))
+      (respond-json-with-error
+       404
+       (format #f "The build log of derivation ~a is not available." drv))))
+
   (match (request-path-components request)
     (((or "jobsets" "specifications") . rest)
-     (respond '((content-type . (application/json)))
-              #:body (spec->json-string (car (db-get-specifications db)))))
+     (respond-json (object->json-string (car (db-get-specifications db)))))
+    (("build" build-id)
+     (let ((hydra-build (handle-build-request db build-id)))
+       (if hydra-build
+           (respond-json (object->json-string hydra-build))
+           (respond-build-not-found build-id))))
+    (("build" build-id "log" "raw")
+     (let ((build (db-get-build db build-id)))
+       (if build
+           (let ((log-response (handle-log-request db build)))
+             (if log-response
+                 (respond-text log-response)
+                 (respond-build-log-not-found build)))
+           (respond-build-not-found build-id))))
+    (("api" "latestbuilds")
+     (let* ((params (request-parameters request))
+            ;; 'nr parameter is mandatory to limit query size.
+            (valid-params? (assq-ref params 'nr)))
+       (if valid-params?
+           (respond-json (object->json-string
+                          (handle-builds-request db params)))
+           (respond-json-with-error 500 "Parameter not defined!"))))
     (_
      (respond (build-response #:code 404)
               #:body (string-append "Resource not found: "
@@ -73,6 +169,6 @@
 (define* (run-cuirass-server db #:key (port 8080))
   (format (current-error-port) "listening on port ~A~%" port)
   (run-server url-handler
-              'http                     ;server implementation
-              `(#:port ,port)           ;implementation parameters
-              db))                      ;state
+              'http
+              `(#:port ,port)
+              db))
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index d966543..a932674 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -21,9 +21,29 @@
 (define-module (cuirass utils)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
-  #:export (alist?))
+  #:use-module (json)
+  #:export (alist?
+            object->json-scm
+            object->json-string))
 
 (define (alist? obj)
   "Return #t if OBJ is an alist."
   (and (list? obj)
        (every pair? obj)))
+
+(define (object->json-scm obj)
+  "Prepare OBJ for JSON usage."
+  (cond ((string? obj)  obj)
+        ((number? obj)  obj)
+        ((boolean? obj) obj)
+        ((null? obj)    obj)
+        ((symbol? obj)  (symbol->string obj))
+        ((keyword? obj) (object->json-scm (keyword->symbol obj)))
+        ((alist? obj)   (map object->json-scm obj))
+        ((pair? obj)    (cons (object->json-scm (car obj))
+                              (object->json-scm (cdr obj))))
+        (else           (object->string obj))))
+
+(define* (object->json-string object #:key pretty)
+  "Return OBJECT as a JSON object."
+  (scm->json-string (object->json-scm object) #:pretty pretty))
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new HTTP API.
  2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
@ 2017-08-01 19:51   ` Mathieu Othacehe
  2017-09-08 16:01     ` Ludovic Courtès
  2017-09-08 15:59   ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Ludovic Courtès
  2 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-08-01 19:51 UTC (permalink / raw)
  To: 27876

* tests/http.scm: Add various tests on new HTTP API.
---
 tests/http.scm | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 192 insertions(+), 27 deletions(-)

diff --git a/tests/http.scm b/tests/http.scm
index 4c5214d..99daf23 100644
--- a/tests/http.scm
+++ b/tests/http.scm
@@ -1,6 +1,7 @@
 ;;; http.scm -- tests for (cuirass http) module
 ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of Cuirass.
 ;;;
@@ -18,7 +19,14 @@
 ;;; along with Cuirass.  If not, see <http://www.gnu.org/licenses/>.
 
 (use-modules (cuirass http)
+             (cuirass database)
+             (cuirass utils)
+             (guix utils)
+             (guix build utils)
              (json)
+             (web client)
+             (web response)
+             (rnrs bytevectors)
              (srfi srfi-1)
              (srfi srfi-64))
 
@@ -42,30 +50,187 @@
                   #t
                   t1)))
 
-(test-begin "http")
-
-(test-assert "spec->json-string"
-  ;; Note: We cannot compare the strings directly because field ordering
-  ;; depends on the hash algorithm used in Guile's hash tables, and that
-  ;; algorithm changed in Guile 2.2.
-  (hash-table=?
-   (call-with-input-string
-       (string-append "{"
-                      "\"boolean\" : false,"
-                      "\"string\" : \"guix\","
-                      "\"alist\" : {\"subset\" : \"hello\"},"
-                      "\"list\" : [1, \"2\", \"three\"],"
-                      "\"symbol\" : \"hydra-jobs\","
-                      "\"number\" : 1"
-                      "}")
-     json->scm)
-   (call-with-input-string
-       (spec->json-string '((#:number . 1)
-                            (string . "guix")
-                            ("symbol" . hydra-jobs)
-                            (#:alist (subset . "hello"))
-                            (list 1 "2" #:three)
-                            ("boolean" . #f)))
-     json->scm)))
-
-(test-end)
+(define (http-get-body uri)
+  (call-with-values (lambda () (http-get uri))
+    (lambda (response body) body)))
+
+(define (wait-until-ready port)
+  ;; Wait until the server is accepting connections.
+  (let ((conn (socket PF_INET SOCK_STREAM 0)))
+    (let loop ()
+      (unless (false-if-exception
+               (connect conn AF_INET (inet-pton AF_INET "127.0.0.1") port))
+        (loop)))))
+
+(define (test-cuirass-uri route)
+  (string-append "http://localhost:6688" route))
+
+(define database-name
+  ;; Use an empty and temporary database for the tests.
+  (string-append (getcwd) "/" (number->string (getpid)) "-tmp.db"))
+
+(define %db
+  ;; Global Slot for a database object.
+  (make-parameter #t))
+
+(define build-query-result
+  '((#:id . 1)
+    (#:project . "guix")
+    (#:jobset . "master")
+    (#:job . "fake-job")
+    (#:timestamp . 1501347493)
+    (#:starttime . 1501347493)
+    (#:stoptime . 1501347493)
+    (#:buildoutputs . ((out ("path" . "/gnu/store/fake-1.0"))))
+    (#:system . "x86_64-linux")
+    (#:nixname . "fake-1.0")
+    (#:buildstatus . 0)
+    (#:busy . 0)
+    (#:priority . 0)
+    (#:finished . 1)
+    (#:buildproducts . #nil)
+    (#:releasename . #nil)
+    (#:buildinputs_builds . #nil)))
+
+(define log-file-name
+  ;; Use a fake temporary log file.
+  (string-append (getcwd) "/" (number->string (getpid)) "-log.txt"))
+
+(call-with-output-file log-file-name
+  ;; Write "build log" string compressed with bzip2 inside LOG-FILE-NAME.
+  (lambda (out)
+    (dump-port
+     (call-with-input-string "build log"
+       (lambda (port)
+         (compressed-port 'bzip2 port)))
+     out)))
+
+(test-group-with-cleanup "http"
+  (test-assert "object->json-string"
+    ;; Note: We cannot compare the strings directly because field ordering
+    ;; depends on the hash algorithm used in Guile's hash tables, and that
+    ;; algorithm changed in Guile 2.2.
+    (hash-table=?
+     (call-with-input-string
+         (string-append "{"
+                        "\"boolean\" : false,"
+                        "\"string\" : \"guix\","
+                        "\"alist\" : {\"subset\" : \"hello\"},"
+                        "\"list\" : [1, \"2\", \"three\"],"
+                        "\"symbol\" : \"hydra-jobs\","
+                        "\"number\" : 1"
+                        "}")
+       json->scm)
+     (call-with-input-string
+         (object->json-string '((#:number . 1)
+                                (string . "guix")
+                                ("symbol" . hydra-jobs)
+                                (#:alist (subset . "hello"))
+                                (list 1 "2" #:three)
+                                ("boolean" . #f)))
+       json->scm)))
+
+  (test-assert "db-init"
+    (%db (db-init database-name)))
+
+  (test-assert "cuirass-run"
+    (call-with-new-thread
+     (lambda ()
+       (run-cuirass-server (%db) #:port 6688))))
+
+  (test-assert "wait-server"
+    (wait-until-ready 6688))
+
+  (test-assert "fill-db"
+    (let ((build
+           `((#:derivation . "/gnu/store/fake.drv")
+             (#:eval-id . 1)
+             (#:log . ,log-file-name)
+             (#:status . 0)
+             (#:outputs . (("out" . "/gnu/store/fake-1.0")))
+             (#:timestamp . 1501347493)
+             (#:starttime . 1501347493)
+             (#:stoptime . 1501347493)))
+          (derivation
+           '((#:derivation . "/gnu/store/fake.drv")
+             (#:job-name . "fake-job")
+             (#:system . "x86_64-linux")
+             (#:nix-name . "fake-1.0")
+             (#:eval-id . 1)))
+          (specification
+           '((#:name . "guix")
+             (#:url . "git://git.savannah.gnu.org/guix.git")
+             (#:load-path . ".")
+             (#:file . "/tmp/gnu-system.scm")
+             (#:proc . hydra-jobs)
+             (#:arguments (subset . "hello"))
+             (#:branch . "master")
+             (#:tag . #f)
+             (#:commit . #f)
+             (#:no-compile? . #f)))
+          (evaluation
+           '((#:specification . "guix")
+             (#:revision . 1))))
+      (db-add-build (%db) build)
+      (db-add-derivation (%db) derivation)
+      (db-add-specification (%db) specification)
+      (db-add-evaluation (%db) evaluation)))
+
+  (test-assert "/build/1"
+    (hash-table=?
+     (call-with-input-string
+         (utf8->string
+          (http-get-body (test-cuirass-uri "/build/1")))
+       json->scm)
+     (call-with-input-string
+         (object->json-string build-query-result)
+       json->scm)))
+
+  (test-equal "/build/1/log/raw"
+    "build log"
+    (http-get-body
+     (test-cuirass-uri "/build/1/log/raw")))
+
+  (test-equal "/build/2"
+    404
+    (response-code (http-get (test-cuirass-uri "/build/2"))))
+
+  (test-equal "/build/2/log/raw"
+    404
+    (response-code (http-get (test-cuirass-uri "/build/2/log/raw"))))
+
+  (test-equal "/api/latestbuilds"
+    500
+    (response-code (http-get (test-cuirass-uri "/api/latestbuilds"))))
+
+  (test-assert "/api/latestbuilds?nr=1&project=guix&jobset=master"
+    (let ((hash-list
+           (call-with-input-string
+               (utf8->string
+                (http-get-body
+                 (test-cuirass-uri
+                  "/api/latestbuilds?nr=1&project=guix&jobset=master")))
+             json->scm)))
+      (and (= (length hash-list) 1)
+           (hash-table=?
+            (car hash-list)
+            (call-with-input-string
+                (object->json-string build-query-result)
+              json->scm)))))
+
+  (test-assert "/api/latestbuilds?nr=1&project=gnu"
+    ;; The result should be an empty JSON array.
+    (let ((hash-list
+           (call-with-input-string
+               (utf8->string
+                (http-get-body
+                 (test-cuirass-uri
+                  "/api/latestbuilds?nr=1&project=gnu")))
+             json->scm)))
+      (= (length hash-list) 0)))
+
+  (test-assert "db-close"
+    (db-close (%db)))
+
+  (delete-file database-name)
+  (delete-file log-file-name))
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API.
  2017-08-01 19:48   ` Mathieu Othacehe
@ 2017-08-02  9:22     ` Ludovic Courtès
  0 siblings, 0 replies; 16+ messages in thread
From: Ludovic Courtès @ 2017-08-02  9:22 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876

Heya,

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

>> That said, there’s only one place where we work, which is where we spawn
                                              ^^^^
I meant “fork”.  :-)

>> the ‘evaluate’ command.  It may be that spawning it with ‘open-pipe’
>> from (ice-9 popen) would sidestep the problem because ‘open-pipe’ is
>> specifically written to permit this.
>
> The open-pipe solution seems fine indeed !

Good.

> Yes my planning is the following :
>
> 1. Fiberizing the whole thing to make it scalable.
> 2. Add build start/stop detection : I think the ideal would be wip-ui
> branch to get merged before, so that I can use the same mechanism to
> parse build output :)
> 3. Add authentification, and the other API you're describing.

Sounds good!

So it looks like you kind of like the ‘wip-ui’ approach.  I wasn’t sure
but maybe that’s the way to go.  After all, even if it’s a bit of a
hack, the API itself could still work if/when we have a better protocol
with the daemon.  We’ll see…

Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new " Mathieu Othacehe
@ 2017-09-08 15:59   ` Ludovic Courtès
  2017-09-08 19:13     ` bug#27876: " Mathieu Othacehe
  2 siblings, 1 reply; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-08 15:59 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876

Hi Mathieu,

I’m sorry that this patch series fell through the cracks!

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> * bin/evaluate.in (fill-job): New procedure.
> (main): Use it to fill informations (nix-name, system) that will later be
> added to database.
> * doc/cuirass.texi (Database)[Derivation]: Add system and nix_name fields.
> (Database)[Builds]: Add id, status, timestamp, starttime and stoptime
> fields. Remove output field.
> (Database)[Outputs]: New table describing the build outputs.
> * src/cuirass/base.scm (build-packages): Add new fields to build object before
> adding it to database.
> * src/cuirass/database.scm (db-get-build, db-get-builds): New procedures to get
> a build by id from database and a list of builds using filter parameters
> respectively.
> * src/schema.sql (Outputs) : New table.
> (Derivations): Add system and nix_name columns.
> (Builds): Remove output column and add id, status, timestamp, starttime and
> stoptime columns.

Overall looks good.  Just some minor comments and you can push:

> +(define (fill-job job eval-id)
> +  "Given JOB assoc list, add EVAL-ID to it. Also process #:nix-name and
> +  #:system from derivation stored in JOB."

Rather:

  “Augment the JOB alist with EVAL-ID and additional information
  gathered from JOB’s #:derivation.”

> +  (let ((drv (read-derivation-from-file
> +              (assq-ref job #:derivation))))
> +    ((compose
> +      (cut acons #:eval-id eval-id <>)
> +      (cut acons #:nix-name (derivation-name drv) <>)
> +      (cut acons #:system (derivation-system drv) <>))
> +     job)))

Rather:

  `((#:eval-id . ,eval-id)
    (#:nix-name . ,…)
    …
    ,@job))


[...]

>  Copyright @copyright{} 2016, 2017 Mathieu Lirzin
> +Copyright @copyright{} 2017 Mathieu Othacehe

Add @* at the end of the previous line.

>  @quotation
>  Permission is granted to copy, distribute and/or modify this document
> @@ -312,6 +313,13 @@ This field holds the @code{id} of an evaluation from the
>  
>  @item job_name
>  This text field holds the name of the job.
> +
> +@item system
> +This text field holds the system name of the derivation.
> +
> +@item nix_name
> +This text field holds the name of the derivation.

Maybe add: “---e.g., @code{coreutils-8.28}”.  (Am I right?)

Otherwise OK!

Of course if would be awesome to have more tests, but let’s not delay
this patch series further.  :-)

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API.
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
@ 2017-09-08 16:00     ` Ludovic Courtès
  0 siblings, 0 replies; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-08 16:00 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> * doc/cuirass.texi (Sections)[Web API]: New section describing the HTTP API.
> * src/cuirass/http.scm (spec->json-string): Move it to utils.scm and rename it
>   object->json-string.
> (object->json-scm): Move it utils.scm.
> (handle-*-request): New helpers procedures.
> (request-parameters): New procedure to parse a request query.
> (url-handler): Add new API's.
> * src/cuirass/utils.scm (object->json-scm, object->json-string): Exported
> procedures moved from http.scm.

All right!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new HTTP API.
  2017-08-01 19:51   ` [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new " Mathieu Othacehe
@ 2017-09-08 16:01     ` Ludovic Courtès
  0 siblings, 0 replies; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-08 16:01 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> * tests/http.scm: Add various tests on new HTTP API.

Excellent (can even be squashed with the previous patch since they go
together.)

Thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#27876: [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-08 15:59   ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Ludovic Courtès
@ 2017-09-08 19:13     ` Mathieu Othacehe
  2017-09-08 20:44       ` [bug#27876] " Ludovic Courtès
  0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-09-08 19:13 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 27876-done


Hi Ludo !

> I’m sorry that this patch series fell through the cracks!

No problem, thanks for reviewing :)

> Maybe add: “---e.g., @code{coreutils-8.28}”.  (Am I right?)

You are !

I pushed this patch and the two following squashed together, as you
suggested. Note that your recent patch on "db-add-build" seems useless
now that Builds's primary key is an autoincremented index.

I removed most of your patch during my rebase, is that ok for you ?

Now this is merged, I'll start working on build start/stop detection
next week.

Thanks,

Mathieu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-08 19:13     ` bug#27876: " Mathieu Othacehe
@ 2017-09-08 20:44       ` Ludovic Courtès
  2017-09-09  7:48         ` Mathieu Othacehe
  0 siblings, 1 reply; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-08 20:44 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876-done

Hi!

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> I pushed this patch and the two following squashed together, as you
> suggested. Note that your recent patch on "db-add-build" seems useless
> now that Builds's primary key is an autoincremented index.
>
> I removed most of your patch during my rebase, is that ok for you ?

The goal of 72f2b6b77cc4e3d7629bdf34e6daee05398b8de1 was to make sure
that, if you add the same build twice, it’ll just work and you won’t get
duplicate entries in the database (although the test only tested that
‘db-add-build’ itself doesn’t throw an exception.)

With an autoincremented index, I suppose we might want to make sure that
‘db-add-build’ does not add a new entry for a build that’s already in
the table.  WDYT?

Thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-08 20:44       ` [bug#27876] " Ludovic Courtès
@ 2017-09-09  7:48         ` Mathieu Othacehe
  2017-09-10 13:01           ` Ludovic Courtès
  0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-09-09  7:48 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 27876-done


> With an autoincremented index, I suppose we might want to make sure that
> ‘db-add-build’ does not add a new entry for a build that’s already in
> the table.  WDYT?

Yes we might, but looking for a build with the same
derivation-evaluation-outputs before each build insertion will be an
expensive operation (now that this tuple is no longer the primary key).

Mathieu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-09  7:48         ` Mathieu Othacehe
@ 2017-09-10 13:01           ` Ludovic Courtès
  2017-09-10 13:26             ` Mathieu Othacehe
  0 siblings, 1 reply; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-10 13:01 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876-done

Heya Mathieu,

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

>> With an autoincremented index, I suppose we might want to make sure that
>> ‘db-add-build’ does not add a new entry for a build that’s already in
>> the table.  WDYT?
>
> Yes we might, but looking for a build with the same
> derivation-evaluation-outputs before each build insertion will be an
> expensive operation (now that this tuple is no longer the primary key).

OK, but isn’t there a risk of recording the same set of derivations at
every evaluation?

Basically, between two subsequent evaluations, 99% of the derivations
are exactly the same (assuming an evaluation is triggered at each git
push, and each git push adds/modifies just a handful of packages).  If
we record new builds for these 99%, even though nothing has changed,
then that’s potentially bad, no?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-10 13:01           ` Ludovic Courtès
@ 2017-09-10 13:26             ` Mathieu Othacehe
  2017-09-10 20:38               ` Ludovic Courtès
  0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Othacehe @ 2017-09-10 13:26 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 27876-done


Hi Ludo,

> Basically, between two subsequent evaluations, 99% of the derivations
> are exactly the same (assuming an evaluation is triggered at each git
> push, and each git push adds/modifies just a handful of packages).  If
> we record new builds for these 99%, even though nothing has changed,
> then that’s potentially bad, no?

Hmm, you're right but the situation is already problematic.

On each evaluation, N new entries will appear in Derivations table
(because the primary key is on derivation,evaluation tuple).

N new entries will also appear in Builds table (both with primary key on
id or on derivation,evaluation,output tuple).

When build start/stop will be detected, only a small part of N
(derivations which were rebuilt), will be added to Builds. Checking for
pre-existing builds with the same derivation will become useless unless
I'm wrong.

So there's still the problem of Derivations table growing from N at each
commit. I'm not sure what to do about it. Maybe removing the
"evaluation" field, and puting primary key on "derivation" only would be
better ?

Thanks,

Mathieu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration.
  2017-09-10 13:26             ` Mathieu Othacehe
@ 2017-09-10 20:38               ` Ludovic Courtès
  0 siblings, 0 replies; 16+ messages in thread
From: Ludovic Courtès @ 2017-09-10 20:38 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 27876-done

Howdy,

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

>> Basically, between two subsequent evaluations, 99% of the derivations
>> are exactly the same (assuming an evaluation is triggered at each git
>> push, and each git push adds/modifies just a handful of packages).  If
>> we record new builds for these 99%, even though nothing has changed,
>> then that’s potentially bad, no?
>
> Hmm, you're right but the situation is already problematic.
>
> On each evaluation, N new entries will appear in Derivations table
> (because the primary key is on derivation,evaluation tuple).
>
> N new entries will also appear in Builds table (both with primary key on
> id or on derivation,evaluation,output tuple).
>
> When build start/stop will be detected, only a small part of N
> (derivations which were rebuilt), will be added to Builds. Checking for
> pre-existing builds with the same derivation will become useless unless
> I'm wrong.
>
> So there's still the problem of Derivations table growing from N at each
> commit. I'm not sure what to do about it. Maybe removing the
> "evaluation" field, and puting primary key on "derivation" only would be
> better ?

You’re right, I don’t know off the top of my head.  Perhaps we should
check the schemas that Hydra uses, it should be similar.

Future work!

Ludo’.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-09-10 20:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-30 10:07 [bug#27876] [PATCH] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
2017-07-31 14:57 ` Ludovic Courtès
2017-08-01 19:48   ` Mathieu Othacehe
2017-08-02  9:22     ` Ludovic Courtès
2017-08-01 19:51 ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Mathieu Othacehe
2017-08-01 19:51   ` [bug#27876] [PATCH v2 2/3] cuirass: add Hydra compatible HTTP API Mathieu Othacehe
2017-09-08 16:00     ` Ludovic Courtès
2017-08-01 19:51   ` [bug#27876] [PATCH v2 3/3] cuirass: Add tests for new " Mathieu Othacehe
2017-09-08 16:01     ` Ludovic Courtès
2017-09-08 15:59   ` [bug#27876] [PATCH v2 1/3] cuirass: Store new information in database to prepare new HTTP API integration Ludovic Courtès
2017-09-08 19:13     ` bug#27876: " Mathieu Othacehe
2017-09-08 20:44       ` [bug#27876] " Ludovic Courtès
2017-09-09  7:48         ` Mathieu Othacehe
2017-09-10 13:01           ` Ludovic Courtès
2017-09-10 13:26             ` Mathieu Othacehe
2017-09-10 20:38               ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.