From 3d01a76296d770806298d5698062770c22e66e3c Mon Sep 17 00:00:00 2001 From: James Long Date: Fri, 29 Apr 2022 10:35:13 -0400 Subject: [PATCH] Updates --- .dockerignore | 2 ++ .gitignore | 3 ++- Dockerfile | 3 +++ README.md | 26 +++++++++++++++++++++++-- fly.template.toml | 39 +++++++++++++++++++++++++++++++++++++ fly.toml | 6 +++++- load-config.js | 4 +++- sql/default-account.sqlite | Bin 0 -> 28672 bytes 8 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 fly.template.toml create mode 100644 sql/default-account.sqlite diff --git a/.dockerignore b/.dockerignore index 3c3629e..9e680f5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ node_modules +user-files +server-files diff --git a/.gitignore b/.gitignore index 46e1ad4..19faa0c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ log supervise bin/large-sync-data.txt user-files -server-files \ No newline at end of file +server-files +fly.toml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 065317a..844f6af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,8 @@ ENV NODE_ENV=production ADD . . RUN yarn install --production +RUN mkdir ./server-files +RUN mkdir ./user-files +RUN cp ./sql/default-account.sqlite ./server-files/account.sqlite CMD ["yarn", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 5981df4..733600c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ You should deploy your server so it's always running. We recommend [fly.io](http Next, [install the `flyctl`](https://fly.io/docs/flyctl/installing/) utility. Run `flyctl auth login` to sign into your account. -Open `fly.toml` and customize the app name on the first line of the file. +Copy `fly.template.toml` to `fly.toml`. Open `fly.toml` and customize the app name on the first line of the file. Now, run `flyctl launch` from `actual-server`. You should have a running app now! @@ -36,10 +36,32 @@ Whenever you want to update Actual, update the versions of `@actual-app/api` and **Note:** if you don't want to use fly, we still provide a `Dockerfile` to build the app so it should work anywhere that can compile a docker image. +### Persisting server data + +One problem with the above setup is every time you deploy, it will wipe away all the data on the server. You'll need to bootstrap the instance again and upload your files. + +Let's move the data somewhere that persists. With [fly.io](https://fly.io) we can create a [volume](https://fly.io/docs/reference/volumes/). Run this command: + +``` +flyctl volumes create actual_data +``` + +Now we need to tell Actual to use this volume. Add this in `fly.toml`: + +``` +[mounts] + source="actual_data" + destination="/data" +``` + +That's it! Actual will automatically check if the `/data` directory exists and use it automatically. + +_You can also configure the data dir with the `ACTUAL_USER_FILES` environment variable._ + ## Configuring the server URL The Actual app is totally separate from the server. In this project, they happen to both be served by the same server, but the app doesn't know where the server lives. The server could live on a completely different domain. You might setup Actual so that the app and server are running in completely separate places. -Since Actual doesn't know what server to use, the first thing it does is asks you for the server URL. If you are running this project, simply click "Use this domain" and it will automatically fill it in with the current domain. This works because we are serving the app and server in the same place. \ No newline at end of file +Since Actual doesn't know what server to use, the first thing it does is asks you for the server URL. If you are running this project, simply click "Use this domain" and it will automatically fill it in with the current domain. This works because we are serving the app and server in the same place. diff --git a/fly.template.toml b/fly.template.toml new file mode 100644 index 0000000..6bd5f2d --- /dev/null +++ b/fly.template.toml @@ -0,0 +1,39 @@ +app = "%NAME%" + +kill_signal = "SIGINT" +kill_timeout = 5 +processes = [] + +[env] + PORT = "8080" + +[experimental] + allowed_public_ports = [] + auto_rollback = true + +[[services]] + http_checks = [] + internal_port = 5006 + processes = ["app"] + protocol = "tcp" + script_checks = [] + + [services.concurrency] + hard_limit = 25 + soft_limit = 20 + 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" diff --git a/fly.toml b/fly.toml index 6bd5f2d..1656b7f 100644 --- a/fly.toml +++ b/fly.toml @@ -1,4 +1,4 @@ -app = "%NAME%" +app = "actual-server" kill_signal = "SIGINT" kill_timeout = 5 @@ -11,6 +11,10 @@ processes = [] allowed_public_ports = [] auto_rollback = true +[mounts] + source="actual_data" + destination="/data" + [[services]] http_checks = [] internal_port = 5006 diff --git a/load-config.js b/load-config.js index c425822..4af565d 100644 --- a/load-config.js +++ b/load-config.js @@ -2,10 +2,12 @@ let config; try { config = require('./config'); } catch (e) { + let fs = require('fs'); + config = { mode: 'development', port: 5006, - files: './user-files' + files: fs.existsSync('/data') ? '/data' : './user-files' }; } diff --git a/sql/default-account.sqlite b/sql/default-account.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..3878e6831c5c80d9af8539f4b3fa7fcc3de6b916 GIT binary patch literal 28672 zcmeI%&u-H&9Ki8p?NT&Ux=WQ)CEuVD0#zIl5?RTlY1syCkmxCd)q|>O(#6?Wj}tdu zj#uEeSKvr&5vf(x6SwFa$$#=oV#go*VtM=_m=#i7W%(j5#4GF2vTf_F5SC>%%G4@T zb?N(NbyJr1T76fwVZ9iCZg>7zPW!>?{OtVdJnl@|4^MvY`hYkB2q1s}0tg_000Iag zfWUtV+~4lET-UXKoEGtyL|)AjsZ8b!N4^*OBJ_>|UzpH=5YJ{)5&EA(@qTo2=8Y!e z)So;rLUHT`W8ZX=#tUg$>GvJSedF5JES<_b zb)A%(-6*~(GIJl9@kRqvw1S4?_Imch2q~%bh*VWJH=L@drYf?zOt-Z9FPn}#?Ct8f zY9Ja^wf&*(xZSQjH{F-N_)Vw1jc#>Bce#v}`kv+6bJTyj=eV!CyL#2%M+2Sfz5FA+ zqS`t;)EO572q1s}0tg_000IagfB*sr)K%a>4~+ePU8k3EA%Fk^2q1s}0tg_000Iag zU<5e-XCWYf00IagfB*srAb