This commit is contained in:
jem 2021-03-17 19:31:12 +01:00
parent 9fb9cb13f3
commit c91af154ec
9 changed files with 56 additions and 37 deletions

View file

@ -99,7 +99,6 @@ release:
rules: rules:
- if: '$CI_COMMIT_TAG != null' - if: '$CI_COMMIT_TAG != null'
variables: variables:
CI_COMMIT_TAG: "0.1.1"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic" PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic"
UBERJAR_URL: "${PACKAGE_REGISTRY_URL}/k8s-mastodon-bot-standalone/${$CI_COMMIT_TAG}/k8s-mastodon-bot-standalone.jar" UBERJAR_URL: "${PACKAGE_REGISTRY_URL}/k8s-mastodon-bot-standalone/${$CI_COMMIT_TAG}/k8s-mastodon-bot-standalone.jar"
FRONTEND_URL: "${PACKAGE_REGISTRY_URL}/k8s-mastodon-bot/${$CI_COMMIT_TAG}/k8s-mastodon-bot.js" FRONTEND_URL: "${PACKAGE_REGISTRY_URL}/k8s-mastodon-bot/${$CI_COMMIT_TAG}/k8s-mastodon-bot.js"

View file

@ -2,7 +2,7 @@
"name": "k8s-mastodon-bot", "name": "k8s-mastodon-bot",
"description": "Generate k8s yaml for a mastodon-bot deployment.", "description": "Generate k8s yaml for a mastodon-bot deployment.",
"author": "meissa GmbH", "author": "meissa GmbH",
"version": "0.1.2", "version": "0.1.3-SNAPSHOT",
"homepage": "https://gitlab.com/domaindrivenarchitecture/k8s-mastodon-bot#readme", "homepage": "https://gitlab.com/domaindrivenarchitecture/k8s-mastodon-bot#readme",
"repository": "https://www.npmjs.com/package/k8s-mastodon-bot", "repository": "https://www.npmjs.com/package/k8s-mastodon-bot",
"license": "APACHE2", "license": "APACHE2",

View file

@ -1,4 +1,4 @@
(defproject dda/k8s-mastodon-bot "0.1.2" (defproject dda/k8s-mastodon-bot "0.1.3-SNAPSHOT"
:description "common utils for dda config" :description "common utils for dda config"
:url "https://www.domaindrivenarchitecture.org" :url "https://www.domaindrivenarchitecture.org"
:license {:name "Apache License, Version 2.0" :license {:name "Apache License, Version 2.0"

View file

@ -22,23 +22,24 @@
:nitter-urls? false :nitter-urls? false
;; accounts you wish to mirror ;; accounts you wish to mirror
:accounts ["arstechnica" "WIRED"]} :accounts ["arstechnica" "WIRED"]}
:target {:target-type :mastodon :target {:target-type :mastodon
;; optional flag specifying wether the name of the account ;; optional flag specifying wether the name of the account
;; will be appended in the post, defaults to false ;; will be appended in the post, defaults to false
:append-screen-name? false :append-screen-name? false
;; optional visibility flag: direct, private, unlisted, public ;; optional visibility flag: direct, private, unlisted, public
;; defaults to public ;; defaults to public
:visibility "unlisted" :visibility "unlisted"
;; optional boolean to mark content as sensitive. Defaults to true. ;; optional boolean to mark content as sensitive. Defaults to true.
:sensitive? true :sensitive? true
;; optional boolean defaults to false ;; optional boolean defaults to false
;; only sources containing media will be posted when set to true ;; only sources containing media will be posted when set to true
:media-only? true :media-only? true
;; optional limit for the post length. Defaults to 300. ;; optional limit for the post length. Defaults to 300.
:max-post-length 300 :max-post-length 300
;; optional signature for posts. Defaults to "not present". ;; optional signature for posts. Defaults to "not present".
:signature "#newsbot"} :signature "#newsbot"}
}]} }]
:auth {}}}
</textarea><br><br> </textarea><br><br>
<label for="auth" class="form-label">Your auth.edn:</label> <label for="auth" class="form-label">Your auth.edn:</label>

View file

