Commit 6d6d5049 authored by Arnaud de Mouhy's avatar Arnaud de Mouhy

Dockerized

parent 9a279f05
.cpan
.cpanm
.git
docker-compose.yml
local
log/*
lstu.conf
lstu.db
\ No newline at end of file
.cpan
.cpanm
.*_history
local/*
cover_db/*
safebrowsing_db/*
......
......@@ -13,3 +13,4 @@
* Pierre Rudloff
* Belvar (Gwenn M) (breton translation)
* Ira W. Snyder
* Arnaud de Mouhy (docker port)
\ No newline at end of file
FROM alpine:3.7
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Let's Shorten That URL" \
org.label-schema.url="https://lstu.fr/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://git.framasoft.org/luc/lstu" \
org.label-schema.vendor="Luc Didry" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
RUN adduser -D lstu
COPY --chown=lstu:lstu . /home/lstu
WORKDIR /home/lstu
RUN apk --update add ca-certificates perl perl-netaddr-ip perl-io-socket-ssl perl-dbd-pg mariadb-client-libs libpng zlib \
&& apk add --virtual .build-deps build-base perl-utils perl-dev make sudo zlib-dev libpng-dev postgresql-dev mariadb-dev \
&& cpan Carton \
&& sudo -u lstu carton install --deployment --without=test \
&& perl -MCPAN -e 'install inc::latest' \
&& perl -MCPAN -e 'install Config::FromHash' \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/*
USER lstu
ENTRYPOINT ["/bin/sh", "/home/lstu/docker/entrypoint.sh"]
\ No newline at end of file
......@@ -12,6 +12,8 @@ Lstu is licensed under the terms of the WTFPL. See the LICENSE file.
Please, see the [wiki](https://framagit.org/luc/lstu/wikis/home).
Or you can see [usage with Docker](https://framagit.org/luc/lstu/wikis/usage-with-docker).
## How many URLs can it handle ?
By default, there are 8 361 453 672 available combinations.
......
version: '3.3'
services:
app_dev:
build: .
ports:
- 8080:8080
volumes:
- .:/home/lstu
command: dev
mariadb_dev:
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: lstu
postgres_dev:
image: postgres:10.3-alpine
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: lstu
POSTGRES_DB: lstu
memcached:
image: memcached:1.5-alpine
adminer:
image: dehy/adminer
ports:
- 8081:80
\ No newline at end of file
version: '3.3'
services:
app:
build: .
ports:
- 8080:8080
volumes:
- ./lstu.conf:/home/lstu/lstu.conf:ro
db:
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: lstu
cache:
image: memcached:1.5-alpine
minion:
build: .
command: minion
volumes:
- ./lstu.conf:/home/lstu/lstu.conf:ro
minion_db:
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: lstu_minion
\ No newline at end of file
version: '3.3'
services:
app:
image: aquinum/lstu
configs:
- source: lstu.conf
target: /home/lstu/lstu.conf
uid: '1000'
gid: '1000'
mode: 0440
deploy:
replicas: 1
db:
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: <changeme>
MYSQL_DATABASE: lstu
cache:
image: memcached:1.5-alpine
minion:
image: aquinum/lstu
command: minion
configs:
- source: lstu.conf
target: /home/lstu/lstu.conf
uid: '1000'
gid: '1000'
mode: 0440
minion_db:
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: <changeme>
MYSQL_DATABASE: lstu_minion
configs:
lstu.conf:
file: ./lstu.conf
\ No newline at end of file
#!/bin/sh
set -eu
cd ~lstu
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 " apk --update add vim build-base perl-utils perl-dev make sudo zlib-dev libpng-dev postgresql-dev mariadb-dev"
tail -f /dev/null
exit 0
fi
# If MySQL/PostgreSQL, wait for database to be up
DB_TYPE=$(perl utilities/read_conf.pl dbtype)
DB_HOST=
DB_PORT=
if [ "$DB_TYPE" == "mysql" ]
then
DB_HOST=$(perl utilities/read_conf.pl mysqldb/host db)
DB_PORT=$(perl utilities/read_conf.pl mysqldb/port 3306)
fi
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/lstu
\ No newline at end of file
#!/bin/bash
# https://medium.com/microscaling-systems/labelling-automated-builds-on-docker-hub-f3d073fb8e1#.yldbwesu7
if [ -z "${IMAGE_NAME}" ]; then
echo ! "IMAGE_NAME" variable missing.
echo eg. IMAGE_NAME="aquinum/lstu:local" sh $0
exit 1
fi
function evil_git_dirty {
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "-dirty"
}
function last_tag {
git describe --abbrev=0
}
function version_number_plus {
[[ $(git rev-list --count ${1}..HEAD) -gt 0 ]] && echo "+"
}
VERSION=$(last_tag)
VERSION=${VERSION}$(version_number_plus ${VERSION})
VCS_REF=$(git rev-parse --short HEAD)$(evil_git_dirty)
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
docker build --build-arg VCS_REF=${VCS_REF} \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg VERSION=${VERSION} \
-t $IMAGE_NAME .
#!/usr/bin/env perl
# read_conf.pl - Outputs lstu's config value for given keypath
use strict;
use warnings;
use FindBin;
use Cwd qw(realpath);
use Config::FromHash;
sub print_help {
print <<END;
Usage:
$0 [-h] KEYPATH [DEFAULT] -- reads the lstu.conf file and outputs value at KEYPATH, or prints DEFAULT value
where:
-h prints this help message and exit
KEYPATH refers to the path in the hash, slash-separated (ie. mysqldb/host)
DEFAULT if keypath is undefined, return this value (ie. localhost)
END
return;
}
if (defined $ARGV[0] and $ARGV[0] eq "-h") {
print_help();
exit 0;
}
if (not defined $ARGV[0]) {
print_help();
exit 1;
}
my $filename = realpath("$FindBin::Bin/../lstu.conf");
if (! -r $filename) {
print STDERR "Error: unable to read config file \"$filename\"\n";
exit 1;
}
my $config = Config::FromHash->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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment