Skip to content

Commit 8a3f189

Browse files
committed
Synchronize electric-fiddle with electric-starter-app
2 parents 1838cdb + 814dadf commit 8a3f189

208 files changed

Lines changed: 25593 additions & 259 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clj-kondo/config.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
hyperfiddle.electric.impl.array-fields/deffields clojure.core/declare}
77
:linters {:redundant-expression {:level :off}
88
:var-same-name-except-case {:level :off}
9-
:clojure-lsp/unused-public-var {:level :off}}}
9+
:clojure-lsp/unused-public-var {:level :off}}}

.dockerignore

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
resources/public/electric_starter_app/js
2-
target/
3-
.cpcache
4-
.shadow-cljs
1+
**/.clj-kondo
2+
**/.cpcache
3+
**/.DS_Store
4+
**/.env
5+
**/.idea
6+
**/.lsp
7+
**/.nrepl-port
8+
**/*.~undo-tree~
9+
**/*.iml
10+
**/report.html
11+
**/yarn-error.log
12+
fly.toml
13+
yarn.lock
14+
15+
# ignore target artifacts – docker owns the prod build
16+
**/.shadow-cljs
17+
**/node_modules
18+
**/output.calva-repl
19+
**/resources/public/*.min.css
20+
**/resources/public/js
21+
**/target
22+
**/tsconfig.tsbuildinfo
23+
# **/src/**/*.js -- we commit precompiled js files (Failure.js, Pending.js), as well as .class
24+
**/datagrid/state
25+
**/datomic_browser/state

.github/workflows/deploy.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: hyperfiddle/electric-fiddle
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
jobs:
8+
deploy:
9+
name: "Fly deploy, domain: hello-fiddle"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
submodules: recursive # includes HFQL
16+
ssh-key: ${{ secrets.HYPERFIDDLE_ORG_DEPLOY_KEY }}
17+
- uses: superfly/flyctl-actions/setup-flyctl@master
18+
- run: NO_COLOR=1 flyctl deploy --remote-only --config src/hello-fiddle/fly.toml --build-arg hfql_ssh_prv_key="$HFQL_SSH_PRV_KEY"
19+
env:
20+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
21+
#DATOMIC_DEV_LOCAL_USER: ${{ secrets.DATOMIC_DEV_LOCAL_USER }}
22+
23+
# docker_build:
24+
# needs: [jvm, browser]
25+
# if: success()
26+
# runs-on: ubuntu-latest
27+
# name: Build and push Docker image
28+
# steps:
29+
# - uses: actions/checkout@v3
30+
# with:
31+
# fetch-depth: 0
32+
# - name: Set Environment Variables
33+
# run: echo "HYPERFIDDLE_ELECTRIC_SERVER_VERSION=$(git describe --tags --long --always --dirty)" >> $GITHUB_ENV
34+
35+
# - name: Set up Docker Buildx
36+
# uses: docker/setup-buildx-action@v2
37+
38+
# - uses: superfly/flyctl-actions/setup-flyctl@master
39+
# - run: flyctl auth docker
40+
# env:
41+
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
42+
43+
# - name: Build and push
44+
# uses: docker/build-push-action@v4
45+
# with:
46+
# push: true
47+
# tags: registry.fly.io/electric-demo:latest
48+
# build-args: |
49+
# HYPERFIDDLE_ELECTRIC_SERVER_VERSION=${{ env.HYPERFIDDLE_ELECTRIC_SERVER_VERSION }}
50+
51+
# deploy:
52+
# needs: [docker_build]
53+
# if: success() && github.ref == 'refs/heads/master'
54+
# name: Deploy Docker image to Fly.io
55+
# runs-on: ubuntu-latest
56+
# steps:
57+
# - uses: actions/checkout@v3
58+
# - uses: superfly/flyctl-actions/setup-flyctl@master
59+
# - run: flyctl deploy --image registry.fly.io/electric-demo:latest
60+
# env:
61+
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,21 @@
99
.nrepl-port
1010
.shadow-cljs
1111
node_modules
12-
/resources/public/electric_starter_app/js
12+
#/report.html
13+
/resources/public/electric_fiddle/js
1314
/resources/electric-manifest.edn
1415
/target
16+
/yarn-error.log
1517
.DS_Store
18+
#src/**/*.js -- for tsc modules only, see https://github.com/hyperfiddle/photon/commit/0aa9b26c35d961151891c1e42ec13fcf52e38fa2
19+
# for xtdb-starter demo:
20+
data
21+
# ---
22+
/src/datomic_browser/state/
23+
/src/datagrid/state/
24+
/src-dev/electric-fiddle.edn
1625
/.dir-locals.el
26+
/resources/public/user/ui_demo.css
27+
28+
# libpython-clj
29+
/classes

