client: docker: complete build overhaul, optimize

This commit brings a complete overhaul of the build system:

- Creates a separation of concerns for 'local' and 'remote' building
  * 'local' is built locally via the docker-finance `build` command
  * 'remote' is built *outside* of the docker-finance `build` command
    (pushed to a remote registry and then pulled by the 'local' build)
  * Related refactoring
    - Dockerfiles
    - `lib_gen`

- Adds remote image 'hledger-suite'
  * Provides the latest versions of all `hledger` related binaries
  * No longer relies on package maintainers / out-dated packages

- Adds remote image 'docker-finance'
  * Provides base image for 'finance' and 'dev-tools' images
    - tags 'archlinux' | 'ubuntu' | 'dev-tools'

- Removes previous `hledger` related build modules
  * Removes building any `hledger` related binaries locally

- Removes 'experimental' build
  * End-user can use local custom Dockerfile and/or custom tag instead

- Updates the 'default' | 'slim' | 'tiny' | 'micro' build types
  * Refactors build type requirements into separate build modules
    - Adds 'fetch' module
    - Adds 'track' module
    - Adds 'user' module
      * creates container user *after* base and all other modules
      * allows for quick re-building across multiple local users
    - Updates 'root' module
  * `lib_docker`
    - Updates usage help
    - Adds build modules per build type

- Huge optimizations
  * Vastly improves build times
    - ~60% faster w/ a fresh build
    - ~60%-90% faster rebuild (depending on image type)
  * Vastly improves image sizes
    - e.g., 'default' Arch Linux image size is ~50% smaller
This commit is contained in:
2024-09-16 21:46:11 -07:00
parent 9feb05be2d
commit dc4990ab90
34 changed files with 554 additions and 582 deletions

View File

@@ -0,0 +1,81 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM ubuntu:rolling
RUN apt-get update -y
# Add builder user (for `composer` and non-root building)
RUN useradd -m -s /bin/bash -r builder
#
# 'dev-tools' linters
#
# Bash
RUN apt-get install -y shfmt shellcheck
# C++
RUN apt-get install -y clang-format cppcheck cpplint
# PHP
RUN apt-get install -y composer
USER builder
WORKDIR /usr/local/lib/php
RUN composer require -n --dev friendsofphp/php-cs-fixer
RUN composer require -n --dev phpstan/phpstan
USER root
RUN echo "export PATH=\"\$PATH:/usr/local/lib/php/vendor/bin\"" >>/etc/bash.bashrc
#
# 'finance' dependencies (`fetch` APIs)
#
RUN apt-get install -y php php-bcmath php-curl php-gmp
USER builder
WORKDIR /usr/local/lib/php
RUN composer require -n ozdemirburak/json-csv
RUN composer require -n ccxt/ccxt
# "Sunsetted" Coinbase Pro
RUN composer require -n mocking-magician/coinbase-pro-sdk
#
# 'dev-tools' misc.
#
USER root
# Doxygen
RUN apt-get install -y doxygen graphviz
# docker-finance `version` command
RUN apt-get install -y yq
#
# Entrypoint
#
COPY ./entrypoint.bash /entrypoint.bash
RUN chmod a+rx /entrypoint.bash
ENTRYPOINT ["/entrypoint.bash"]
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,26 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
services:
dev-tools:
image: evergreencrypto/docker-finance:dev-tools
container_name: evergreencrypto_docker-finance_dev-tools
build:
dockerfile: Dockerfile.dev-tools
# TODO: add labels
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Keep container running
tail -f /dev/null
exec "$@"

View File

