summaryrefslogtreecommitdiff
path: root/guix/vkraus/packages/disfluid-load-image.scm
blob: 90a6ff30b0dc7691f88bbda60acdfe6b353d6a90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; disfluid, implementation of the Solid specification
;; Copyright (C) 2020, 2021  Vivien Kraus

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.

;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(define-module (vkraus packages disfluid-load-image)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages docker))

(define builder
  '(let ((out (assoc-ref %outputs "out"))
         (bash-in (assoc-ref %build-inputs "bash"))
         (coreutils-in (assoc-ref %build-inputs "coreutils"))
         (grep-in (assoc-ref %build-inputs "grep"))
         (docker-in (assoc-ref %build-inputs "docker-cli")))
     (mkdir out)
     (mkdir (string-append out "/bin"))
     (call-with-output-file (string-append out "/bin/disfluid-load-image")
       (lambda (port)
         (format port "#!~a/bin/bash
if ! VERSION=$(guix show disfluid | ~a/bin/grep '^version:' | ~a/bin/cut -d ' ' -f 2)
then
    >&2 echo \"Failed to get disfluid version.\"
    exit 1
fi

if ! TARBALL=$(guix pack -c 16 -f docker -Sbin=/bin gnutls nss-certs disfluid)
then
    >&2 echo \"Failed to put disfluid in a pack.\"
    exit 1
fi

if ! IMAGE=$(sudo ~a/bin/docker load -i $TARBALL | ~a/bin/tail -n 1 | ~a/bin/cut -b 15-)
then
    >&2 echo \"Failed to load the image.\"
    exit 1
fi

sudo ~a/bin/docker tag $IMAGE vivienkraus/disfluid:$VERSION \
  || (>&2 echo \"Failed to tag the image.\" ; exit 1)

sudo ~a/bin/docker tag vivienkraus/disfluid:$VERSION vivienkraus/disfluid:latest \
  || (>&2 echo \"Failed to tag the image.\" ; exit 1)

echo vivienkraus/disfluid:$VERSION
"
                 bash-in
                 grep-in coreutils-in
                 docker-in coreutils-in coreutils-in
                 docker-in
                 docker-in)))
     (chmod (string-append out "/bin/disfluid-load-image") #o755)
     #t))

(define-public disfluid-load-image
  (package
   (name "disfluid-load-image")
   (version "0.0.0")
   (source (plain-file "empty" ""))
   (build-system trivial-build-system)
   (arguments `(#:builder ,builder))
   (inputs `(("bash" ,bash)
             ("coreutils" ,coreutils)
             ("grep" ,grep)
             ("docker-cli" ,docker-cli)))
   (synopsis "Generate a docker image for disfluid")
   (description "Some people like to have disfluid in a docker image, but the guix pack invocation is not trivial.")
   (home-page "https://labo.planete-kraus.eu/webid-oidc.git")
   (license license:gpl3+)))