Commit 835d92e9 authored by Bruno Burke's avatar Bruno Burke 🍔
Browse files

Initial commit

parents
Pipeline #2185 failed with stages
in 59 seconds
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
image: docker:latest
services:
- docker:dind
stages:
- build
- test
#- release
- deploy
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/lehrmeister/document-storage:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/lehrmeister/document-storage:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
build:
stage: build
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
test1:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run -rm $CONTAINER_TEST_IMAGE lein test
#release-image:
# stage: release
# script:
# - docker pull $CONTAINER_TEST_IMAGE
# - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
# - docker push $CONTAINER_RELEASE_IMAGE
# only:
# - master
deploy:
stage: deploy
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run -rm --dns=$DNS_SERVER -e ARTIFACTORY_USER=$ARTIFACTORY_USER -e ARTIFACTORY_PASS=$ARTIFACTORY_PW -e ARTIFACTORY_URL=$ARTIFACTORY_DEPLOY_REPOSITORY $CONTAINER_TEST_IMAGE sh deploy.sh
only:
- master
FROM clojure:lein-2.7.1-alpine
LABEL maintainer="burke@fh-muenster.de"
ENV LEIN_SNAPSHOTS_IN_RELEASE=TRUE
RUN lein clean
RUN lein uberjar
# document-storage
A Clojure library designed to ... well, that part is up to you.
## Usage
FIXME
## License
Copyright © 2018 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
echo "{:user {:deploy-repositories [[\"internal\" {:url \"${ARTIFACTORY_URL}\" :username :env/artifactory_user :password :env/artifactory_pass :sign-releases false}]]}}" > ~/.lein/profiles.clj
lein deploy internal
# Introduction to document-storage
TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)
(defproject document-storage "0.1.0"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/tools.logging "0.4.0"]
[clj-jgit "0.9.1-SNAPSHOT"]])
(ns document-storage.core
(:require [clj-jgit.porcelain :as jp]
[clojure.tools.logging :as log]
[clojure.data :refer [diff]]
[clojure.java.io :as io]
[clojure.edn :refer [read-string]]
[clojure.pprint :refer [pprint]]))
(def repo-dir (atom ""))
(def repositories (atom {}))
(def default-repository :default)
(def upstream-ssh-identity "upstream")
(def storage-directory (atom ""))
(defn init-repository [dir]
(when-not (jp/discover-repo dir)
(log/info dir " is not a Git-Repository")
(log/info "Initialize Git-Repository in " dir)
(jp/git-init dir))
(jp/load-repo (jp/discover-repo dir)))
(defn load-config [dir]
(-> dir
(str "/config.edn")
slurp
read-string))
(defn init-storage [dir]
(log/info "Init Storage in " dir)
(reset! storage-directory dir)
(if-let [config (load-config dir)]
(doseq [repo (keys (:repositories config))]
(swap! repositories
assoc repo
(merge {:directory (str dir "/" (name repo))
:unsaved-files []
:git-repo (init-repository (str dir "/" (name repo)))}
(get (:repositories config) repo))))
(log/error "Unable to initialize Document Storage - no config!")))
(defn get-file-path [id repository]
(let [repo-directory (get-in @repositories [repository :directory])
file-path (str repo-directory "/" id)]
file-path))
(defn valid-id? [id repository]
(let [file-path (get-file-path id repository)]
(.exists (io/as-file file-path))))
(defn get-repo-data [id]
(if-let [repo (get-in @repositories [id])]
repo
(log/error "invalid repository " id)
))
(defn- get-repo
([]
(get-repo default-repository))
([id]
(:git-repo (get-repo-data id))))
(defn- commit-document-change [message repository]
(jp/git-commit (get-repo repository) message {:name "Document-Manager" :email "burke@fh-muenster.de"}))
(defn save-document [id document & {:keys [repository] :or {repository default-repository}}]
(let [file-path (get-file-path id repository)
document (with-out-str (pprint document))]
(when-not (and (valid-id? id repository) (= (slurp file-path) document))
(spit file-path document)
(jp/git-add (get-repo repository) id)
(commit-document-change (str "saved new version of " id) repository))))
(defn delete-document [id & {:keys [repository] :or {repository default-repository}}]
(when (valid-id? id repository)
(io/delete-file (get-file-path id :units) true)
(jp/git-rm (get-repo repository) id)
(commit-document-change (str "deleted document " id) repository)))
(defn load-document [id & {:keys [repository] :or {repository default-repository}}]
(when (valid-id? id repository)
(read-string (slurp (get-file-path id repository)))))
(defn get-upstreams [repo-name]
(-> (get-repo-data repo-name)
:upstreams))
(defn init-upstreams [repo-name]
(let [git (get-repo repo-name)
upstreams (get-upstreams :default)]
(doseq [[id {:keys [url]}] upstreams]
(jp/git-remote-remove git (name id))
(jp/git-remote-add git (name id) url)
)
)
)
(defn push-upstreams [repo-name]
(let [git (get-repo repo-name)
upstreams (jp/git-remote-list git)]
(jp/with-identity {:name (str @storage-directory "/" upstream-ssh-identity) :exclusive true}
(doseq [[id urls] upstreams]
(jp/git-push git :remote id)
))
)
)
(defn shutdown []
(pmap (fn [[id repo]]
(push-upstreams id)
) @repositories))
(ns document-storage.core-test
(:require [clojure.test :refer :all]
[document-storage.core :refer :all]))
(deftest a-test
(testing "I pass."
(is (= 1 1))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment