[FEAT] Run in a Docker container

This commit is contained in:
2023-10-29 01:54:15 +01:00
parent 072740a2b7
commit a01611e193
5 changed files with 38 additions and 3 deletions

12
Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM php:latest
RUN apt-get update && apt-get install cron -y
COPY autosave.php /srv/autosave.php
COPY autosave.cron /srv/autosave.cron
COPY entrypoint.sh /srv/entrypoint.sh
RUN chmod 0600 /srv/autosave.cron
RUN chmod 0700 /srv/entrypoint.sh
RUN crontab /srv/autosave.cron
WORKDIR /srv
RUN docker-php-ext-install bcmath
RUN printenv | grep -v "no_proxy" >> /etc/environment
ENTRYPOINT /srv/entrypoint.sh

3
autosave.cron Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
0 * * * * /usr/local/bin/php /srv/autosave.php --account=$SRC_ACCOUNT --destination=$DST_ACCOUNT --amount=$AMOUNT --days=$DAYS > /proc/1/fd/1 2>/proc/1/fd/2

View File

@@ -29,8 +29,9 @@ bcscale(12);
* Keep in mind that running this script is entirely AT YOUR OWN RISK with ZERO GUARANTEES.
*/
const EXCLUDED_TAGS = 'Direct debit';
const FIREFLY_III_TOKEN = 'ey...';
define('EXCLUDED_TAGS', (string)((getenv('EXCLUDED_TAGS') !== false) ? getenv('EXCLUDED_TAGS') : ''));
define('FIREFLY_III_TOKEN', (string)((getenv('FIREFLY_III_TOKEN') !== false) ? getenv('FIREFLY_III_TOKEN') : 'ey...'));
define('FIREFLY_III_URL', (string)((getenv('FIREFLY_III_URL') !== false) ? getenv('FIREFLY_III_URL') : 'https://firefly-iii.org'));
/*
* HERE BE MONSTERS
@@ -136,6 +137,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void
));
return;
}
// create transaction:
$submission = [
'transactions' => [
@@ -151,6 +153,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void
],
],
];
// submit:
$result = postCurlRequest('/api/v1/transactions', $submission);
$groupId = $result['data']['id'];
@@ -285,7 +288,7 @@ function getTransactions(int $accountId): array
$tags = $transaction['tags'];
$noExcludedTags = true;
foreach (explode(";", EXCLUDED_TAGS) as $excludedTag) {
if (in_array($tags, $excludedTag)) {
if (in_array($excludedTag, $tags)) {
$noExcludedTags = false;
}
}

13
docker-compose.yml Normal file
View File

@@ -0,0 +1,13 @@
version: '3.3'
services:
php-cron:
image: fireflyiii-autosave-cron
build: .
environment:
FIREFLY_III_TOKEN: 'ey...'
FIREFLY_III_URL: 'https://firefly-iii.org'
EXCLUDED_TAGS:
SRC_ACCOUNT: 1
DST_ACCOUNT: 2
AMOUNT: 1
DAYS: 1

4
entrypoint.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
printenv | grep -v "no_proxy" >> /etc/environment
cron -f