Skip to content

Commit

Permalink
Add Electric template (#1)
Browse files Browse the repository at this point in the history
* [dev] POC custom template with options

* %

* [electric] Add electric template

* generate html page

---------

Co-authored-by: iain <[email protected]>
  • Loading branch information
gmsvalente and soulflyer authored May 11, 2023
1 parent 732bfab commit df1715c
Show file tree
Hide file tree
Showing 928 changed files with 283,065 additions and 12 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# flexiana/xiana-deps
# flexiana/xiana-deps-template

FIXME: my new template.
New Xiana template using deps-new

## Usage

FIXME: write usage documentation!

This is a template project for use with [deps-new](https://github.com/seancorfield/deps-new).
As originally generated, it will produce a new library project when run:

$ clojure -Sdeps '{:deps {net.clojars.flexiana/xiana-deps {:local/root "."}}}' -Tnew create :template flexiana/xiana-deps :name myusername/mycoollib

Assuming you have installed `deps-new` as your `new` "tool" via:

```bash
clojure -Ttools install io.github.seancorfield/deps-new '{:git/tag "v0.5.1"}' :as new
```

As originally generated, it will produce a new library project when run:

$ clojure -Sdeps '{:deps {flexiana/xiana-deps-template {:git/url "https://github.com/Flexiana/xiana-deps-template" :git/sha "732bfab7203388aa5ca84207a38e9278b4ad03df"}}}' -Tnew create :template flexiana/xiana-deps-template :name myusername/mycoollib


> Note: once the template has been published (to a public git repo), the invocation will be the same, except the `:local/root` dependency will be replaced by a git or Maven-like coordinate.
Run this template project's tests (by default, this just validates your template's `template.edn`
Expand All @@ -26,7 +25,7 @@ file -- that it is valid EDN and it satisfies the `deps-new` Spec for template f

## License

Copyright © 2023 Apollo
Copyright © 2023 Flexiana

_EPLv1.0 is just the default for projects generated by `deps-new`: you are not_
_required to open source this project, nor are you required to use EPLv1.0!_
Expand Down
14 changes: 14 additions & 0 deletions resources/flexiana/electric/build/main.tmpl
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))))))
22 changes: 22 additions & 0 deletions resources/flexiana/electric/build/user.tmpl
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))
13 changes: 13 additions & 0 deletions resources/flexiana/electric/resources/index.tmpl
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>
26 changes: 26 additions & 0 deletions resources/flexiana/electric/root/Dockerfile
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
34 changes: 34 additions & 0 deletions resources/flexiana/electric/root/README.md
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
29 changes: 29 additions & 0 deletions resources/flexiana/electric/root/deps.edn
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"]}}}
36 changes: 36 additions & 0 deletions resources/flexiana/electric/root/fly.toml
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"
Binary file not shown.
13 changes: 13 additions & 0 deletions resources/flexiana/electric/root/resources/public/index.html
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.

Loading

0 comments on commit df1715c

Please sign in to comment.