Skip to content

Commit 9d5662a

Browse files
committed
initial commit
0 parents  commit 9d5662a

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### BOOT #######################################################################
2+
3+
/.boot/
4+
5+
### LEININGEN ##################################################################
6+
7+
.lein-*
8+
9+
### MAVEN (include pom.xml in /base) ###########################################
10+
11+
*.jar
12+
*.war
13+
pom.xml
14+
pom.xml.asc
15+
16+
### NREPL ######################################################################
17+
18+
.repl-*
19+
.nrepl-*
20+
21+
### JAVA #######################################################################
22+
23+
/hs_err_pid*.log
24+
25+
### OSX ########################################################################
26+
27+
.DS_Store
28+
29+
### EMACS ######################################################################
30+
31+
[#]*[#]
32+
33+
### VIM ########################################################################
34+
35+
*.swn
36+
*.swo
37+
*.swp

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# boot-stack
2+
3+
a boot task for deploying aws cloud formation templates
4+
5+
[](dependency)
6+
```clojure
7+
[tailrecursion/boot-stack "0.1.0-SNAPSHOT"] ;; latest release
8+
```
9+
[](/dependency)
10+
11+
## overview
12+
13+
the `create` task provisions a new cloudfront stack from a template described
14+
by clojure data structures, instead of json and yaml, so it may be conveniently
15+
manipulated by a boot build.
16+
17+
conversely, the `delete` task tears it down.

boot.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOOT_CLOJURE_VERSION=1.9.0
2+
BOOT_VERSION=2.7.2

build.boot

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(set-env!
2+
:resource-paths #{"src"}
3+
:dependencies '[[org.clojure/clojure "1.8.0" :scope "provided"]
4+
[adzerk/bootlaces "0.1.13" :scope "test"]])
5+
6+
(require
7+
'[adzerk.bootlaces :refer :all])
8+
9+
(def +version+ "0.1.0-SNAPSHOT")
10+
11+
(bootlaces! +version+)
12+
13+
(deftask develop []
14+
(comp (watch) (speak) (build-jar)))
15+
16+
(deftask deploy []
17+
(comp (speak) (build-jar) (push-release)))
18+
19+
(task-options!
20+
pom {:project 'tailrecursion/boot-stack
21+
:version +version+
22+
:description "Boot tasks for standing up and tearing down aws resources."
23+
:url "https://github.com/tailrecursion/boot-stack"
24+
:scm {:url "https://github.com/tailrecursion/boot-stack"}
25+
:license {"EPL" "http://www.eclipse.org/legal/epl-v10.html"}})

src/tailrecursion/boot_stack.clj

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(ns tailrecursion.boot-stack
2+
{:boot/export-tasks true}
3+
(:require
4+
[boot.core :as boot]
5+
[boot.pod :as pod]
6+
[boot.util :as util]))
7+
8+
(def ^:private deps
9+
'[[cheshire "5.8.1"]
10+
[com.amazonaws/aws-java-sdk-cloudformation "1.11.419"]])
11+
12+
(defn- warn-deps [deps]
13+
(let [conflict (delay (util/warn "Overriding project dependencies, using:\n"))]
14+
(doseq [dep deps]
15+
(when (pod/dependency-loaded? dep)
16+
@conflict
17+
(util/warn "• %s\n" (pr-str dep))))))
18+
19+
(defn- pod-env [deps]
20+
(let [dep-syms (->> deps (map first) set)]
21+
(warn-deps deps)
22+
(-> (dissoc pod/env :source-paths)
23+
(update :dependencies #(remove (comp dep-syms first) %))
24+
(update :dependencies into deps))))
25+
26+
(boot/deftask create
27+
[n stack NAME str "Name of the stack"
28+
r region REGION str "AWS Region"
29+
a access-key ACCESS_KEY str "AWS Access Key"
30+
s secret-key SECRET_KEY str "AWS Secret Key"
31+
t template TMPL edn "AWS CloudFormation template."]
32+
(let [pod (pod/make-pod (pod-env deps))]
33+
(boot/with-pre-wrap fileset
34+
(util/info "Creating stack %s in region %s...\n" stack region)
35+
(pod/with-call-in pod
36+
(tailrecursion.boot-stack.client/create-stack! ~*opts*))
37+
fileset)))
38+
39+
(boot/deftask delete
40+
[n stack NAME str "Name of the stack"
41+
r region REGION str "AWS Region"
42+
a access-key ACCESS_KEY str "AWS Access Key"
43+
s secret-key SECRET_KEY str "AWS Secret Key"]
44+
(let [pod (pod/make-pod (pod-env deps))]
45+
(boot/with-pre-wrap fileset
46+
(util/info "Deleting stack %s in region %s...\n" stack region)
47+
(pod/with-call-in pod
48+
(tailrecursion.boot-stack.client/delete-stack! ~*opts*))
49+
fileset)))
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(ns tailrecursion.boot-stack.client
2+
(:require
3+
[cheshire.core :refer [generate-string]])
4+
(:import
5+
[com.amazonaws.auth AWSStaticCredentialsProvider BasicAWSCredentials]
6+
[com.amazonaws.services.cloudformation AmazonCloudFormationClientBuilder]
7+
[com.amazonaws.services.cloudformation.model CreateStackRequest DeleteStackRequest]))
8+
9+
(defn client [acc-key sec-key region]
10+
(let [creds (AWSStaticCredentialsProvider. (BasicAWSCredentials. acc-key sec-key))]
11+
(-> (AmazonCloudFormationClientBuilder/standard)
12+
(.withCredentials creds)
13+
(.withRegion region)
14+
(.build)
15+
(delay))))
16+
17+
(defn creation [stack template]
18+
(-> (CreateStackRequest.)
19+
(.withStackName stack)
20+
(.withTemplateBody (generate-string template))))
21+
22+
(defn deletion [stack]
23+
(-> (DeleteStackRequest.)
24+
(.withStackName stack)))
25+
26+
(defn create-stack! [{:keys [access-key secret-key region stack template]}]
27+
(let [client @(client access-key secret-key region)
28+
creation (creation stack template)]
29+
(.toString (.createStack client creation))))
30+
31+
(defn delete-stack! [{:keys [access-key secret-key region stack]}]
32+
(let [client @(client access-key secret-key region)
33+
deletion (deletion stack)]
34+
(.toString (.deleteStack client deletion))))

0 commit comments

Comments
 (0)