beancount / ledger2beancount

Ledger to Beancount text-based converter
GNU General Public License v3.0
79 stars 15 forks source link

Dockerfile or image on Dockerhub? #239

Closed dennislwm closed 3 years ago

dennislwm commented 3 years ago

Hi,

Is there a Dockerfile or existing image on Dockerhub?

I'm would like to run this on my Windows laptop.

If this doesn't exist, maybe I will try to create this.

tbm commented 3 years ago

There's no Docker file or image. I don't know anything about Docker but if you want to contribute something that'd be nice.

tbm commented 3 years ago

I'm would like to run this on my Windows laptop.

ledger2beancount works in Windows though without Docker. You can use choko to install install Strawberry Perl. The installation section mentions Windows. Did that not work?

tbm commented 3 years ago

@dennislwm are you still interested in working on this?

dennislwm commented 3 years ago

I have already done a Dockerfile that installed all the ledger2beancount dependencies, but I haven't added any environment variables, paths etc. Sorry if taking a long time as I have been busy with my work.

dennislwm commented 3 years ago

Hi,

I'm not familiar with ledger2beancount or perl, so I need some help to verify the expected results.

I've run a test using the Dockerfile and this is the command that I used and its result:

Command $ bin/ledger2beancount examples/simple.ledger

Result ;---------------------------------------------------------------------- ; ledger2beancount conversion notes: ; ; - Unknown line. Please report. Line: ; - Unknown line. Please report. Line: ; - Unknown line. Please report. Line: ; - Unknown line. Please report. Line: ; - Unknown line. Please report. Line: ; - Metadata key Key renamed to key ; - Metadata key Typed renamed to typed ; - Collision for commodity GBP: GBP, £ ;----------------------------------------------------------------------

option "operating_currency" "EUR" ; SPDX-FileCopyrightText: © 2018 Martin Michlmayr tbm@cyrius.com ; ; SPDX-License-Identifier: GPL-3.0-or-later

1970-01-01 open Assets:Wallet 1970-01-01 open Expenses:Purchase

1970-01-01 commodity EUR 1970-01-01 commodity GBP

2018-03-28 txn "Simple transaction " Expenses:Purchase 10.00 EUR Assets:Wallet

2018-03-28 txn "Currency code, posting flag " Expenses:Purchase 20.00 GBP

2018-03-28 * "Transaction flag, aux date, code, conversion " aux-date: 2018-03-27 code: "100" Expenses:Purchase 10.00 EUR @ 0.86 GBP Assets:Wallet -8.60 GBP

2018-03-28 * "Meta data "

tag

key: "value " typed: [2018-03-20] Expenses:Purchase 10.00 EUR Assets:Wallet

tbm commented 3 years ago
;
; - Unknown line. Please report. Line:
; - Unknown line. Please report. Line:

that's not correct

2018-03-28 txn "Simple transaction
"

The quote should be on the same line.

It looks as if it's not parsing the line endings properly?

The file use standard Unix-like file endings. Is that an issue when you run Docker on Windows?

Anyway, there is a test suite that you can run with make test.

tests/README.md contains some info about the test suite. Which Linux does the docker image use? You basically just need coreutils which every Linux distro should offer.

dennislwm commented 3 years ago

I've tried it again and this is the result:

Result ;---------------------------------------------------------------------- ; ledger2beancount conversion notes: ; ; - Metadata key Key renamed to key ; - Metadata key Typed renamed to typed ; - Collision for commodity GBP: GBP, £ ;----------------------------------------------------------------------

option "operating_currency" "EUR" ; SPDX-FileCopyrightText: © 2018 Martin Michlmayr tbm@cyrius.com ; ; SPDX-License-Identifier: GPL-3.0-or-later

1970-01-01 open Assets:Wallet 1970-01-01 open Expenses:Purchase

1970-01-01 commodity EUR 1970-01-01 commodity GBP

2018-03-28 txn "Simple transaction" Expenses:Purchase 10.00 EUR Assets:Wallet

2018-03-28 txn "Currency code, posting flag" Expenses:Purchase 20.00 GBP

2018-03-28 * "Transaction flag, aux date, code, conversion" aux-date: 2018-03-27 code: "100" Expenses:Purchase 10.00 EUR @ 0.86 GBP Assets:Wallet -8.60 GBP

2018-03-28 * "Meta data"

tag

key: "value" typed: 2018-03-20 Expenses:Purchase 10.00 EUR Assets:Wallet

tbm commented 3 years ago

That looks good!

Can you run the test suite (make test)

dennislwm commented 3 years ago

Command $ make test

