Skip to content

Commit 7abaa65

Browse files
committed
Initial commit
0 parents  commit 7abaa65

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.cpcache
2+
.nrepl-port

Diff for: Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM clojure:tools-deps
2+
RUN mkdir -p /usr/src/app
3+
WORKDIR /usr/src/app
4+
COPY deps.edn /usr/src/app/
5+
RUN clj -Sforce < /dev/null
6+
COPY . /usr/src/app
7+
CMD clj -m example.server

Diff for: app.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "heroku-clj-docker",
3+
"description": "Dockerized tools-deps Clojure app using heroku.yml",
4+
"repository": "https://git.heroku.com/heroku-clj-docker.git",
5+
"logo": "",
6+
"keywords": ["clojure", "docker", "toy"],
7+
"stack": "container"
8+
}

Diff for: deps.edn

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:deps
2+
{ring/ring-jetty-adapter {:mvn/version "1.7.0"}
3+
metosin/reitit {:mvn/version "0.2.5"}}}

Diff for: docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '2'
2+
services:
3+
web:
4+
build:
5+
context: .
6+
ports:
7+
- '3000:3000'

Diff for: heroku.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker:
3+
web: Dockerfile

Diff for: src/example/server.clj

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(ns example.server
2+
(:require [clojure.spec.alpha :as s]
3+
[muuntaja.core :as m]
4+
[reitit.coercion.spec]
5+
[reitit.ring :as ring]
6+
[reitit.ring.coercion :as coercion]
7+
[reitit.ring.middleware.muuntaja :as muuntaja]
8+
[ring.adapter.jetty :as jetty]
9+
[ring.middleware.params :as params]
10+
[spec-tools.spec :as spec]))
11+
12+
;; wrap into Spec Records to enable runtime conforming
13+
(s/def ::x spec/int?)
14+
(s/def ::y spec/int?)
15+
(s/def ::total spec/int?)
16+
17+
(s/def ::port (s/int-in 0 (inc 65535)))
18+
(s/def ::config (s/keys :req-un [::port]))
19+
20+
(def routes
21+
["/spec"
22+
{:coercion reitit.coercion.spec/coercion}
23+
["/plus"
24+
{:responses {200 {:body (s/keys :req-un [::total])}}
25+
:get
26+
{:summary "plus with query-params"
27+
:parameters {:query (s/keys :req-un [::x ::y])}
28+
:handler (fn [{{{:keys [x y]} :query} :parameters}]
29+
{:status 200
30+
:body {:total (+ x y)}})}
31+
:post
32+
{:summary "plus with body-params"
33+
:parameters {:body (s/keys :req-un [::x ::y])}
34+
:handler (fn [{{{:keys [x y]} :body} :parameters}]
35+
{:status 200
36+
:body {:total (+ x y)}})}}]])
37+
38+
(def app
39+
(ring/ring-handler
40+
(ring/router
41+
routes
42+
{:data
43+
{:muuntaja m/instance
44+
:middleware [params/wrap-params
45+
muuntaja/format-middleware
46+
coercion/coerce-exceptions-middleware
47+
coercion/coerce-request-middleware
48+
coercion/coerce-response-middleware]}})
49+
(ring/create-default-handler)))
50+
51+
(defn start [{:keys [port] :as config}]
52+
{:pre (s/valid? ::config config)}
53+
(let [server (jetty/run-jetty #'app {:port port, :join? false})]
54+
(println "server running in port" port)
55+
server))
56+
57+
(defn -main [& args]
58+
(let [port (or (System/getenv "PORT") 3000)]
59+
(start {:port port})))

0 commit comments

Comments
 (0)