diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1692082 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.ash_history +.git +.cpan +.cpanm +/files/ +/local/ +/lutim.conf +/lutim.db \ No newline at end of file diff --git a/.gitignore b/.gitignore index 16e53dc..dd3b30b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ tmp/* .zanata-cache/* cover_db/* *.passwd +.ash_history +.vscode/ +.DS_Store +.cpanm/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bbee699 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM alpine:3.9 + +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Let's Upload That Image" \ + org.label-schema.url="https://lut.im/" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://git.framasoft.org/luc/lutim" \ + org.label-schema.vendor="Luc Didry" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" + +RUN adduser -D lutim +COPY --chown=lutim:lutim . /home/lutim + +WORKDIR /home/lutim +RUN /bin/sh /home/lutim/docker/build.sh + +USER lutim + +ENTRYPOINT ["/bin/sh", "/home/lutim/docker/entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..e07b9f9 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,22 @@ +version: '3.3' + +services: + app_dev: + build: . + ports: + - 8080:8080 + volumes: + - .:/home/lutim + command: dev + postgres_dev: + image: postgres:11.2-alpine + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: lutim + POSTGRES_DB: lutim + memcached: + image: memcached:1.5-alpine + adminer: + image: dehy/adminer + ports: + - 8081:80 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ec40467 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.3' + +services: + app: + build: . + ports: + - 8080:8080 + volumes: + - ./lutim.conf:/home/lutim/lutim.conf:ro + db: + image: postgres:11.2-alpine + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: lutim + POSTGRES_DB: lutim + cache: + image: memcached:1.5-alpine + minion: + build: . + command: minion + volumes: + - ./lutim.conf:/home/lutim/lutim.conf:ro + minion_db: + image: postgres:11.2-alpine + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: lutim_minion + POSTGRES_DB: lutim_minion \ No newline at end of file diff --git a/docker-stack.yml b/docker-stack.yml new file mode 100644 index 0000000..6fb39ec --- /dev/null +++ b/docker-stack.yml @@ -0,0 +1,39 @@ +version: '3.3' + +services: + app: + image: aquinum/lutim + configs: + - source: lutim.conf + target: /home/lutim/lutim.conf + uid: '1000' + gid: '1000' + mode: 0440 + deploy: + replicas: 1 + db: + image: postgres:11.2-alpine + environment: + POSTGRES_PASSWORD: + POSTGRES_USER: lutim + POSTGRES_DB: lutim + cache: + image: memcached:1.5-alpine + minion: + image: aquinum/lutim + command: minion + configs: + - source: lutim.conf + target: /home/lutim/lutim.conf + uid: '1000' + gid: '1000' + mode: 0440 + minion_db: + image: mariadb:10.3 + environment: + MYSQL_ROOT_PASSWORD: + MYSQL_DATABASE: lutim_minion + +configs: + lutim.conf: + file: ./lutim.conf \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 0000000..fd1e763 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +set -eu + +apk update +apk add perl libpq perl-crypt-rijndael perl-io-socket-ssl perl-net-ssleay su-exec shared-mime-info libressl +sh $(dirname $0)/install-dev-env.sh + +sh $(dirname $0)/install-imagemagick.sh + +cpan notest Carton Config::FromHash +carton install --without test + +# Remove dev env +apk del .build-deps +rm -rf /var/cache/apk/* /root/.cpan* \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..4fe4050 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -eu + +cd ~lutim + +if [ "${1:-}" == "dev" ] +then + echo "" + echo "" + echo "Container started in dev mode. Connect to the container with the following command:" + echo " docker-compose -f docker-compose.dev.yml exec -u root app_dev sh" + echo "" + echo "" + echo "You can then install the build dependencies with this command" + echo " sh ~lutim/docker/install-dev-env.sh" + + tail -f /dev/null + exit 0 +fi + +# If MySQL/PostgreSQL, wait for database to be up +DB_TYPE=$(perl utilities/read_conf.pl dbtype sqlite) +DB_HOST= +DB_PORT= +if [ "$DB_TYPE" == "postgresql" ] +then + DB_HOST=$(perl utilities/read_conf.pl pgdb/host db) + DB_PORT=$(perl utilities/read_conf.pl pgdb/port 5432) +fi +if [ -n "$DB_HOST" -a -n "$DB_PORT" ] +then + while ! nc -vz "${DB_HOST}" "${DB_PORT}"; do + echo "Waiting for database..." + sleep 1; + done +fi + +if [ "${1:-}" == "minion" ] +then + exec carton exec script/application minion worker +fi + +exec carton exec hypnotoad -f script/lutim \ No newline at end of file diff --git a/docker/install-dev-env.sh b/docker/install-dev-env.sh new file mode 100644 index 0000000..2f219d7 --- /dev/null +++ b/docker/install-dev-env.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +apk --update add --virtual .build-deps build-base perl-utils perl-dev postgresql-dev vim wget zlib-dev \ No newline at end of file diff --git a/docker/install-imagemagick.sh b/docker/install-imagemagick.sh new file mode 100644 index 0000000..5a4f73f --- /dev/null +++ b/docker/install-imagemagick.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +# Instructions from https://imagemagick.org/script/perl-magick.php + +set -eu + +IM_VERSION=7.0.8-41 +SHA256_DIGEST=93f73a245c25194f757c075df9f2ec40010376200cc664c21646565b8690112c + +IM_DIR="ImageMagick-$IM_VERSION" +TARBALL="$IM_DIR.tar.gz" + +ORIG_DIR="$(pwd)" + +apk add libgomp libgcc libmagic \ + libjpeg libjpeg-turbo-dev \ + libpng libpng-dev \ + tiff tiff-dev \ + libwebp libwebp-dev + +mkdir -p /tmp/im-build +cd /tmp/im-build + +echo "$SHA256_DIGEST *$TARBALL" > SHA256SUM + +wget https://imagemagick.org/download/$TARBALL -O $TARBALL +sha256sum -c SHA256SUM + +tar xvf $TARBALL +cd $IM_DIR +./configure --with-perl --with-jpeg --with-png --with-tiff --with-webp +make -j$(nproc) +make install + +ldconfig /usr/local/lib +perl -MImage::Magick -le 'print Image::Magick->QuantumDepth' + +cd "$ORIG_DIR" +apk del libjpeg-turbo-dev libpng-dev tiff-dev libwebp-dev +rm -rf /tmp/im-build \ No newline at end of file diff --git a/utilities/read_conf.pl b/utilities/read_conf.pl new file mode 100755 index 0000000..1076b6d --- /dev/null +++ b/utilities/read_conf.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl + +# read_conf.pl - Outputs lutim's config value for given keypath + +use strict; +use warnings; + +use FindBin; +use Cwd qw(realpath); +use Config::FromHash; + +sub print_help { + print <new(filename => $filename); +my $value = $config->get($ARGV[0]); + +if (defined $value) { + print $value; + exit 0; +} +if (not defined $value and defined $ARGV[1]) { + print $ARGV[1]; + exit 0; +} +print STDERR "Error: keypath \"$ARGV[0]\" not found in config, and no default value provided.\n"; +exit 1; \ No newline at end of file