.gitmodules

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[submodule "vendor/hfql"]
2+
path = vendor/hfql
3+
url = git@gitlab.com:hyperfiddle/hfql.git
4+
[submodule "vendor/electric"]
5+
path = vendor/electric
6+
url = git@gitlab.com:hyperfiddle/electric.git
7+
[submodule "vendor/rcf"]
8+
path = vendor/rcf
9+
url = git@gitlab.com:hyperfiddle/rcf.git
10+
[submodule "heroicons-electric"]
11+
path = vendor/heroicons-electric
12+
url = git@gitlab.com:hyperfiddle/heroicons-electric.git
13+
[submodule "vendor/hyperfiddle"]
14+
path = vendor/hyperfiddle
15+
url = git@gitlab.com:hyperfiddle/hyperfiddle.git
16+
[submodule "src-private"]
17+
path = src-private
18+
url = git@gitlab.com:hyperfiddle/scratch.git
19+
[submodule "vendor/electric3-starter-app"]
20+
path = vendor/electric3-starter-app
21+
url = git@gitlab.com:hyperfiddle/electric3-starter-app.git
22+
[submodule "vendor/electric-datomic-browser"]
23+
path = vendor/electric-datomic-browser
24+
url = git@gitlab.com:hyperfiddle/electric-datomic-browser.git
25+
[submodule "vendor/hyperfiddle-contrib"]
26+
path = vendor/hyperfiddle-contrib
27+
url = git@gitlab.com:hyperfiddle/hyperfiddle-contrib.git