@@ -0,0 +1,53 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Base dependencies
#
# https://hub.docker.com/evergreencrypto/hledger-suite
FROM evergreencrypto/hledger-suite:latest AS hledger-suite
# https://hub.docker.com/_/archlinux
FROM archlinux:base-devel
COPY --from=hledger-suite /usr/local/bin/hledger /usr/local/bin/hledger
COPY --from=hledger-suite /usr/local/bin/hledger-ui /usr/local/bin/hledger-ui
COPY --from=hledger-suite /usr/local/bin/hledger-web /usr/local/bin/hledger-web
COPY --from=hledger-suite /usr/local/bin/hledger-iadd /usr/local/bin/hledger-iadd
COPY --from=hledger-suite /usr/local/bin/hledger-flow /usr/local/bin/hledger-flow
RUN pacman -Syu --noconfirm --disable-download-timeout
RUN pacman -Syu \
bc \
csvkit \
vim \
xsv \
yq \
--noconfirm --disable-download-timeout
#
# Entrypoint
#
USER root
COPY ./entrypoint.bash /entrypoint.bash
RUN chmod a+rx /entrypoint.bash
ENTRYPOINT ["/entrypoint.bash"]
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,56 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Base dependencies
#
# https://hub.docker.com/evergreencrypto/hledger-suite
FROM evergreencrypto/hledger-suite:latest AS hledger-suite
# https://hub.docker.com/_/ubuntu/
FROM ubuntu:rolling
COPY --from=hledger-suite /usr/local/bin/hledger /usr/local/bin/hledger
COPY --from=hledger-suite /usr/local/bin/hledger-ui /usr/local/bin/hledger-ui
COPY --from=hledger-suite /usr/local/bin/hledger-web /usr/local/bin/hledger-web
COPY --from=hledger-suite /usr/local/bin/hledger-iadd /usr/local/bin/hledger-iadd
COPY --from=hledger-suite /usr/local/bin/hledger-flow /usr/local/bin/hledger-flow
RUN apt-get update -y
RUN apt-get install -y \
bc \
csvkit \
gawk \
vim \
yq \
zlib1g-dev
RUN apt-get install -y cargo
RUN cargo install xsv --root /usr
#
# Entrypoint
#
USER root
COPY ./entrypoint.bash /entrypoint.bash
RUN chmod a+rx /entrypoint.bash
ENTRYPOINT ["/entrypoint.bash"]
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,31 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
services:
archlinux:
image: evergreencrypto/docker-finance:archlinux
container_name: evergreencrypto_docker-finance_archlinux
build:
dockerfile: Dockerfile.archlinux
ubuntu:
image: evergreencrypto/docker-finance:ubuntu
container_name: evergreencrypto_docker-finance_ubuntu
build:
dockerfile: Dockerfile.ubuntu
# TODO: add labels
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# *** WARNING: REQUIRES GENERATED CLIENT ENVIRONMENT ***
#
if [ -z "$DOCKER_FINANCE_CONTAINER_REPO" ]; then
echo "FATAL: DOCKER_FINANCE_CONTAINER_REPO not set" >&2
exit 1
fi
if [ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ]; then
echo "FATAL: DOCKER_FINANCE_CONTAINER_FLOW not set" >&2
exit 1
fi
# Dynamically connect hledger-flow source with end-user hledger-flow structure
# TODO: annoying, find a better way
ln -f -s "${DOCKER_FINANCE_CONTAINER_REPO}/src/hledger-flow" "${DOCKER_FINANCE_CONTAINER_FLOW}/src"
# Keep container running
tail -f /dev/null
exec "$@"

View File

@@ -0,0 +1,57 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM haskell:latest
RUN apt-get update -y
RUN apt-get upgrade -y
#
# hledger-flow
#
WORKDIR /usr/local/src
RUN git clone --depth=1 https://github.com/apauley/hledger-flow -b v0.15.0
WORKDIR /usr/local/src/hledger-flow
RUN stack setup
RUN stack install --install-ghc --local-bin-path=/usr/local/bin
#
# hledger-iadd
#
WORKDIR /usr/local/src
RUN git clone --depth=1 https://github.com/hpdeifel/hledger-iadd -b v1.3.21
WORKDIR /usr/local/src/hledger-iadd
RUN sed -i 's/^ - hledger-lib-1\.32\.2/ - hledger-lib-1\.33\.1@sha256\:3920c9b273ecae8be59628b6f6f93fd1b4f3cee03a89fda23b0c4b183d0577f2\,7844/g' stack.yaml
RUN stack setup
RUN stack install --resolver="lts" --install-ghc --local-bin-path=/usr/local/bin hledger-iadd
#
# hledger / hledger-ui / hledger-web
#
WORKDIR /usr/local/src
RUN git clone --depth=1 https://github.com/simonmichael/hledger -b 1.40
WORKDIR /usr/local/src/hledger
RUN stack setup
RUN stack install --resolver="lts" --install-ghc --local-bin-path=/usr/local/bin
# vim: sw=2 sts=2 si ai et

View File

@@ -0,0 +1,24 @@
# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
services:
hledger-suite:
image: evergreencrypto/hledger-suite:latest
container_name: evergreencrypto_hledger-suite
build: .
# vim: sw=2 sts=2 si ai et