From 2197e52f33932ee92af14991db979833fd72b928 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:25:33 -0400 Subject: [PATCH 01/16] Create Dockerfile --- Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6aeed7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Node.js runtime as a parent image +FROM node:22 + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Create the cache directory +RUN mkdir -p ./cache + +# Copy the current directory contents into the container at /usr/src/app +COPY . . + +# Install any needed packages specified in package.json +RUN npm install +RUN npm update +# Define environment variable +ENV NODE_ENV production + +# Run the app when the container launches +ENTRYPOINT ["tail", "-f", "/dev/null"] From af75b031cab5e74a149473c48fc8b0b0732755e0 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:29:25 -0400 Subject: [PATCH 02/16] Create update.sh --- update.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 update.sh diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..8ee0901 --- /dev/null +++ b/update.sh @@ -0,0 +1,22 @@ +#!/bin/bash +export $(xargs <.env) + +# Notify healthchecks.io that the job is starting +curl -fsS --retry 3 "${HEALTHCHECKS_URL}/start" + +# Start the Docker container in detached mode and get its ID +CONTAINER_ID=$(docker run -d actual-helper) + +# Execute the command inside the container +docker exec $CONTAINER_ID node kbb.js +docker exec $CONTAINER_ID node zestimate.js +docker exec $CONTAINER_ID node sync-banks.js + + + +# Stop and remove the container after execution +docker rm -f $CONTAINER_ID + + +# Notify healthchecks.io that the job has completed +curl -fsS --retry 3 "${HEALTHCHECKS_URL}" From c6901dd297cd9486168645e81a2506421559ae78 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:31:04 -0400 Subject: [PATCH 03/16] Create example.env --- example.env | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 example.env diff --git a/example.env b/example.env new file mode 100644 index 0000000..31616d9 --- /dev/null +++ b/example.env @@ -0,0 +1,22 @@ +ACTUAL_SERVER_URL="https://" +ACTUAL_SERVER_PASSWORD="" +ACTUAL_SYNC_ID="" + +# optional, for encrypted files +ACTUAL_FILE_PASSWORD="" + +# optional, if you want to use a different cache directory +ACTUAL_CACHE_DIR="./cache" + +# optional, name of the payee for added interest transactions +INTEREST_PAYEE_NAME="Loan Interest" + +# optional, name of the payee for added interest transactions +INVESTMENT_PAYEE_NAME="Investment" +# optional, name of the cateogry group for added investment tracking transactions +INVESTMENT_CATEGORY_GROUP_NAME="Income" +# optional, name of the category for added investment tracking transactions +INVESTMENT_CATEGORY_NAME="Investment" + +# +HEALTHCHECKS_URL="https://hc-ping.com/" From 9b5159d629bb85f3de892ff4767200568d021452 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:32:17 -0400 Subject: [PATCH 04/16] Create actual-helper.timer --- actual-helper.timer | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 actual-helper.timer diff --git a/actual-helper.timer b/actual-helper.timer new file mode 100644 index 0000000..a73bd50 --- /dev/null +++ b/actual-helper.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run Actual Helper Scripts Nightly + +[Timer] +OnCalendar=*-*-* 00:00:00 +Persistent=true + +[Install] +WantedBy=timers.target From 8041eac7b6ca94a3f91929c032b1cdcba382de52 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:33:49 -0400 Subject: [PATCH 05/16] Create actual-helper.service --- actual-helper.service | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 actual-helper.service diff --git a/actual-helper.service b/actual-helper.service new file mode 100644 index 0000000..ab3eb6f --- /dev/null +++ b/actual-helper.service @@ -0,0 +1,11 @@ +[Unit] +Description=Run Actual Helper Scripts + +[Service] +ExecStart=/actual-helpers/start.sh +WorkingDirectory=/actual-helpers +User=1000 +Group=1000 + +[Install] +WantedBy=multi-user.target From 8cc9e4566995d8417e376500f4d84ca536022bb3 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:51:04 -0400 Subject: [PATCH 06/16] Update README.md --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 51fa1b7..3d841fd 100644 --- a/README.md +++ b/README.md @@ -222,3 +222,27 @@ $ node track-investments.js ``` It is recommended to run this script once per month. + + + +# Setup with Docker: +This guide assumes you already have a working version of docker installed and have cloned the repo to a location of your choice. + +Build the container image_ +`docker build -t actual-helper ./` + +Test if the docker container works correctly. +`docker run -itd actual-helper --name actual-helper` +`docker exec actual-helper node sync-banks.js` + +If it is working correctly the bank sync should execute and run. Now lets automate this to run on a schedule. To do this we will be using systemd timers and a shell script to create a new container and execute the update scripts we want to use. +Allow the script to be executed. Update the script where it does `docker exec` to include any of the scripts you wish to run. +`chmod +x ./update.sh` + +Update the actual-helper.service file to point to the correct location of the update.sh file. Change the user and group info if needed. Also add a healthchecks.io ID to the **.env** if you want to automate alerting as well. +`mv ./actual-helper.timer /etc/systemd/system` +`mv ./actual-helper.service /etc/systemd/system` + +`systemctl enable actual-helper.timer` +`systemctl enable actual-helper.service` +Note: The timer is configured to run at midnight daily by default. From 883d3302c6ee3532d3d70bd7121ab3a6b5379fb4 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:51:50 -0400 Subject: [PATCH 07/16] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d841fd..08751bc 100644 --- a/README.md +++ b/README.md @@ -228,21 +228,29 @@ It is recommended to run this script once per month. # Setup with Docker: This guide assumes you already have a working version of docker installed and have cloned the repo to a location of your choice. -Build the container image_ +Build the container image + `docker build -t actual-helper ./` Test if the docker container works correctly. + `docker run -itd actual-helper --name actual-helper` + `docker exec actual-helper node sync-banks.js` If it is working correctly the bank sync should execute and run. Now lets automate this to run on a schedule. To do this we will be using systemd timers and a shell script to create a new container and execute the update scripts we want to use. Allow the script to be executed. Update the script where it does `docker exec` to include any of the scripts you wish to run. + `chmod +x ./update.sh` Update the actual-helper.service file to point to the correct location of the update.sh file. Change the user and group info if needed. Also add a healthchecks.io ID to the **.env** if you want to automate alerting as well. + `mv ./actual-helper.timer /etc/systemd/system` + `mv ./actual-helper.service /etc/systemd/system` `systemctl enable actual-helper.timer` + `systemctl enable actual-helper.service` + Note: The timer is configured to run at midnight daily by default. From 2bc1127c6d2f939e624f594cd00898382b1aa5ed Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:20:17 -0400 Subject: [PATCH 08/16] Update example.env Co-authored-by: Robert Dyer --- example.env | 3 --- 1 file changed, 3 deletions(-) diff --git a/example.env b/example.env index 31616d9..66c6aed 100644 --- a/example.env +++ b/example.env @@ -17,6 +17,3 @@ INVESTMENT_PAYEE_NAME="Investment" INVESTMENT_CATEGORY_GROUP_NAME="Income" # optional, name of the category for added investment tracking transactions INVESTMENT_CATEGORY_NAME="Investment" - -# -HEALTHCHECKS_URL="https://hc-ping.com/" From bd46f82b0f00b51357fe8e628ed0375b208bfe8d Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:20:24 -0400 Subject: [PATCH 09/16] Update README.md Co-authored-by: Robert Dyer --- README.md | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/README.md b/README.md index 08751bc..1722d51 100644 --- a/README.md +++ b/README.md @@ -238,19 +238,4 @@ Test if the docker container works correctly. `docker exec actual-helper node sync-banks.js` -If it is working correctly the bank sync should execute and run. Now lets automate this to run on a schedule. To do this we will be using systemd timers and a shell script to create a new container and execute the update scripts we want to use. -Allow the script to be executed. Update the script where it does `docker exec` to include any of the scripts you wish to run. - -`chmod +x ./update.sh` - -Update the actual-helper.service file to point to the correct location of the update.sh file. Change the user and group info if needed. Also add a healthchecks.io ID to the **.env** if you want to automate alerting as well. - -`mv ./actual-helper.timer /etc/systemd/system` - -`mv ./actual-helper.service /etc/systemd/system` - -`systemctl enable actual-helper.timer` - -`systemctl enable actual-helper.service` - -Note: The timer is configured to run at midnight daily by default. +If it is working correctly the bank sync should run. From 24155a04556fd171eb69a0b69c92256d9cd7a0a4 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:41:40 -0400 Subject: [PATCH 10/16] Update README.md Fixed docker run command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1722d51..d87b4c0 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ Build the container image Test if the docker container works correctly. -`docker run -itd actual-helper --name actual-helper` +`docker run -itd --name actual-helper actual-helper ` `docker exec actual-helper node sync-banks.js` From 9e2689e0524a08e2123df2aebfb6a0705c58f81a Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:55:35 -0400 Subject: [PATCH 11/16] Update Dockerfile Co-authored-by: Robert Dyer --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d6aeed7..c42215f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ COPY . . RUN npm install RUN npm update # Define environment variable -ENV NODE_ENV production +ENV NODE_ENV=production # Run the app when the container launches ENTRYPOINT ["tail", "-f", "/dev/null"] From df7325a58cc00dce40abdf03f8475fc76e1f84d7 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:56:42 -0400 Subject: [PATCH 12/16] Update Dockerfile Co-authored-by: Robert Dyer --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c42215f..78ffa20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,10 @@ WORKDIR /usr/src/app RUN mkdir -p ./cache # Copy the current directory contents into the container at /usr/src/app -COPY . . +COPY .env *.js *.credentials package.json README.md LICENSE . # Install any needed packages specified in package.json -RUN npm install -RUN npm update +RUN npm install && npm update # Define environment variable ENV NODE_ENV=production From 986e335d3ae686eb6fb228edf4919755c190b4a2 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:59:39 -0400 Subject: [PATCH 13/16] Delete actual-helper.service --- actual-helper.service | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 actual-helper.service diff --git a/actual-helper.service b/actual-helper.service deleted file mode 100644 index ab3eb6f..0000000 --- a/actual-helper.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Run Actual Helper Scripts - -[Service] -ExecStart=/actual-helpers/start.sh -WorkingDirectory=/actual-helpers -User=1000 -Group=1000 - -[Install] -WantedBy=multi-user.target From 287d93399408b3d6a286da706b5e0a2f2472aff9 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:59:51 -0400 Subject: [PATCH 14/16] Delete actual-helper.timer --- actual-helper.timer | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 actual-helper.timer diff --git a/actual-helper.timer b/actual-helper.timer deleted file mode 100644 index a73bd50..0000000 --- a/actual-helper.timer +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Run Actual Helper Scripts Nightly - -[Timer] -OnCalendar=*-*-* 00:00:00 -Persistent=true - -[Install] -WantedBy=timers.target From 5c5e15337d39d6268b29152d01d11712b751fb47 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:01:08 -0400 Subject: [PATCH 15/16] Delete update.sh --- update.sh | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 update.sh diff --git a/update.sh b/update.sh deleted file mode 100644 index 8ee0901..0000000 --- a/update.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -export $(xargs <.env) - -# Notify healthchecks.io that the job is starting -curl -fsS --retry 3 "${HEALTHCHECKS_URL}/start" - -# Start the Docker container in detached mode and get its ID -CONTAINER_ID=$(docker run -d actual-helper) - -# Execute the command inside the container -docker exec $CONTAINER_ID node kbb.js -docker exec $CONTAINER_ID node zestimate.js -docker exec $CONTAINER_ID node sync-banks.js - - - -# Stop and remove the container after execution -docker rm -f $CONTAINER_ID - - -# Notify healthchecks.io that the job has completed -curl -fsS --retry 3 "${HEALTHCHECKS_URL}" From 2d46733605758358ed66bc793d503b262f341269 Mon Sep 17 00:00:00 2001 From: Woodson Gates <43043100+faultoverload@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:08:07 -0400 Subject: [PATCH 16/16] Update Dockerfile Co-authored-by: Robert Dyer --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 78ffa20..5bb625f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # Use an official Node.js runtime as a parent image FROM node:22 +# Don't run as root +USER node + # Set the working directory in the container WORKDIR /usr/src/app