Dockerfile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1+
FROM node:18-bookworm-slim AS node-deps
2+
WORKDIR /app
3+
COPY package.json package.json
4+
RUN npm install
5+
16
FROM clojure:temurin-17-tools-deps-1.12.0.1501 AS build
27
WORKDIR /app
8+
COPY --from=node-deps /app/node_modules /app/node_modules
9+
# install python for libpython-clj navigator demo
10+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3 python3-dev && rm -rf /var/lib/apt/lists/*
311
COPY deps.edn deps.edn
12+
13+
ARG HYPERFIDDLE_FIDDLE_DEPS_ALIAS
14+
ARG HYPERFIDDLE_FIDDLE_NS
415
ARG VERSION
16+
517
ENV VERSION=$VERSION
6-
RUN clojure -A:prod -M -e ::ok # preload – rebuilds if deps or commit version changes
7-
RUN clojure -A:build:prod -M -e ::ok # preload
18+
19+
RUN clojure -A:prod:$HYPERFIDDLE_FIDDLE_DEPS_ALIAS -M -e ::ok # preload
20+
RUN clojure -A:build:prod:$HYPERFIDDLE_FIDDLE_DEPS_ALIAS -M -e ::ok # preload
821

922
COPY shadow-cljs.edn shadow-cljs.edn
1023
COPY src src
11-
COPY src-prod src-prod
1224
COPY src-build src-build
25+
COPY src-prod src-prod
1326
COPY resources resources
1427

15-
RUN clojure -X:prod:build uberjar :version "\"$VERSION\"" :build/jar-name "app.jar"
28+
RUN clojure -X:build:prod:$HYPERFIDDLE_FIDDLE_DEPS_ALIAS uberjar \
29+
:build/fiddle-ns $HYPERFIDDLE_FIDDLE_NS \
30+
:build/fiddle-deps-alias $HYPERFIDDLE_FIDDLE_DEPS_ALIAS \
31+
:build/jar-name app.jar \
32+
:version "\"$VERSION\""
1633

1734
FROM amazoncorretto:17 AS app
1835
WORKDIR /app
36+
# install python for libpython-clj navigator demo
37+
RUN yum update -y && yum install -y python3 && yum clean all && rm -rf /var/cache/yum
1938
COPY --from=build /app/target/app.jar app.jar
2039

2140
EXPOSE 8080

LICENSE

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
MIT No Attribution
1+
MIT License
22

33
Copyright (c) 2024 Hyperfiddle
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,49 @@
1-
# Electric v3 Starter App
1+
# Hyperfiddle demos repo — Electric Fiddle
2+
3+
This is an **internal playground repo** where we host a lot of our demos, live examples, and little snippets and deploy them to prod. In its current form it's **not intended for public use**. We only leave it published so we can link to the source code of certain demos when we need to.
4+
5+
For a minimalist Electric starter repo, see https://gitlab.com/hyperfiddle/electric3-starter-app.
26

37
## Links
48

59
* Electric github with source code: https://github.com/hyperfiddle/electric
610
* Tutorial: https://electric.hyperfiddle.net/
711

8-
## Getting started - dev setup
12+
## Getting started dev setup
913

10-
* Shell: `clj -A:dev -X dev/-main`.
14+
* Shell: `clj -A:dev:private:electric-tutorial:dustingetz -X dev/-main`
1115
* Login instructions will be printed
12-
* REPL: `:dev` deps alias, `(dev/-main)` at the REPL to start dev build
16+
* REPL: `:dev:private:electric-tutorial:dustingetz` deps aliases, `(dev/-main)` at the REPL to start dev build
1317
* App will start on http://localhost:8080
14-
* Electric root function: [src/electric_starter_app/main.cljc](src/electric_starter_app/main.cljc)
1518
* Hot code reloading works: edit -> save -> see app reload in browser
1619

1720
> [!WARNING]
18-
> Electric dev environments must run **one single JVM** that is shared by both the Clojure REPL and shadow-cljs ClojureScript compilation process! Electric uses a custom hot code reloading strategy to ensure that the Electric frontend and backend processes (DAGs) stay in sync as you change one or the other. This starter repo achieves this by booting shadow from the dev entrypoint[src-dev/dev.cljc](src-dev/dev.cljc). I believe this is compatible with both Calva and Cursive's "happy path" shadow-cljs support. For other editors, watch out as your boot sequence may run shadow-cljs in a second process! You will experience undefined behavior.
21+
> Electric dev environments must run **one single JVM** that is shared by both the Clojure REPL and shadow-cljs ClojureScript compilation process! Electric uses a custom hot code reloading strategy to ensure that the Electric frontend and backend processes (DAGs) stay in sync as you change one or the other. This starter repo achieves this by booting shadow from the dev entrypoint [src-dev/dev.cljc](src-dev/dev.cljc). I believe this is compatible with both Calva and Cursive's "happy path" shadow-cljs support. For other editors, watch out as your boot sequence may run shadow-cljs in a second process! You will experience undefined behavior.
22+
23+
## "Fiddle" classpath infrastructure (optional)
24+
25+
This repo is structured to allow multiple "fiddles" (little apps) to share common dev infrastructure (e.g. routing, databases). During dev, these classpaths are merged, but prod classpaths are isolated so that each fiddle can deployed individually.
26+
27+
* **local dev**: the [dev entrypoint](src-dev/dev.cljc) uses a [clever reader trick](src-dev/load_dev_fiddles!.cljc) to drive Clojure/Script namespace `:require` directives dynamically from a config file, [`electric-fiddle.edn`](src-dev/electric-fiddle.example.edn). Clone the example file to override it locally, and remember to restart your REPL.
28+
29+
* **prod**: the [prod entrypoint](src-prod/prod.cljc) runs only one fiddle at a time, with an isolated classpath. Prod has a mandatory [build](src-build/build.clj), which bakes the Electric application client program. At compile time, both the Electric program hash (derived from git) and the fiddle entrypoint namespace are known statically, and built into both the client assets and also the server asset `resources/electric-manifest.edn` which is used to ensure that the client & server agree about the baked Electric program hash. At runtime, the prod entrypoint uses the reader trick to lookup the name of the entrypoint to run.
30+
31+
This is all done in a rather tiny amount of LOC, so we feel it is reasonable to expect you to understand it.
1932

2033
## Deployment
2134

2235
```shell
23-
# Prod build
24-
clj -X:build:prod build-client
25-
clj -M:prod -m prod
2636

27-
# Uberjar (optional)
28-
clj -X:build:prod uberjar :build/jar-name "app.jar"
37+
clj -X:build:prod:electric-tutorial build-client :build/fiddle-ns docs-site.sitemap
38+
clj -M:prod:electric-tutorial -m prod
39+
40+
# Uberjar
41+
clj -X:build:prod:electric-tutorial uberjar :build/fiddle-ns docs-site.sitemap :build/fiddle-deps-alias :electric-tutorial :build/jar-name '"app.jar"'
2942
java -cp target/app.jar clojure.main -m prod
3043

3144
# Docker
32-
docker build --build-arg VERSION=$(git rev-parse HEAD) -t electric3-starter-app:latest .
33-
docker run --rm -it -p 8080:8080 electric3-starter-app:latest
45+
docker build --build-arg HYPERFIDDLE_FIDDLE_NS=docs-site.sitemap --build-arg HYPERFIDDLE_FIDDLE_DEPS_ALIAS=electric-tutorial --build-arg VERSION=$(git rev-parse HEAD) -t electric-fiddle:latest .
46+
docker run --rm -it -p 8080:8080 electric-fiddle:latest
3447

3548
# Fly
3649
fly deploy --remote-only --build-arg VERSION=$(git rev-parse HEAD)

0 commit comments

Comments
 (0)