Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set up dokku deployment.
  • Loading branch information
codonnell committed Dec 26, 2020
1 parent 2cbd20b commit 5bb58ac
Show file tree
Hide file tree
Showing 44 changed files with 591 additions and 596 deletions.
3 changes: 2 additions & 1 deletion .dir-locals.el
Expand Up @@ -2,4 +2,5 @@
(column-enforce-column . 70)
(cider-default-cljs-repl . shadow)
(cider-shadow-default-options . ":dev")
(cider-shadow-cljs-global-options . "-A:dev:test"))))
(cider-shadow-cljs-global-options . "-A:dev:backend:frontend:test")
(cider-preferred-build-tool . shadow-cljs))))
8 changes: 8 additions & 0 deletions .dockerignore
@@ -0,0 +1,8 @@
resources/public/js
resources/public/css
node_modules
.cpcache
.shadow-cljs
.nrepl-port
.clj-kondo/.cache
target
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@ node_modules
.cpcache
.shadow-cljs
.nrepl-port
.clj-kondo/.cache
.clj-kondo/.cache
target
1 change: 1 addition & 0 deletions CHECKS
@@ -0,0 +1 @@
/ My Gift List Rocks
7 changes: 0 additions & 7 deletions Dockerfile.flyway

This file was deleted.

26 changes: 22 additions & 4 deletions Makefile
@@ -1,14 +1,32 @@
.PHONY: test test-up test-down
.PHONY: test test-up test-down migrate uberjar run build-report outdated

test:
POSTGRES_PORT=15433 docker-compose -p mygiftlist-blog-test up -d
scripts/migrate-local.sh mygiftlist-blog-test_default
clojure -A:dev:test:run-tests
clojure -X:migrate :database-url '"postgresql://postgres:password@localhost:15433/postgres"'
clojure -M:backend:dev:test:run-tests
docker-compose -p mygiftlist-blog-test down

test-up:
POSTGRES_PORT=15433 docker-compose -p mygiftlist-blog-test up -d
scripts/migrate-local.sh mygiftlist-blog-test_default
clojure -X:migrate :database-url '"postgresql://postgres:password@localhost:15433/postgres"'

test-down:
docker-compose -p mygiftlist-blog-test down

migrate:
clojure -X:migrate :database-url '"postgresql://postgres:password@localhost:15432/postgres"'

uberjar:
npm install
npx shadow-cljs release prod
npm run css-build
clojure -X:depstar uberjar :jar target/mygiftlistrocks.jar :aliases '[:backend]'

run:
java -cp target/mygiftlistrocks.jar clojure.main -m rocks.mygiftlist.main

build-report:
npx shadow-cljs run shadow.cljs.build-report prod report.html