Result cd tests && ./runtests Skipping ledger validation checks since ledger is not installed Skipping hledger validation checks since hledger is not installed Converting accounts.ledger... ok Converting amounts-decimal-comma.ledger... ok Converting amounts.ledger... ok Converting aux-date.ledger... ok Converting balance-assertion.ledger... ok Converting bug214.ledger... ok Converting bug237.ledger... ok Converting code.ledger... ok Converting comments.ledger... ok Converting commodities.ledger... ok Converting dates-month.ledger... ok Converting dates.ledger... ok Converting directives.ledger... ok Converting fixated.ledger... ok Converting flags.ledger... ok Converting ignore.ledger... ok Converting include1.ledger... ok Converting include2.ledger... ok Converting include3.ledger... ok Converting lots.ledger... ok Converting metadata.ledger... ok Converting narration.ledger... ok Converting no-config.ledger... ok Converting non-standard-account-root.ledger... ok Converting payee.ledger... ok Converting prices.ledger... ok Converting spacing.ledger... ok Converting tags.ledger... ok Converting transactions.ledger... ok Converting virtual-postings.ledger... ok Converting hledger.hledger... ok Validating accounts.beancount... FAIL Validating amounts-decimal-comma.beancount... FAIL Validating amounts.beancount... FAIL Validating aux-date.beancount... FAIL Validating balance-assertion.beancount... FAIL Validating bug214.beancount... FAIL Validating bug237.beancount... FAIL Validating code.beancount... FAIL Validating comments.beancount... FAIL Validating commodities.beancount... FAIL Validating dates-month.beancount... FAIL Validating dates.beancount... FAIL Validating directives.beancount... FAIL Validating fixated.beancount... FAIL Validating flags.beancount... FAIL Validating hledger.beancount... FAIL Validating ignore.beancount... FAIL Validating include1.beancount... FAIL Validating include2.beancount... FAIL Validating include3.beancount... FAIL Validating lots.beancount... FAIL Validating metadata.beancount... FAIL Validating narration.beancount... FAIL Validating no-config.beancount... FAIL Validating non-standard-account-root.beancount... FAIL Validating payee.beancount... FAIL Validating prices.beancount... FAIL Validating spacing.beancount... FAIL Validating tags.beancount... FAIL Validating transactions.beancount... FAIL Validating virtual-postings.beancount... FAIL Makefile:13: recipe for target 'test-stamp' failed

tbm commented 3 years ago

You need to install beancount for the test suite to work.

I should ensure there's a clear error when this isn't the case...

tbm commented 3 years ago

note that you only need beancount for the test suite, not to run ledger2beancount standalone.

Do Docker scripts have a concept of installing additional software to run a test suite as opposed to just building a basic image to run the program

dennislwm commented 3 years ago

The question of having tests within the Dockerfile, depends on your audience. Will your audience be running a test suite? If not, then a separate Dockerfile for running tests makes more sense.

Having said that, it doesn't take much more effort to maintain two separate Dockerfiles: (1) for users, a minimal Dockerfile for production, (2) for admin, a Dockerfile that has additional tests suites.

Below is an article that explains this concept more clearly:

Should You Use The Same Dockerfile For Dev, Staging And Production Builds?

tbm commented 3 years ago

Users wouldn't need to run the test suite, no.

It's just to ensure the Docker image is correct. Thanks for the link. I'll check (Again, I don't know anything about Docker; maybe it's time to learn).

tbm commented 3 years ago

Right, so it sounds you should create the production image and then have a testing image that has a FROM production image and installs the necessary dependencies for the test suite (beancount, ledger, hledger) and then run make test.

Which Linux distro did you use as the base?

dennislwm commented 3 years ago

Yes, that is correct, you can use FROM production image, after it has been published in an image repository, such as DockerHub.

I used ubuntu:18.04 as I'm familiar with this distro. Which distro should I use?

tbm commented 3 years ago

Ubuntu sounds good to me.

I have just registered the beancount community on Docker Hub, so we could publish it here.

Where's your script?

tbm commented 3 years ago

I used ubuntu:18.04 as I'm familiar with this distro. Which distro should I use?

Ubuntu works for me.

The only reason I ask is because I heard that many Docker images use Alpine Linux as its base because this is a much smaller Linux than most other distros. I'd be curious how much smaller the Docker image would get if you used Alpine instead of Ubuntu (but if you don't have time to try this, no problem).

tbm commented 3 years ago

I might try Alpine Docker myself following this example: https://github.com/starlocke/docker-ledger-cli/blob/master/Dockerfile

dennislwm commented 3 years ago

Hi,

I've created a pull request. Here is an example of how to use the Dockerfile.

To build the Docker image from Dockerfile:

$ DOCKER_BUILDKIT=1 docker image build -t <IMAGENAME> .

To run ledger2beancount from the above image:

--- copy and paste into bash script ---

#-------------------------------------------------------------------------
# Usage:  docker run -rm -v <hostdir>:<containerdir>:rw <image> <FILE>
#   hostdir is the host directory that contains your ledger files
#   containerdir is an empty container directory for the app to read/write
#   image is the Docker image name
#   FILE is the ledger file name
if [ -z $1 ]; then
    echo "Run ledger2beancount from a Docker image"
    echo "Usage:"
    echo "  $0 <hostdir> <image> <FILE>"
    echo "  hostdir Use absolute path"
    exit
fi

docker run --rm -v $1:/usr/ledger2beancount/docker:rw $2 docker/$3

--- end ---