Skip to content

Commit 00626ce

Browse files
authored
Merge pull request #341 from Swirrl/lk/issue_340
Add task to build and publish docker images
2 parents 939ad0c + 1b66d69 commit 00626ce

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

.circleci/config.yml

+18
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ jobs:
124124
"${CIRCLE_TAG}" \
125125
csv2rdf-darwin.tar.gz
126126
127+
deploy-docker:
128+
docker:
129+
- image: cimg/clojure:1.11.1
130+
auth:
131+
username: $DOCKERHUB_USERNAME
132+
password: $DOCKERHUB_PASSWORD
133+
steps:
134+
- checkout
135+
- run:
136+
name: "Deploy csv2rdf docker to public image repository"
137+
command: clojure -T:build docker :image-type :registry :to :remote
138+
127139
# Invoke jobs via workflows
128140
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
129141
workflows:
@@ -164,3 +176,9 @@ workflows:
164176
only: /.*/
165177
branches:
166178
ignore: /.*/
179+
- deploy-docker:
180+
context:
181+
- gcp-artifact-registry
182+
- swirrl-dockerhub-consumer
183+
requires:
184+
- test

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ need to be provided when processing from a metadata file since the metadata shou
4747

4848
java -jar csv2rdf-standalone.jar -u /path/to/metadata/file.json -o output.ttl
4949

50+
### Running with docker
51+
52+
Docker images are published to the public repository `europe-west2-docker.pkg.dev/swirrl-devops-infrastructure-1/public/csv2rdf`.
53+
These can be run by specifying the image version to run, and mapping volumes into the container to make local files available within
54+
the container e.g.
55+
56+
docker run --rm -v .:/data europe-west2-docker.pkg.dev/swirrl-devops-infrastructure-1/public/csv2rdf:v0.7 -t /data/input.csv -o /data/output.ttl
57+
58+
Note that file paths should be specified relative to the container, not the local system.
59+
5060
## Using as a library
5161

5262
csv2rdf also exposes its functionality as a library - please see [the csv2rdf library](doc/library.md) for a description of the library and its interface.

build.clj

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns build
22
(:require [clojure.tools.build.api :as b]
33
[org.corfield.build :as bb]
4-
[clojure.string :as str])
4+
[clojure.string :as str]
5+
[juxt.pack.api :as pack])
6+
(:import [com.google.cloud.tools.jib.api JibContainer])
57
(:refer-clojure :exclude [test]))
68

79
(def lib 'swirrl/csv2rdf)
@@ -63,3 +65,43 @@
6365
:class-dir class-dir
6466
:uber-file "target/csv2rdf-app.jar"
6567
})))
68+
69+
;; A tag name must be valid ASCII and may contain lowercase and uppercase
70+
;; letters, digits, underscores, periods and dashes
71+
;; https://docs.docker.com/engine/reference/commandline/tag/#extended-description
72+
(defn tag [s]
73+
(when s (str/replace s #"[^a-zA-Z0-9_.-]" "_")))
74+
75+
(def repo "europe-west2-docker.pkg.dev/swirrl-devops-infrastructure-1/public")
76+
77+
(defn docker [opts]
78+
(let [tags (->> ["rev-parse HEAD"
79+
"describe --tags --always"
80+
"branch --show-current"]
81+
(map #(tag (b/git-process {:git-args %})))
82+
(remove nil?))
83+
image-type (get opts :image-type :docker)
84+
build-args {:basis (b/create-basis {:project "deps.edn" :aliases [:docker]})
85+
;; If we don't include a tag in the :image-name, then pack implicitly
86+
;; tags the image with latest, even when we specify additional tags. So
87+
;; choose a tag arbitrarily to be part of the :image-name, and then
88+
;; provide the rest in :tags.
89+
:image-name (str repo "/csv2rdf:" (first tags))
90+
:tags (set (rest tags))
91+
:image-type image-type
92+
:base-image "eclipse-temurin:17" ;; An openJDK 17 base docker provided by https://github.com/adoptium/containers#containers
93+
}
94+
publish-args {:platforms #{:linux/amd64 :linux/arm64}
95+
96+
;; NOTE Not as documented!
97+
;; The docstring states that these should be
98+
;; :to-registry {:username ... :password ...}
99+
;; but alas, that is a lie.
100+
;; https://github.com/juxt/pack.alpha/issues/101
101+
:to-registry-username "_json_key"
102+
:to-registry-password (System/getenv "GCLOUD_SERVICE_KEY")}
103+
args (if (= :remote (:to opts))
104+
(merge build-args publish-args)
105+
build-args)
106+
^JibContainer container (pack/docker args)]
107+
(println (.. container (getDigest) (getHash)))))

deps.edn

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@
3030
:extra-paths ["test" "test/resources"]
3131
:main-opts ["-m" "kaocha.runner"]}
3232

33-
:build {:deps {io.github.seancorfield/build-clj
34-
{:git/tag "v0.6.3" :git/sha "9b8e09b"}}
33+
:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.6.3" :git/sha "9b8e09b"}
34+
io.github.juxt/pack.alpha {:git/sha "802b3d6347376db51093d122eb4b8cf8a7bbd7cf"}
35+
com.google.cloud.tools/jib-core {:mvn/version "0.23.0"}}
36+
3537
:ns-default build}
3638

39+
:docker {:jvm-opts ["-Xmx4g"
40+
"-Dcom.sun.management.jmxremote.ssl=false"
41+
"-Dcom.sun.management.jmxremote.authenticate=false"
42+
"-Dcom.sun.management.jmxremote.port=3007"]
43+
:main-opts ["-m" "csv2rdf.main"]}
44+
3745
:gen-test-suite {:extra-deps {org.clojure/data.csv {:mvn/version "1.0.1"}}
3846
:extra-paths ["test" "test/resources"]
3947
:exec-fn csv2rdf.w3c-csvw-suite-test.gen/write-tests-file}}}

0 commit comments

Comments
 (0)