Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.nrepl-port
/.cpcache
/classes
/target
/.clj-kondo
/heroku.yml
/app.json

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.nrepl-port
/.cpcache
/classes
/target
/.clj-kondo/.cache
18 changes: 18 additions & 0 deletions Dockerfile.heroku
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM clojure:tools-deps as builder

RUN mkdir /tmp/ecomspark

WORKDIR /tmp/ecomspark

copy deps.edn Makefile ./
COPY src ./src
COPY resources ./resources

RUN make uberjar


FROM adoptopenjdk/openjdk11 as runner

COPY --from=builder /tmp/ecomspark/target/ecomspark.jar ./

ENTRYPOINT ["java","-jar","./ecomspark.jar"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
.PHONY: run ancient clean uberjar
run:
clj -M:cider

ancient:
clj -M:cider:ancient

clean:
rm -rf target classes .cpcache

uberjar: target/ecomspark.jar

define CLASS_BUILDER
(binding [clojure.core/*compiler-options*
{:direct-linking true
:elide-meta [:doc :file :line :added]}]
(compile (symbol "ecomspark.main")))
endef
export CLASS_BUILDER

classes: ./src/ecomspark deps.edn
mkdir -p classes
clj -M -e "$$CLASS_BUILDER"

target/ecomspark.jar: classes ./src/ecomspark deps.edn
clojure -M:uberjar --main-class ecomspark.main
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is an example of a working app with [TwinSpark](https://kasta-ua.github.io/
This is a simple eCommerce site: product list with endless scroll, where you can
add a product to cart and so on.

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is pretty neat. Heroku server reads a request origin to figure out what app should be deployed.


## Variants

- [Python+Flask](https://github.com/vsolovyov/ecomspark-flask/)
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "TwinSpark demo",
"description": "This is an example of a working app with TwinSpark",
"repository": "https://github.com/piranha/ecomspark",
"keywords": ["web", "framework", "frontendless", "ancient technology"]
}
7 changes: 5 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src" "resources"]
{:paths ["src" "resources" "classes"]
:deps
{org.clojure/clojure {:mvn/version "1.10.3"}
org.slf4j/slf4j-api {:mvn/version "1.7.30"}
Expand All @@ -20,4 +20,7 @@
"--middleware" "[cider.nrepl/cider-middleware,refactor-nrepl.middleware/wrap-refactor]"]}

:ancient {:extra-deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}
:main-opts ["-m" "antq.core"]}}}
:main-opts ["-m" "antq.core"]}
:uberjar {:replace-deps {uberdeps/uberdeps {:mvn/version "1.0.4"}}
:main-opts ["-m" "uberdeps.uberjar"]
:exec-args {:aot true}}}}
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile.heroku
11 changes: 8 additions & 3 deletions src/ecomspark/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
[ecomspark.app :as app]))


(def default-port 5454)

(mount/defstate httpd
:start (do
(println "Starting HTTPd on :5454...")
(httpd/run-server app/app {:port 5454}))
:start (let [port (or (some->> "PORT" System/getenv Integer/parseInt)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heroku sets PORT variable.

default-port)]
(printf "Starting HTTPd on :%s...\n" port)
(flush)
(httpd/run-server app/app {:port port})
(println "Done!"))
:stop (httpd))


Expand Down