Skip to content
This repository was archived by the owner on Nov 12, 2023. It is now read-only.

Commit 92f422a

Browse files
committed
ci: switch to jib for image building
1 parent 8fecc04 commit 92f422a

4 files changed

Lines changed: 66 additions & 32 deletions

File tree

.circleci/config.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ version: 2.1
22

33
orbs:
44
tools: replikativ/clj-tools@0
5-
docker: circleci/docker@2.0.1
65

76
jobs:
87
build:
@@ -12,31 +11,33 @@ jobs:
1211
at: /home/circleci
1312
- run:
1413
name: Build
15-
command: clojure -T:build uber
14+
command: clojure -Sthreads 1 -T:build uber
1615
no_output_timeout: 5m
1716
- persist_to_workspace:
1817
root: /home/circleci/
1918
paths:
2019
- replikativ/target
2120
deploy:
22-
executor: docker/docker
21+
executor: tools/clojurecli
2322
steps:
24-
- setup_remote_docker
2523
- attach_workspace:
2624
at: /home/circleci
27-
- docker/check
2825
- run:
29-
name: Build datahike-server container image
26+
name: Deploy to Docker Hub
3027
command: |
31-
cd /home/circleci/replikativ
32-
VERSION=$(git rev-list HEAD --count)
33-
docker build -t replikativ/datahike-server:${VERSION} .
28+
clojure -Sthreads 1 \
29+
-T:build deploy-image \
30+
:docker-login ${DOCKER_LOGIN} \
31+
:docker-password ${DOCKER_PASSWORD} \
32+
no_output_timeout: 5m
33+
release:
34+
executor: tools/clojurecli
35+
steps:
36+
- attach_workspace:
37+
at: /home/circleci
3438
- run:
35-
name: Deploy Snapshot to Docker Hub
36-
command: |
37-
cd /home/circleci/replikativ
38-
VERSION=$(git rev-list HEAD --count)
39-
docker push replikativ/datahike-server:${VERSION}
39+
name: Release
40+
command: clojure -Sthreads 1 -T:build release
4041

4142
workflows:
4243
build-test-and-deploy:
@@ -62,7 +63,6 @@ workflows:
6263
- tools/setup
6364
- deploy:
6465
context:
65-
- clojars-deploy
6666
- dockerhub-deploy
6767
filters:
6868
branches:
@@ -73,3 +73,12 @@ workflows:
7373
- tools/unittest
7474
- tools/integrationtest
7575
- build
76+
- release:
77+
context:
78+
- dockerhub-deploy
79+
- github-token
80+
filters:
81+
branches:
82+
only: main
83+
requires:
84+
- deploy

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gcr.io/distroless/java:17
1+
FROM gcr.io/distroless/java17-debian11
22

33
COPY target/datahike-server-*-standalone.jar /
44

build.clj

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22
(:require
33
[borkdude.gh-release-artifact :as gh]
44
[clojure.tools.build.api :as b]
5-
[deps-deploy.deps-deploy :as dd]))
5+
[deps-deploy.deps-deploy :as dd])
6+
(:import
7+
[java.nio.file Paths]
8+
[com.google.cloud.tools.jib.api Jib Containerizer RegistryImage TarImage]
9+
[com.google.cloud.tools.jib.api.buildplan AbsoluteUnixPath Port]))
610

711
(def lib 'io.replikativ/datahike-server)
812
(def version (format "0.1.%s" (b/git-count-revs nil)))
913
(def current-commit (gh/current-commit))
1014
(def class-dir "target/classes")
1115
(def basis (b/create-basis {:project "deps.edn"}))
12-
(def jar-file (format "target/%s-%s.jar" (name lib) version))
13-
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
16+
(def jar-path (format "target/%s-%s.jar" (name lib) version))
17+
(def uber-file (format "%s-%s-standalone.jar" (name lib) version))
18+
(def uber-path (format "target/%s" uber-file))
19+
(def image (format "docker.io/replikativ/datahike-server:%s" version))
20+
21+
(defn get-version
22+
[_]
23+
(println version))
1424

1525
(defn clean
1626
[_]
@@ -35,7 +45,7 @@
3545
(b/copy-dir {:src-dirs ["src" "resources"]
3646
:target-dir class-dir})
3747
(b/jar {:class-dir class-dir
38-
:jar-file jar-file}))
48+
:jar-file jar-path}))
3949

4050
(defn uber
4151
[_]
@@ -46,14 +56,14 @@
4656
:src-dirs ["src"]
4757
:class-dir class-dir})
4858
(b/uber {:class-dir class-dir
49-
:uber-file uber-file
59+
:uber-file uber-path
5060
:basis basis
5161
:main 'datahike-server.core}))
5262

5363
(defn deploy
5464
"Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars."
5565
[_]
56-
(dd/deploy {:installer :remote :artifact jar-file
66+
(dd/deploy {:installer :remote :artifact jar-path
5767
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
5868

5969
(defn release
@@ -62,7 +72,7 @@
6272
:repo (name lib)
6373
:tag version
6474
:commit current-commit
65-
:file jar-file
75+
:file uber-path
6676
:content-type "application/java-archive"})
6777
:url
6878
println))
@@ -74,19 +84,34 @@
7484
(b/install {:basis (b/create-basis {})
7585
:lib lib
7686
:version version
77-
:jar-file jar-file
87+
:jar-file jar-path
7888
:class-dir class-dir}))
7989

90+
(defn deploy-image
91+
[{:keys [docker-login docker-password]}]
92+
(if-not (and docker-login docker-password)
93+
(println "Docker credentials missing.")
94+
(.containerize
95+
(-> (Jib/from "gcr.io/distroless/java17-debian11")
96+
(.addLayer [(Paths/get uber-path (into-array String[]))] (AbsoluteUnixPath/get "/"))
97+
(.setProgramArguments [(format "/%s" uber-file)])
98+
(.addExposedPort (Port/tcp 3000)))
99+
(Containerizer/to
100+
(-> (RegistryImage/named image)
101+
(.addCredential (str docker-login) (str docker-password))))))
102+
(println "Deployed new image to Docker Hub: " image))
103+
80104
(comment
105+
(def docker-login "")
106+
(def docker-password "")
107+
81108
(b/pom-path {:lib lib :class-dir class-dir})
82109
(clean nil)
83110
(compile nil)
84111
(jar nil)
112+
(uber nil)
113+
(deploy-image {:docker-login docker-login
114+
:docker-password docker-password})
85115
(deploy nil)
86116
(release nil)
87-
(install nil)
88-
89-
(name lib)
90-
(namespace lib)
91-
(require '[babashka.fs :as fs])
92-
(fs/file-name (format "target/datahike-%s.jar" version)))
117+
(install nil))

deps.edn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
:sha "2f8898d84126a4e922c490f8614211a8b0cf67cd"}
3131
babashka/babashka.curl {:mvn/version "0.1.1"}
3232
babashka/fs {:mvn/version "0.1.2"}
33-
cheshire/cheshire {:mvn/version "5.10.1"}}
33+
cheshire/cheshire {:mvn/version "5.10.1"}
34+
com.google.cloud.tools/jib-core {:mvn/version "0.20.0"}}
3435
:ns-default build}}}
35-

0 commit comments

Comments
 (0)