outdated:
clojure -M:outdated -a backend,frontend,dev,test,depstar,migrate,outdated
2 changes: 2 additions & 0 deletions Procfile
@@ -0,0 +1,2 @@
web: java -cp target/mygiftlistrocks.jar clojure.main -m rocks.mygiftlist.main
release: clojure -X:migrate
38 changes: 36 additions & 2 deletions README.md
Expand Up @@ -28,15 +28,15 @@ docker-compose up -d
```
After starting the database, you'll need to run migrations, which you can do with
```bash
./scripts/migrate-local.sh
make migrate
```
There's also a convenience script available at `./scripts/psql` to open up a psql client connected to the database. There are resources to learn more about working with a database inside docker compose in the [documentation](https://docs.docker.com/compose/).

### Application

To run this application in development mode, start a shadow-cljs server with
```bash
npx shadow-cljs -A:dev:test -d nrepl:0.7.0 -d cider/piggieback:0.4.2 -d refactor-nrepl:2.5.0 -d cider/cider-nrepl:0.25.0-SNAPSHOT server
npx shadow-cljs -A:dev:backend:frontend:test -d nrepl:0.8.2 -d cider/piggieback:0.5.1 -d refactor-nrepl:2.5.0 -d cider/cider-nrepl:0.25.3 server
```

With this running, you can control compilation by accessing the shadow-cljs server at http://localhost:9630. In addition, this command will start up an nrepl server, which you should connect to with your preferred REPL. Alternatively, CIDER users can run `cider-jack-in-clj&cljs` and choose `shadow-cljs`.
Expand All @@ -59,3 +59,37 @@ With the test database up and running, you should be able to run tests. You can
```bash
make test-down
```

## Deployment

To create an uberjar `target/mygiftlistrocks.jar` that includes production frontend assets, run
```
make uberjar
```

You can then run this uberjar with
```
java -cp target/mygiftlistrocks.jar clojure.main -m rocks.mygiftlist.main
```

You can run database migrations with
```
clojure -X:migrate :database-url '"postgresql://me:password@mydbhost:port/dbname"'
```

You can deploy to dokku with
```
git push dokku master
```

## Maintenance

To find outdated dependencies, you can run
```
make outdated
```

To create a build report documenting how large frontend dependencies are in your bundle, run
```
make build-report
```
2 changes: 2 additions & 0 deletions bin/build
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
make uberjar
77 changes: 46 additions & 31 deletions deps.edn
@@ -1,37 +1,52 @@
{:paths ["src" "resources"]
:deps {com.fulcrologic/fulcro {:mvn/version "3.2.6"}
com.wsscode/pathom {:mvn/version "2.2.31"}
edn-query-language/eql {:mvn/version "0.0.9"}
com.taoensso/timbre {:mvn/version "4.10.0"}
com.cognitect/transit-clj {:mvn/version "1.0.324"}
ring/ring-core {:mvn/version "1.8.1"}
ring/ring-defaults {:mvn/version "0.3.2"}
bk/ring-gzip {:mvn/version "0.3.0"}
com.auth0/java-jwt {:mvn/version "3.10.3"}
com.auth0/jwks-rsa {:mvn/version "0.11.0"}
integrant {:mvn/version "0.8.0"}
seancorfield/next.jdbc {:mvn/version "1.0.424"}
honeysql {:mvn/version "0.9.10"}
nilenso/honeysql-postgres {:mvn/version "0.2.6"}
org.postgresql/postgresql {:mvn/version "42.2.12"}
hikari-cp {:mvn/version "2.12.0"}
aero {:mvn/version "1.1.6"}
http-kit {:mvn/version "2.4.0-alpha6"}}
:aliases {:dev {:extra-paths ["dev"]
:jvm-opts ["-Dtrace"]
:extra-deps {org.clojure/tools.namespace {:mvn/version "1.0.0"}
org.clojure/clojurescript {:mvn/version "1.10.764"}
com.fulcrologic/semantic-ui-wrapper {:mvn/version "1.0.1"}
org.clojure/core.async {:mvn/version "1.2.603"}
{:paths ["resources" "src/cljc"]
:deps {com.fulcrologic/fulcro {:mvn/version "3.4.10"
:exclusions [cljsjs/react
cljsjs/react-dom
cljsjs/react-dom-server
org.clojure/clojurescript]}
edn-query-language/eql {:mvn/version "1.0.1"}
com.taoensso/timbre {:mvn/version "5.1.0"}
org.clojure/core.async {:mvn/version "1.3.610"}}
:aliases {:backend {:extra-paths ["src/clj"]
:extra-deps {com.wsscode/pathom {:mvn/version "2.3.0"}
com.cognitect/transit-clj {:mvn/version "1.0.324"}
ring/ring-core {:mvn/version "1.8.2"}
http-kit/http-kit {:mvn/version "2.5.0"}
ring/ring-defaults {:mvn/version "0.3.2"}
bk/ring-gzip {:mvn/version "0.3.0"}
com.auth0/java-jwt {:mvn/version "3.12.0"}
com.auth0/jwks-rsa {:mvn/version "0.15.0"}
integrant/integrant {:mvn/version "0.8.0"}
seancorfield/next.jdbc {:mvn/version "1.1.613"}
honeysql/honeysql {:mvn/version "1.0.444"}
nilenso/honeysql-postgres {:mvn/version "0.2.6"}
org.postgresql/postgresql {:mvn/version "42.2.18"}
hikari-cp/hikari-cp {:mvn/version "2.13.0"}
aero/aero {:mvn/version "1.1.6"}}}
:frontend {:extra-paths ["src/cljs"]
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.773"}
com.fulcrologic/semantic-ui-wrapper {:mvn/version "2.0.1"}
com.cognitect/transit-cljs {:mvn/version "0.8.264"}
com.wsscode/async {:mvn/version "1.0.8"}
com.wsscode/async {:mvn/version "1.0.13"}
clj-commons/pushy {:mvn/version "0.3.10"}
thheller/shadow-cljs {:mvn/version "2.9.6"}
binaryage/devtools {:mvn/version "1.0.0"}
integrant/repl {:mvn/version "0.3.1"}}}
thheller/shadow-cljs {:mvn/version "2.11.10"}}}
:dev {:extra-paths ["dev"]
:jvm-opts ["-Dtrace"]
:extra-deps {binaryage/devtools {:mvn/version "1.0.2"}
integrant/repl {:mvn/version "0.3.2"}}}
:test {:extra-paths ["test"]
:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git"
:sha "f7ef16dc3b8332b0d77bc0274578ad5270fbfedd"}}}
:sha "b6b3193fcc42659d7e46ecd1884a228993441182"}}}
:run-tests {:main-opts ["-m" "cognitect.test-runner"]}
:outdated {:extra-deps {olical/depot {:mvn/version "1.8.4"}}
:migrate {:replace-paths ["migrate" "migrations"]
;; For some reason, depot doesn't detect
;; updated flyway versions. Update this
;; manually periodically.
:replace-deps {org.flywaydb/flyway-core {:mvn/version "7.3.2"}
org.postgresql/postgresql {:mvn/version "42.2.18"}}
:exec-fn rocks.mygiftlist.migrate/migrate}
:depstar {:extra-deps {seancorfield/depstar {:mvn/version "2.0.161"}}
:ns-default hf.depstar
:exec-args {}}
:outdated {:extra-deps {olical/depot {:mvn/version "2.0.1"}}
:main-opts ["-m" "depot.outdated.main"]}}}
2 changes: 1 addition & 1 deletion docker-compose.yaml
@@ -1,7 +1,7 @@
version: "3.7"
services:
postgres:
image: postgres:12.2
image: postgres:13.1
restart: always
environment:
POSTGRES_PASSWORD: password
Expand Down
23 changes: 23 additions & 0 deletions migrate/rocks/mygiftlist/migrate.clj
@@ -0,0 +1,23 @@
(ns rocks.mygiftlist.migrate
(:require [clojure.string :as str])
(:import [java.net URI]
[org.flywaydb.core Flyway]
[org.flywaydb.core.api Location]))

(defn database-url->datasource-args [database-url]
(let [{:keys [userInfo host port path]} (bean (URI. database-url))
[username password] (str/split userInfo #":")]
{:jdbc-url (str "jdbc:postgresql://" host ":" port path)
:username username
:password password}))

(defn migrate [{:keys [database-url]}]
(let [{:keys [jdbc-url username password]}
(database-url->datasource-args
(or database-url (System/getenv "DATABASE_URL")))]
(.. (Flyway/configure)
(dataSource jdbc-url username password)
(locations (into-array Location
[(Location. "filesystem:./migrations")]))
(load)
(migrate))))

0 comments on commit 5bb58ac

Please sign in to comment.