From 0affa5de246f3e9bade279ef9ef7bbae4ebbe91a Mon Sep 17 00:00:00 2001 From: foorschtbar Date: Wed, 19 Aug 2020 21:27:22 +0200 Subject: [PATCH] Inital commit --- .gitignore | 10 +++++ README.md | 84 +++++++++++++++++++++++++++++++++++++++ data/db/.gitkeep | 0 data/telegram/Dockerfile | 23 +++++++++++ data/web/Dockerfile | 23 +++++++++++ data/web/apache.conf | 32 +++++++++++++++ data/web/doctrine.yaml | 33 +++++++++++++++ data/web/services.yaml | 34 ++++++++++++++++ data/web/strichliste.yaml | 71 +++++++++++++++++++++++++++++++++ 9 files changed, 310 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 data/db/.gitkeep create mode 100644 data/telegram/Dockerfile create mode 100644 data/web/Dockerfile create mode 100644 data/web/apache.conf create mode 100644 data/web/doctrine.yaml create mode 100644 data/web/services.yaml create mode 100644 data/web/strichliste.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fd6631 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +settings.env +docker-compose.yml + +#database +/data/db/* +!/data/db/.gitkeep + +#telegram +/data/telegram/* +!/data/telegram/Dockerfile \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..538c006 --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +# strichliste-docker - A Strichliste Docker Container + +This is a docker container for the [strichliste](https://www.strichliste.org/) using the [strichliste frontend and backend bundle](https://github.com/strichliste/strichliste), a MariaDB database and a the Telegram Bot [strichliste-telegram](https://github.com/Westwoodlabs/strichliste-telegram). + +## Usage + +- Clone this repository. +- Create settings.env from template and change values. +- Create docker-compose.yml from template and change for your needs (remove treafik for example). +- Setup initial database. + +### Setup initial database +After configuring the environment variables you can start the container and create the inital database schema with the following command: +``` +./../bin/console doctrine:schema:create +``` +(you might need to wait a bit for the database to start up, the command will tell you if it succeeded or not) + +## Templates +Example settings.env configuration: + +```env +DB_HOST=db +MYSQL_ROOT_PASSWORD= +MYSQL_DATABASE=strichliste +MYSQL_USER=strichliste +MYSQL_PASSWORD= +DATABASE_URL=mysql://strichliste:@db/strichliste +``` + +Example docker-compose configuration: + +```yml +version: "3.8" + +services: + + web: + build: ./data/web + env_file: + - settings.env + networks: + - reverse-proxy + - internal + volumes: + - ./data/web/services.yaml:/var/www/html/config/services.yaml + - ./data/web/strichliste.yaml:/var/www/html/config/strichliste.yaml + - ./data/web/doctrine.yaml:/var/www/html/config/packages/doctrine.yaml + labels: + - "traefik.enable=true" + - "traefik.http.routers.strichliste.rule=Host(`myhostname.fqdn.local`)" + - "traefik.http.routers.strichliste.entryPoints=https" + - "traefik.http.routers.strichliste.tls=true" + - "traefik.http.services.strichliste.loadbalancer.server.scheme=http" + - "traefik.http.services.strichliste.loadbalancer.server.port=80" + restart: unless-stopped + depends_on: + - db + db: + image: mariadb + restart: unless-stopped + env_file: + - settings.env + volumes: + - ./data/db:/var/lib/mysql + networks: + - internal + + telegram: + build: ./data/telegram + restart: unless-stopped + volumes: + - ./data/telegram/authorizedUsers.json:/usr/src/app/authorizedUsers.json + - ./data/telegram/config.py:/usr/src/app/config.py + networks: + - internal + +networks: + reverse-proxy: + external: true + internal: + external: false +``` + diff --git a/data/db/.gitkeep b/data/db/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/telegram/Dockerfile b/data/telegram/Dockerfile new file mode 100644 index 0000000..0260f75 --- /dev/null +++ b/data/telegram/Dockerfile @@ -0,0 +1,23 @@ +#download StrichlisteTelegramBridge with git clone +FROM alpine:3.8 as release + +RUN apk --no-cache add ca-certificates \ + && apk --no-cache add \ + git + +RUN mkdir /source + +WORKDIR /source + +RUN git clone --depth=1 https://github.com/Westwoodlabs/strichliste-telegram.git . + +# build StrichlisteTelegramBridge container +FROM python:3 + +COPY --from=release /source /usr/src/app + +WORKDIR /usr/src/app + +RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt + +CMD [ "python", "./bot.py" ] \ No newline at end of file diff --git a/data/web/Dockerfile b/data/web/Dockerfile new file mode 100644 index 0000000..41e77e4 --- /dev/null +++ b/data/web/Dockerfile @@ -0,0 +1,23 @@ +FROM alpine:3.8 as release + +RUN apk --no-cache add ca-certificates \ + && apk --no-cache add \ + curl \ + tar + +RUN mkdir /source +WORKDIR /source +RUN curl -Lo strichliste.tar.gz https://github.com/strichliste/strichliste/releases/download/v1.7.1/strichliste.tar.gz +RUN tar -xf strichliste.tar.gz +RUN rm -r strichliste.tar.gz + +FROM php:7.3-apache + +RUN docker-php-ext-install pdo_mysql + +COPY --from=release /source /var/www/html + +RUN chown -R www-data:www-data /var/www/html + +# configure apache +COPY ./apache.conf /etc/apache2/sites-available/000-default.conf \ No newline at end of file diff --git a/data/web/apache.conf b/data/web/apache.conf new file mode 100644 index 0000000..aa6f58c --- /dev/null +++ b/data/web/apache.conf @@ -0,0 +1,32 @@ +User www-data +Group www-data + + + ServerName strichliste + + DocumentRoot /var/www/html/public + + AllowOverride All + Order Allow,Deny + Allow from All + + FallbackResource /index.php + + + # uncomment the following lines if you install assets as symlinks + # or run into problems when compiling LESS/Sass/CoffeeScript assets + + Options FollowSymlinks + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # Change log to works better behind a reverse proxy + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy + ErrorLog ${APACHE_LOG_DIR}/error.log + SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded + CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded + CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded + \ No newline at end of file diff --git a/data/web/doctrine.yaml b/data/web/doctrine.yaml new file mode 100644 index 0000000..26c31f9 --- /dev/null +++ b/data/web/doctrine.yaml @@ -0,0 +1,33 @@ +parameters: + # Adds a fallback DATABASE_URL if the env var is not set. + # This allows you to run cache:warmup even if your + # environment variables are not available yet. + # You should not need to change this value. + env(DATABASE_URL): '' + +doctrine: + dbal: + # configure these for your database server + driver: 'pdo_mysql' + server_version: '5.7' + charset: utf8mb4 + default_table_options: + charset: utf8mb4 + collate: utf8mb4_unicode_ci + + url: '%env(resolve:DATABASE_URL)%' + orm: + auto_generate_proxy_classes: '%kernel.debug%' + naming_strategy: doctrine.orm.naming_strategy.underscore + auto_mapping: true + dql: + datetime_functions: + date: App\Doctrine\Functions\Date + iif: App\Doctrine\Functions\Iif + mappings: + App: + is_bundle: false + type: annotation + dir: '%kernel.project_dir%/src/Entity' + prefix: 'App\Entity' + alias: App diff --git a/data/web/services.yaml b/data/web/services.yaml new file mode 100644 index 0000000..e8e5dd0 --- /dev/null +++ b/data/web/services.yaml @@ -0,0 +1,34 @@ +# This file is the entry point to configure your own services. +# Files in the packages/ subdirectory configure your dependencies. + +imports: + - { resource: 'strichliste.yaml' } + +# Put parameters here that don't need to change on each machine where the app is deployed +# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration +parameters: + webroot: '%kernel.project_dir%/public' + +services: + # default configuration for services in *this* file + _defaults: + autowire: true # Automatically injects dependencies in your services. + autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + public: false # Allows optimizing the container by removing unused services; this also means + # fetching services directly from the container via $container->get() won't work. + # The best practice is to be explicit about your dependencies anyway. + + # makes classes in src/ available to be used as services + # this creates a service per class whose id is the fully-qualified class name + App\: + resource: '../src/*' + exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' + + # controllers are imported separately to make sure services can be injected + # as action arguments even if you don't extend any base controller class + App\Controller\: + resource: '../src/Controller' + tags: ['controller.service_arguments'] + + # add more service definitions when explicit configuration is needed + # please note that last definitions always *replace* previous ones diff --git a/data/web/strichliste.yaml b/data/web/strichliste.yaml new file mode 100644 index 0000000..ebe1ee7 --- /dev/null +++ b/data/web/strichliste.yaml @@ -0,0 +1,71 @@ +parameters: + strichliste: + + article: + enabled: true + autoOpen: true + + common: + idleTimeout: 30000 # Time in ms + + paypal: + enabled: false + recipient: "foo@bar.de" + fee: 0 + + user: + # See http://de.php.net/manual/en/datetime.formats.relative.php + stalePeriod: '14 day' + + i18n: + dateFormat: 'YYYY-MM-DD HH:mm:ss' + timezone: 'auto' + language: 'en' + currency: + name: 'Euro' + symbol: '€' + alpha3: 'EUR' + + account: + boundary: + upper: 20000 + lower: -2000 + + # Be aware: All amounts are in cents! + payment: + undo: + enabled: true + delete: false + timeout: '20 sec' # See http://de.php.net/manual/en/datetime.formats.relative.php + + boundary: + upper: 15000 + lower: -2000 + + transactions: + enabled: true + + splitInvoice: + enabled: true + + deposit: + enabled: true + custom: true + steps: + - 50 + - 100 + - 200 + - 500 + - 1000 + - 2000 + + dispense: + enabled: true + custom: true + steps: + - 50 + - 100 + - 200 + - 500 + - 1000 + - 2000