Initial commit

This commit is contained in:
Magnus Walbeck 2020-06-08 21:45:54 +02:00
commit dc61924724
Signed by: mwalbeck
GPG key ID: CCB78CFF3F950769
7 changed files with 247 additions and 0 deletions

38
.drone.yml Normal file
View file

@ -0,0 +1,38 @@
---
kind: pipeline
name: build and publish
steps:
- name: docker
image: plugins/docker
settings:
dockerfile: Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
repo: mwalbeck/flox
tags:
- "latest"
trigger:
branch:
- master
event:
- push
---
kind: pipeline
name: test
steps:
- name: docker
image: plugins/docker
settings:
dockerfile: Dockerfile
repo: mwalbeck/flox
dry_run: true
trigger:
event:
- pull_request

83
Dockerfile Normal file
View file

@ -0,0 +1,83 @@
FROM debian:10.3-slim AS prep
ENV FLOX_VERSION master
RUN set -ex; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
git \
ca-certificates \
; \
git clone --branch $FLOX_VERSION https://github.com/devfake/flox.git /flox;
FROM composer:1.10.6 AS composer
COPY --from=prep /flox /flox
RUN set -ex; \
\
cd /flox/backend; \
composer install;
FROM php:7.3.17-fpm-buster
COPY --from=composer /flox /usr/share/flox
RUN set -ex; \
\
groupadd --system foo; \
useradd --no-log-init --system --gid foo --create-home foo; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
supervisor \
busybox-static \
gosu \
sqlite3 \
rsync \
; \
rm -rf /var/lib/apt/lists/*; \
\
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
\
mkdir -p \
/var/log/supervisord \
/var/run/supervisord \
/var/spool/cron/crontabs \
/var/www/flox \
; \
echo '* * * * * php /var/www/flox/backend/artisan schedule:run >> /dev/null 2>&1' > /var/spool/cron/crontabs/foo;
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libpq-dev \
; \
\
docker-php-ext-install -j "$(nproc)" \
bcmath \
pdo_mysql \
pdo_pgsql \
opcache \
; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*;
COPY entrypoint.sh /entrypoint.sh
COPY cron.sh /cron.sh
COPY supervisord.conf /supervisord.conf
WORKDIR /var/www/flox
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]

19
LICENSE Normal file
View file

@ -0,0 +1,19 @@
MIT License Copyright (c) 2020 Magnus Walbeck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# docker-flox
[![Build Status](https://build.walbeck.it/api/badges/mwalbeck/docker-flox/status.svg?ref=refs/heads/master)](https://build.walbeck.it/mwalbeck/docker-flox)
This is a docker image for [flox](https://github.com/devfake/flox) built from the current master branch.

4
cron.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
set -eu
exec busybox crond -f -l 0 -L /dev/stdout

69
entrypoint.sh Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
set -eu
UID=${UID:-1000}
GID=${GID:-1000}
FLOX_DB_INIT=${FLOX_DB_INIT:-false}
FLOX_DB_CONNECTION=${FLOX_DB_CONNECTION:-sqlite}
FLOX_DB_NAME=${FLOX_DB_NAME:-/var/www/flox/backend/database/database.sqlite}
FLOX_DB_USER=${FLOX_DB_USER:-}
FLOX_DB_PASS=${FLOX_DB_PASS:-}
FLOX_DB_HOST=${FLOX_DB_HOST:-localhost}
FLOX_DB_PORT=${FLOX_DB_PORT:-3306}
FLOX_ADMIN_USER=${FLOX_ADMIN_USER:-admin}
FLOX_ADMIN_PASS=${FLOX_ADMIN_PASS:-admin}
FLOX_APP_URL=${FLOX_APP_URL:-http://localhost}
FLOX_APP_ENV=${FLOX_APP_ENV:-local}
FLOX_APP_DEBUG=${FLOX_APP_DEBUG:-false}
FLOX_CLIENT_URI=${FLOX_CLIENT_URI:-/}
FLOX_TIMEZONE=${FLOX_TIMEZONE:-UTC}
FLOX_DAILY_REMINDER_TIME=${FLOX_DAILY_REMINDER_TIME:-10:00}
FLOX_WEEKLY_REMINDER_TIME=${FLOX_WEEKLY_REMINDER_TIME:-20:00}
TMDB_API_KEY=${TMDB_API_KEY}
usermod -o -u "$UID" foo
groupmod -o -g "$GID" foo
rsync -rlD --delete \
--exclude /backend/.env \
--exclude /backend/database/database.sqlite \
--exclude /backend/database/database.sqlite-journal \
--exclude /public/assets/backdrop/ \
--exclude /public/assets/poster/ \
--exclude /public/exports/ \
/usr/share/flox/ /var/www/flox
cd backend
if [ "$FLOX_DB_CONNECTION" = "sqlite" ]; then
touch /var/www/flox/backend/database/database.sqlite
php artisan flox:init --no-interaction $FLOX_DB_NAME
else
php artisan flox:init --no-interaction $FLOX_DB_NAME $FLOX_DB_USER $FLOX_DB_PASS $FLOX_DB_HOST $FLOX_DB_PORT
fi
sed -i "s!^DB_CONNECTION=.*!DB_CONNECTION=$FLOX_DB_CONNECTION!g" .env
sed -i "s!^TMDB_API_KEY=.*!TMDB_API_KEY=$TMDB_API_KEY!g" .env
sed -i "s!^APP_URL=.*!APP_URL=$FLOX_APP_URL!g" .env
sed -i "s!^CLIENT_URI=.*!CLIENT_URI=$FLOX_CLIENT_URI!g" .env
sed -i "s!^APP_DEBUG=.*!APP_DEBUG=$FLOX_APP_DEBUG!g" .env
sed -i "s!^TIMEZONE=.*!TIMEZONE=$FLOX_TIMEZONE!g" .env
sed -i "s!^DAILY_REMINDER_TIME=.*!DAILY_REMINDER_TIME=$FLOX_DAILY_REMINDER_TIME!g" .env
sed -i "s!^WEEKLY_REMINDER_TIME=.*!WEEKLY_REMINDER_TIME=$FLOX_WEEKLY_REMINDER_TIME!g" .env
sed -i "s!^APP_ENV=.*!APP_ENV=local!g" .env
if [ "$FLOX_DB_INIT" = "true" ]; then
php artisan flox:db --no-interaction $FLOX_ADMIN_USER $FLOX_ADMIN_PASS
else
php artisan migrate
fi
sed -i "s!^APP_ENV=.*!APP_ENV=$FLOX_APP_ENV!g" .env
chown foo /proc/self/fd/1 /proc/self/fd/2
chown -R foo:foo /var/www/flox \
/var/log/supervisord \
/var/run/supervisord \
/var/spool/cron/crontabs
exec gosu foo "$@"

29
supervisord.conf Normal file
View file

@ -0,0 +1,29 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisord/supervisord.log
pidfile=/var/run/supervisord/supervisord.pid
childlogdir=/var/log/supervisord/
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error
[program:php-fpm]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php-fpm
[program:flox-worker]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php /var/www/flox/backend/artisan queue:work --tries=3
[program:cron]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=/cron.sh