diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..4e66129 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,74 @@ +version: 2.1 + +orbs: + tools: replikativ/clj-tools@0 + +jobs: + build: + executor: tools/clojurecli + steps: + - attach_workspace: + at: /home/circleci + - run: + name: Build + command: clojure -Sthreads 1 -T:build uber + no_output_timeout: 5m + - persist_to_workspace: + root: /home/circleci/ + paths: + - replikativ/target + deploy: + executor: tools/clojurecli + steps: + - attach_workspace: + at: /home/circleci + - run: + name: Deploy to Docker Hub + command: | + clojure -Sthreads 1 \ + -T:build deploy-image \ + :docker-login ${DOCKER_LOGIN} \ + :docker-password ${DOCKER_PASSWORD} \ + no_output_timeout: 5m + release: + executor: tools/clojurecli + steps: + - attach_workspace: + at: /home/circleci + - run: + name: Release + command: clojure -Sthreads 1 -T:build release + +workflows: + build-and-deploy: + jobs: + - tools/setup: + context: dockerhub-deploy + setup_cljs: false + - tools/format: + context: dockerhub-deploy + requires: + - tools/setup + - build: + context: dockerhub-deploy + requires: + - tools/setup + - deploy: + context: + - dockerhub-deploy + filters: + branches: + only: main + requires: + - tools/setup + - tools/format + - build + - release: + context: + - dockerhub-deploy + - github-token + filters: + branches: + only: main + requires: + - deploy diff --git a/.gitignore b/.gitignore index 54e2919..be3be3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .clj-kondo/ .cpcache/ +target/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d2a3e89 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM gcr.io/distroless/java17-debian11 + +COPY target/datahike-server-*-standalone.jar / + +EXPOSE 3000 + +CMD ["/datahike-server-standalone.jar"] diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..6a960de --- /dev/null +++ b/build.clj @@ -0,0 +1,109 @@ +(ns build + (:require + [borkdude.gh-release-artifact :as gh] + [clojure.tools.build.api :as b] + [deps-deploy.deps-deploy :as dd]) + (:import + [java.nio.file Paths] + [com.google.cloud.tools.jib.api Jib Containerizer RegistryImage TarImage] + [com.google.cloud.tools.jib.api.buildplan AbsoluteUnixPath Port])) + +(def lib 'io.replikativ/souffleuse) +(def version (format "0.1.%s" (b/git-count-revs nil))) +(def current-commit (gh/current-commit)) +(def class-dir "target/classes") +(def basis (b/create-basis {:project "deps.edn"})) +(def jar-path (format "target/%s-%s.jar" (name lib) version)) +(def uber-file (format "%s-%s-standalone.jar" (name lib) version)) +(def uber-path (format "target/%s" uber-file)) +(def image (format "docker.io/replikativ/souffleuse:%s" version)) + +(defn get-version + [_] + (println version)) + +(defn clean + [_] + (b/delete {:path "target"})) + +(defn jar + [_] + (b/write-pom {:class-dir class-dir + :src-pom "./template/pom.xml" + :lib lib + :version version + :basis basis + :src-dirs ["src"]}) + (b/copy-dir {:src-dirs ["src" "resources"] + :target-dir class-dir}) + (b/jar {:class-dir class-dir + :jar-file jar-path})) + +(defn uber + [_] + (clean nil) + (b/copy-dir {:src-dirs ["src" "resources"] + :target-dir class-dir}) + (b/compile-clj {:basis basis + :src-dirs ["src"] + :class-dir class-dir}) + (b/uber {:class-dir class-dir + :uber-file uber-path + :basis basis + :main 'souffleuse.core})) + +(defn deploy + "Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars." + [_] + (dd/deploy {:installer :remote :artifact jar-path + :pom-file (b/pom-path {:lib lib :class-dir class-dir})})) + +(defn release + [_] + (-> (gh/overwrite-asset {:org "replikativ" + :repo (name lib) + :tag version + :commit current-commit + :file uber-path + :content-type "application/java-archive"}) + :url + println)) + +(defn install + [_] + (clean nil) + (jar nil) + (b/install {:basis (b/create-basis {}) + :lib lib + :version version + :jar-file jar-path + :class-dir class-dir})) + +(defn deploy-image + [{:keys [docker-login docker-password]}] + (if-not (and docker-login docker-password) + (println "Docker credentials missing.") + (.containerize + (-> (Jib/from "gcr.io/distroless/java17-debian11") + (.addLayer [(Paths/get uber-path (into-array String[]))] (AbsoluteUnixPath/get "/")) + (.setProgramArguments [(format "/%s" uber-file)]) + (.addExposedPort (Port/tcp 3000))) + (Containerizer/to + (-> (RegistryImage/named image) + (.addCredential (str docker-login) (str docker-password)))))) + (println "Deployed new image to Docker Hub: " image)) + +(comment + (def docker-login "") + (def docker-password "") + + (b/pom-path {:lib lib :class-dir class-dir}) + (clean nil) + (compile nil) + (jar nil) + (uber nil) + (deploy-image {:docker-login docker-login + :docker-password docker-password}) + (deploy nil) + (release nil) + (install nil)) diff --git a/template/pom.xml b/template/pom.xml new file mode 100644 index 0000000..f673e00 --- /dev/null +++ b/template/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + io.replikativ + souffleuse + jar + souffleuse + A simple bot to announce releases and meetings to Slack and Twitter + https://datahike.io + + + Eclipse + http://www.eclipse.org/legal/epl-v10.html + + + + scm:git:git@github.com:replikativ/souffleuse.git + scm:git:git@github.com/replikativ/souffleuse.git + https://github.com/replikativ/souffleuse + +