@ -3,12 +3,9 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as cs] [clojure.string :as cs]
[expound.alpha :as expound]
[clojure.java.io :as io] [clojure.java.io :as io]
[dda.k8s-mastodon-bot.core :as core])) [dda.k8s-mastodon-bot.core :as core]))
(alter-var-root #'s/*explain-out* (constantly expound/printer))
(def usage (def usage
"usage: "usage:

View file

@ -1,10 +1,18 @@
(ns dda.k8s-mastodon-bot.core (ns dda.k8s-mastodon-bot.core
(:require (:require
[clojure.string :as cs] [clojure.string :as cs]
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]]) :cljs [orchestra.core :refer-macros [defn-spec]])
[mastodon-bot.core-domain :as cd] [expound.alpha :as expound]
[dda.k8s-mastodon-bot.yaml :as yaml])) [mastodon-bot.core-domain :as cd]
[dda.k8s-mastodon-bot.yaml :as yaml]))
#?(:clj (alter-var-root #'s/*explain-out* (constantly expound/printer))
:cljs (set! s/*explain-out* expound/printer))
(s/def ::config cd/config?)
(defn generate-config [my-config my-auth] (defn generate-config [my-config my-auth]
(-> (->
@ -18,11 +26,11 @@
(yaml/from-string (yaml/load-resource "deployment.yaml")))) (yaml/from-string (yaml/load-resource "deployment.yaml"))))
(defn-spec generate any? (defn-spec generate any?
[my-config cd/config? [my-config ::config
my-auth cd/auth?] my-auth cd/auth?]
(cs/join "\n" (cs/join "\n"
[(yaml/to-string (generate-config my-config my-auth)) [(yaml/to-string (generate-config my-config my-auth))
"---" "---"
(yaml/to-string (generate-deployment))])) (yaml/to-string (generate-deployment))]))
(st/instrument 'dda.k8s-mastodon-bot.core)

View file

@ -1,12 +1,8 @@
(ns dda.k8s-mastodon-bot.browser (ns dda.k8s-mastodon-bot.browser
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]
[expound.alpha :as expound]
[dda.k8s-mastodon-bot.core :as core])) [dda.k8s-mastodon-bot.core :as core]))
(set! s/*explain-out* expound/printer)
(defn config-from-document [] (defn config-from-document []
(-> js/document (-> js/document
(.getElementById "config") (.getElementById "config")
@ -17,7 +13,7 @@
(.getElementById "auth") (.getElementById "auth")
(.-value))) (.-value)))
(defn render-to-document (defn render-output-to-document
[input] [input]
(-> js/document (-> js/document
(.getElementById "output") (.getElementById "output")
@ -29,7 +25,11 @@
(.getElementById "generate-button") (.getElementById "generate-button")
(.addEventListener "click" (.addEventListener "click"
#(-> (core/generate (config-from-document) (auth-from-document)) #(-> (core/generate (config-from-document) (auth-from-document))
(render-to-document))))) (render-output-to-document)
(print "1"))))
(-> js/document
(st/instrument 'dda.k8s-mastodon-bot.core) (.getElementById "config")
(.addEventListener "blur"
#(-> (s/explain ::core/config (config-from-document))
(print))))
)

View file

@ -0,0 +1,13 @@
(ns dda.k8s-mastodon-bot.core-test
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.k8s-mastodon-bot.core :as cut]))
(deftest should-generate-yaml
(is (= {:apiVersion "v1", :kind "ConfigMap"
:metadata {:name "mastodon-bot",
:labels {:app.kubernetes.io/name "k8s-mastodon-bot"}},
:data {:config.edn "some-config-value\n",
:credentials.edn "some-credentials-value\n"}}
(cut/from-string (cut/load-resource "config.yaml")))))

View file

@ -1,6 +1,7 @@
(ns dda.k8s-mastodon-bot.yaml-test (ns dda.k8s-mastodon-bot.yaml-test
(:require (:require
[clojure.test :refer [deftest is testing are]] #?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.k8s-mastodon-bot.yaml :as cut])) [dda.k8s-mastodon-bot.yaml :as cut]))
(deftest should-parse-yaml-string (deftest should-parse-yaml-string