-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* [dev] POC custom template with options * % * [electric] Add electric template * generate html page --------- Co-authored-by: iain <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(ns {{top/file}}.{{main/file}} | ||
(:require [hyperfiddle.electric :as e] | ||
[hyperfiddle.electric-dom2 :as dom])) | ||
|
||
(e/defn TwoClocks [] | ||
(e/client | ||
(dom/h1 (dom/text "Two Clocks — Electric Clojure TEMPLATE")) | ||
|
||
(let [c (e/client e/system-time-ms) | ||
s (e/server e/system-time-ms)] | ||
|
||
(dom/div (dom/text "client time: " c)) | ||
(dom/div (dom/text "server time: " s)) | ||
(dom/div (dom/text "latency: " (- s c)))))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns ^:dev/always user ; Electric currently needs to rebuild everything when any file changes. Will fix | ||
(:require | ||
{{top/file}}.{{main/file}} | ||
hyperfiddle.electric | ||
hyperfiddle.electric-dom2)) | ||
|
||
(def electric-main | ||
(hyperfiddle.electric/boot ; Electric macroexpansion - Clojure to signals compiler | ||
(binding [hyperfiddle.electric-dom2/node js/document.body] | ||
({{top/file}}.{{main/file}}/TwoClocks.)))) | ||
|
||
(defonce reactor nil) | ||
|
||
(defn ^:dev/after-load ^:export start! [] | ||
(assert (nil? reactor) "reactor already running") | ||
(set! reactor (electric-main | ||
#(js/console.log "Reactor success:" %) | ||
#(js/console.error "Reactor failure:" %)))) | ||
|
||
(defn ^:dev/before-load stop! [] | ||
(when reactor (reactor)) ; teardown | ||
(set! reactor nil)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico"> | ||
<title>{{main/file}}</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<script type="text/javascript" src="$:hyperfiddle.client.module/main$"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM clojure:openjdk-11-tools-deps AS clojure-deps | ||
WORKDIR /app | ||
COPY deps.edn deps.edn | ||
COPY src-build src-build | ||
RUN clojure -A:dev -M -e :ok # preload deps | ||
RUN clojure -T:build noop # preload build deps | ||
|
||
FROM clojure:openjdk-11-tools-deps AS build | ||
WORKDIR /app | ||
COPY --from=clojure-deps /root/.m2 /root/.m2 | ||
COPY shadow-cljs.edn shadow-cljs.edn | ||
COPY deps.edn deps.edn | ||
COPY src src | ||
COPY src-build src-build | ||
COPY resources resources | ||
ARG REBUILD=unknown | ||
ARG VERSION | ||
RUN clojure -X:build uberjar :jar-name "app.jar" :verbose true :version '"'$VERSION'"' | ||
|
||
FROM amazoncorretto:11 AS app | ||
WORKDIR /app | ||
COPY --from=build /app/app.jar app.jar | ||
EXPOSE 8080 | ||
ARG VERSION | ||
ENV VERSION=$VERSION | ||
CMD java -DHYPERFIDDLE_ELECTRIC_VERSION=$VERSION -jar app.jar |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# electric-starter-app | ||
|
||
``` | ||
$ clj -A:dev -X user/main | ||
Starting Electric compiler and server... | ||
shadow-cljs - server version: 2.20.1 running at http://localhost:9630 | ||
shadow-cljs - nREPL server started on port 9001 | ||
[:app] Configuring build. | ||
[:app] Compiling ... | ||
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 1.93s) | ||
👉 App server available at http://0.0.0.0:8080 | ||
``` | ||
|
||
# Deployment | ||
|
||
ClojureScript optimized build, Dockerfile, Uberjar, Github actions CD to fly.io | ||
|
||
``` | ||
clojure -X:build build-client # optimized release build | ||
clojure -X:build uberjar # contains demos and demo server, currently | ||
HYPERFIDDLE_ELECTRIC_APP_VERSION=`git describe --tags --long --always --dirty` | ||
docker build --build-arg VERSION='"'$HYPERFIDDLE_ELECTRIC_APP_VERSION'"' -t electric-starter-app . | ||
docker run --rm -p 7070:8080 electric-starter-app | ||
# flyctl launch ... ? create fly app, generate fly.toml, see dashboard | ||
# https://fly.io/apps/electric-starter-app | ||
NO_COLOR=1 flyctl deploy --build-arg VERSION='$HYPERFIDDLE_ELECTRIC_APP_VERSION' | ||
# https://electric-starter-app.fly.dev/ | ||
``` | ||
|
||
- `NO_COLOR=1` disables docker-cli fancy shell GUI, so that we see the full log (not paginated) in case of exception | ||
- `--build-only` tests the build on fly.io without deploying |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{:paths ["src" "resources"] | ||
:deps {com.hyperfiddle/electric {:mvn/version "v2-alpha-263-g89da9d11"} | ||
com.hyperfiddle/rcf {:mvn/version "20220926-202227"} | ||
info.sunng/ring-jetty9-adapter | ||
{:mvn/version "0.14.3" ; (Jetty 9) is Java 8 compatible; | ||
;:mvn/version "0.17.7" ; (Jetty 10) is NOT Java 8 compatible | ||
:exclusions [org.slf4j/slf4j-api info.sunng/ring-jetty9-adapter-http3]} ; no need | ||
org.clojure/clojure {:mvn/version "1.11.1"} | ||
org.clojure/clojurescript {:mvn/version "1.11.60"} | ||
org.clojure/tools.logging {:mvn/version "1.2.4"} | ||
ch.qos.logback/logback-classic {:mvn/version "1.2.11"} | ||
ring-basic-authentication/ring-basic-authentication {:mvn/version "1.1.1"}} | ||
:aliases {:dev | ||
{:extra-deps | ||
{binaryage/devtools {:mvn/version "1.0.6"} | ||
thheller/shadow-cljs {:mvn/version "2.20.1"}} | ||
:jvm-opts | ||
["-Xss2m" ; https://github.com/hyperfiddle/photon/issues/11 | ||
"-XX:-OmitStackTraceInFastThrow" ;; RCF | ||
] | ||
:exec-fn user/main | ||
:exec-args {}} | ||
:build | ||
{:extra-paths ["src-build"] | ||
:ns-default build | ||
:extra-deps {io.github.clojure/tools.build {:git/tag "v0.8.2" :git/sha "ba1a2bf"} | ||
io.github.seancorfield/build-clj {:git/tag "v0.8.0" :git/sha "9bd8b8a"} | ||
thheller/shadow-cljs {:mvn/version "2.20.1"}} | ||
:jvm-opts ["-Xss2m"]}}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
app = "electric-starter-app" | ||
kill_signal = "SIGINT" | ||
kill_timeout = 5 | ||
processes = [] | ||
|
||
[env] | ||
|
||
[experimental] | ||
allowed_public_ports = [] | ||
auto_rollback = true | ||
|
||
[[services]] | ||
http_checks = [] | ||
internal_port = 8080 | ||
processes = ["app"] | ||
protocol = "tcp" | ||
script_checks = [] | ||
[services.concurrency] | ||
hard_limit = 200 | ||
soft_limit = 150 | ||
type = "connections" | ||
|
||
[[services.ports]] | ||
force_https = true | ||
handlers = ["http"] | ||
port = 80 | ||
|
||
[[services.ports]] | ||
handlers = ["tls", "http"] | ||
port = 443 | ||
|
||
[[services.tcp_checks]] | ||
grace_period = "1s" | ||
interval = "15s" | ||
restart_limit = 0 | ||
timeout = "2s" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico"> | ||
<title>Electric Starter App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<script type="text/javascript" src="$:hyperfiddle.client.module/main$"></script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.