diff --git a/.gitignore b/.gitignore index 0f15b09..715b1ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +backend/.cpcache/ +backend/.nrepl-port +backend/chicken-master.jar + +frontend/.cpcache/ /frontend/out/ /frontend/resources/public/js /frontend/resources/public/css diff --git a/README.md b/README.md index 4f9be7b..7526142 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,7 @@ See the READMEs in the `backend` and `frontend` folders. * daily view * infinite scroll -* Move to different day - * handle regular customers ** every n days ** copy over to next week ** cancel regular order - -* settings menu - -* products CRM diff --git a/backend/README.md b/backend/README.md index 9d0b327..beada27 100644 --- a/backend/README.md +++ b/backend/README.md @@ -20,4 +20,4 @@ The API for the chickens service. ## Deployment clojure -X:depstar uberjar - java -jar chickens.jar -Dconfig=config/dev/config.edn + java -Dconfig=config/dev/config.edn -jar chickens.jar diff --git a/backend/deps.edn b/backend/deps.edn index 149e371..d8d7e54 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -1,13 +1,13 @@ {:paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.10.1"} - ns-tracker {:mvn/version "0.4.0"} - compojure {:mvn/version "1.6.2"} + ns-tracker/ns-tracker {:mvn/version "0.4.0"} + compojure/compojure {:mvn/version "1.6.2"} yogthos/config {:mvn/version "1.1.7"} seancorfield/next.jdbc {:mvn/version "1.1.613"} org.postgresql/postgresql {:mvn/version "42.2.6"} - ring-basic-authentication {:mvn/version "1.1.0"} - ring-cors {:mvn/version "0.1.13"} - ring {:mvn/version "1.8.1"}} + ring-basic-authentication/ring-basic-authentication {:mvn/version "1.1.0"} + ring-cors/ring-cors {:mvn/version "0.1.13"} + ring/ring {:mvn/version "1.8.1"}} :aliases {:dev {:jvm-opts ["-Dconfig=config/dev/config.edn"] @@ -20,4 +20,4 @@ :depstar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.193"}} :ns-default hf.depstar - :exec-args {:aot true :jar "chickens.jar" :main-class chicken-master.server}}}} + :exec-args {:aot true :jar "chicken-master.jar" :main-class chicken-master.server}}}} diff --git a/backend/src/chicken_master/handler.clj b/backend/src/chicken_master/handler.clj index 5e30aaa..2e2b5cf 100644 --- a/backend/src/chicken_master/handler.clj +++ b/backend/src/chicken_master/handler.clj @@ -3,7 +3,7 @@ [chicken-master.api :as endpoints] [clojure.edn :as edn] [config.core :refer [env]] - [compojure.core :refer [GET defroutes routes]] + [compojure.core :refer [GET defroutes routes context]] [compojure.route :refer [resources not-found]] [compojure.handler :refer [api]] [ring.util.response :refer [resource-response]] @@ -39,11 +39,12 @@ (not-found "not found")) (def handler (routes - (-> endpoints/all-routes - (wrap-basic-authentication authenticated?) - (wrap-cors :access-control-allow-origin (map re-pattern (env :allow-origin)) - :access-control-allow-methods [:get :put :post :delete :options]) - api - wrap-edn-request - wrap-edn-response) + (context "/api" [] + (-> endpoints/all-routes + (wrap-basic-authentication authenticated?) + (wrap-cors :access-control-allow-origin (map re-pattern (env :allow-origin)) + :access-control-allow-methods [:get :put :post :delete :options]) + api + wrap-edn-request + wrap-edn-response)) base-routes)) diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..0b7d9c6 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,14 @@ +cd backend +clojure -X:depstar uberjar + +cd ../frontend +npx shadow-cljs release frontend +clojure -A:garden -m chicken-master.css + +cd .. +scp backend/chicken-master.jar chickens:/srv/chickens/chicken-master.jar +ssh chickens 'mkdir -p /srv/chickens/frontend/js' +ssh chickens 'mkdir -p /srv/chickens/frontend/css' +rsync -r frontend/resources/public/index.html chickens:/srv/chickens/frontend/index.html +rsync -r frontend/resources/public/css/screen.css chickens:/srv/chickens/frontend/css/screen.css +rsync -r frontend/resources/public/js/app.js chickens:/srv/chickens/frontend/js/app.js diff --git a/frontend/resources/public/css/screen.css b/frontend/resources/public/css/screen.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/chicken_master/config.cljs b/frontend/src/chicken_master/config.cljs index af137e1..2bd1397 100644 --- a/frontend/src/chicken_master/config.cljs +++ b/frontend/src/chicken_master/config.cljs @@ -33,7 +33,7 @@ :editable-number-inputs (get-setting :editable-number-inputs false) ; only allow number modifications in the edit modal :hide-fulfilled-orders (get-setting :hide-fulfilled-orders false) - :backend-url (get-setting :backend-url (.. js/window -location -href)) ; "http://localhost:3000/" + :backend-url (get-setting :backend-url (str (.. js/window -location -href) "api/")) ; "http://localhost:3000/" }) diff --git a/infra/chickens.service b/infra/chickens.service index 361c7ce..8b583cd 100644 --- a/infra/chickens.service +++ b/infra/chickens.service @@ -3,7 +3,7 @@ Description=Chicken master After=postgresql.service [Service] -ExecStart=/usr/bin/java -Dconfig="/home/dan/chicken-master/config.edn" -jar /home/dan/chicken-master/target/chicken-master.jar +ExecStart=/usr/bin/java -Dconfig="/srv/chickens/config.edn" -jar /srv/chickens/chicken-master.jar Type=simple Restart=always RestartSec=1 diff --git a/infra/db/pg_backup.sh b/infra/db/pg_backup.sh new file mode 100755 index 0000000..0b1f7dd --- /dev/null +++ b/infra/db/pg_backup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +DB_URI="postgresql://localhost/chickens?user=chicken_user&password=" + +BACKUP_DIR=/srv/chickens/backups/ +BACKUP_FILE=$BACKUP_DIR"`date +\%Y-\%m-\%d`.sql" + +pg_dump -Fp "$DB_URI" | gzip > $BACKUP_FILE.gz