From d4adfcf041144b17f121f181828f28739fe4b147 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Thu, 20 Sep 2018 11:37:01 +0200 Subject: [PATCH] initial commit --- .gitignore | 9 ++++++++ README.md | 24 +++++++++++++++++++++ project.clj | 14 +++++++++++++ resources/logback.xml | 13 ++++++++++++ src/wanijo_pipeline/core.clj | 31 ++++++++++++++++++++++++++++ src/wanijo_pipeline/pipeline.clj | 14 +++++++++++++ src/wanijo_pipeline/steps.clj | 23 +++++++++++++++++++++ src/wanijo_pipeline/ui_selection.clj | 30 +++++++++++++++++++++++++++ 8 files changed, 158 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 project.clj create mode 100644 resources/logback.xml create mode 100644 src/wanijo_pipeline/core.clj create mode 100644 src/wanijo_pipeline/pipeline.clj create mode 100644 src/wanijo_pipeline/steps.clj create mode 100644 src/wanijo_pipeline/ui_selection.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e04714b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3cdd7e --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# wanijo-pipeline + +A continuous delivery pipeline for FIXME + +## Usage + +* `lein run` will start your pipeline with a web-ui listening on port 8080 + +## Files + +* `/` + * `project.clj` contains dependencies and build configuration for Leiningen + +* `/src/wanijo_pipeline/` + * `pipeline.clj` contains your pipeline-definition + * `steps.clj` contains your custom build-steps + * `core.clj` contains the `main` function that wires everything together + +* `/resources/` + * `logback.xml` contains a sample log configuration + +## References + +* for a more detailed example, look at the [example pipeline](https://github.com/flosell/lambdacd/tree/master/src/todopipeline) in the main LambdaCD project diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..fc1ec3a --- /dev/null +++ b/project.clj @@ -0,0 +1,14 @@ +(defproject wanijo-pipeline "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :dependencies [[lambdacd "0.14.0"] + [lambdacd-git "0.4.1"] + [lambdaui "1.1.0"] + [http-kit "2.3.0"] + [org.clojure/clojure "1.9.0"] + [org.clojure/tools.logging "0.3.1"] + [org.slf4j/slf4j-api "1.7.5"] + [ch.qos.logback/logback-core "1.0.13"] + [ch.qos.logback/logback-classic "1.0.13"]] + :profiles {:uberjar {:aot :all}} + :main wanijo-pipeline.core) diff --git a/resources/logback.xml b/resources/logback.xml new file mode 100644 index 0000000..1f8b8de --- /dev/null +++ b/resources/logback.xml @@ -0,0 +1,13 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + diff --git a/src/wanijo_pipeline/core.clj b/src/wanijo_pipeline/core.clj new file mode 100644 index 0000000..acd75a4 --- /dev/null +++ b/src/wanijo_pipeline/core.clj @@ -0,0 +1,31 @@ +(ns wanijo-pipeline.core + (:require + [wanijo-pipeline.pipeline :as pipeline] + [wanijo-pipeline.ui-selection :as ui-selection] + [org.httpkit.server :as http-kit] + [lambdacd.runners :as runners] + [lambdacd.core :as lambdacd] + [clojure.tools.logging :as log]) + (:import (java.nio.file.attribute FileAttribute) + (java.nio.file Files LinkOption)) + (:gen-class)) + +(defn- create-temp-dir [] + (str (Files/createTempDirectory "lambdacd" (into-array FileAttribute [])))) + +(defn -main [& args] + (let [;; the home dir is where LambdaCD saves all data. + ;; point this to a particular directory to keep builds around after restarting + home-dir (create-temp-dir) + config {:home-dir home-dir + :name "wanijo pipeline"} + ;; initialize and wire everything together + pipeline (lambdacd/assemble-pipeline pipeline/pipeline-def config) + ;; create a Ring handler for the UI + app (ui-selection/ui-routes pipeline)] + (log/info "LambdaCD Home Directory is " home-dir) + ;; this starts the pipeline and runs one build after the other. + ;; there are other runners and you can define your own as well. + (runners/start-one-run-after-another pipeline) + ;; start the webserver to serve the UI + (http-kit/run-server app {:port 30500}))) diff --git a/src/wanijo_pipeline/pipeline.clj b/src/wanijo_pipeline/pipeline.clj new file mode 100644 index 0000000..7fa6ce9 --- /dev/null +++ b/src/wanijo_pipeline/pipeline.clj @@ -0,0 +1,14 @@ +(ns wanijo-pipeline.pipeline + (:use [lambdacd.steps.control-flow] + [wanijo-pipeline.steps]) + (:require + [lambdacd.steps.manualtrigger :as manualtrigger])) + +(def pipeline-def + `((either + manualtrigger/wait-for-manual-trigger + wait-for-repo) + (with-workspace + clone + compile + test))) diff --git a/src/wanijo_pipeline/steps.clj b/src/wanijo_pipeline/steps.clj new file mode 100644 index 0000000..5a0510e --- /dev/null +++ b/src/wanijo_pipeline/steps.clj @@ -0,0 +1,23 @@ +(ns wanijo-pipeline.steps + (:require [lambdacd.steps.shell :as lcd-shell] + [lambdacd-git.core :as lcd-git])) + +(def repo-uri "https://gitea.heevyis.ninja/josha/wanijo.git") +(def repo-branch "master") + +(defn wait-for-repo [args ctx] + (lcd-git/wait-for-git ctx + repo-uri + :ref (str "refs/heads/" repo-branch))) + +(defn clone [args ctx] + (let [revision (:revision args) + cwd (:cwd args) + ref (or revision repo-branch)] + (lcd-git/clone ctx repo-uri ref cwd))) + +(defn compile [args ctx] + (lcd-shell/bash ctx (:cwd args) "lein compile")) + +(defn test [args ctx] + (lcd-shell/bash ctx (:cwd args) "lein test")) diff --git a/src/wanijo_pipeline/ui_selection.clj b/src/wanijo_pipeline/ui_selection.clj new file mode 100644 index 0000000..2745d54 --- /dev/null +++ b/src/wanijo_pipeline/ui_selection.clj @@ -0,0 +1,30 @@ +(ns wanijo-pipeline.ui-selection + (:require + [hiccup.core :as h] + [lambdaui.core :as lambdaui] + [lambdacd.ui.core :as reference-ui] + [compojure.core :refer [routes GET context]]) + (:gen-class)) + +(defn- ui-selection [] + (h/html + [:html + [:head + [:title "LambdaCD - UI Selection"]] + [:body + [:h1 "LambdaCD - UI Selection"] + [:p "Two different UIs for LambdaCD exist: The reference-ui shipped with the core of LambdaCD and " + [:a {:href "https://github.com/sroidl/lambda-ui"} "LambdaUI"] + ", a community developed, opinionated alternative with a more user friendly interface"] + [:ul + [:li [:a {:href "./lambdaui/lambdaui/index.html"} "LambdaUI"]] + [:li [:a {:href "./reference/"} "Reference UI"]]]]])) + +(defn ui-routes [pipeline] + (let [lambdaui-app (lambdaui/ui-for pipeline :contextPath "/lambdaui") + referenceui-app (reference-ui/ui-for pipeline)] + (routes + (GET "/" [] (ui-selection)) + (context "/lambdaui" [] lambdaui-app) + (context "/reference" [] referenceui-app)))) +