summaryrefslogtreecommitdiffstats
path: root/docker
diff options
context:
space:
mode:
Diffstat (limited to 'docker')
-rw-r--r--docker/Dockerfile32
-rw-r--r--docker/Dockerfile.postgres12
-rwxr-xr-xdocker/entrypoint.postgres.sh31
-rwxr-xr-xdocker/init-invidious-db.sh16
4 files changed, 29 insertions, 62 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 11ab6ed2..96f844fe 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,27 +1,20 @@
-FROM alpine:edge AS builder
-RUN apk add --no-cache crystal shards libc-dev \
- yaml-dev libxml2-dev sqlite-dev zlib-dev openssl-dev \
- sqlite-static zlib-static openssl-libs-static
+FROM crystallang/crystal:0.35.1-alpine AS builder
+RUN apk add --no-cache curl sqlite-static
WORKDIR /invidious
COPY ./shard.yml ./shard.yml
-RUN shards update && shards install
-RUN apk add --no-cache curl && \
- curl -Lo /etc/apk/keys/omarroth.rsa.pub https://github.com/omarroth/boringssl-alpine/releases/download/1.1.0-r0/omarroth.rsa.pub && \
- curl -Lo boringssl-dev.apk https://github.com/omarroth/boringssl-alpine/releases/download/1.1.0-r0/boringssl-dev-1.1.0-r0.apk && \
- curl -Lo lsquic.apk https://github.com/omarroth/lsquic-alpine/releases/download/2.6.3-r0/lsquic-2.6.3-r0.apk && \
- tar -xf boringssl-dev.apk && \
- tar -xf lsquic.apk
-RUN mv ./usr/lib/libcrypto.a ./lib/lsquic/src/lsquic/ext/libcrypto.a && \
- mv ./usr/lib/libssl.a ./lib/lsquic/src/lsquic/ext/libssl.a && \
- mv ./usr/lib/liblsquic.a ./lib/lsquic/src/lsquic/ext/liblsquic.a
+RUN shards update && shards install && \
+ # TODO: Document build instructions
+ # See https://github.com/omarroth/boringssl-alpine/blob/master/APKBUILD,
+ # https://github.com/omarroth/lsquic-alpine/blob/master/APKBUILD,
+ # https://github.com/omarroth/lsquic.cr/issues/1#issuecomment-631610081
+ # for details building static lib
+ curl -Lo ./lib/lsquic/src/lsquic/ext/liblsquic.a https://omar.yt/lsquic/liblsquic-v2.18.1.a
COPY ./src/ ./src/
# TODO: .git folder is required for building – this is destructive.
# See definition of CURRENT_BRANCH, CURRENT_COMMIT and CURRENT_VERSION.
COPY ./.git/ ./.git/
RUN crystal build ./src/invidious.cr \
- --static --warnings all --error-on-warnings \
-# TODO: Remove next line, see https://github.com/crystal-lang/crystal/issues/7946
- -Dmusl \
+ --static --warnings all \
--link-flags "-lxml2 -llzma"
FROM alpine:latest
@@ -30,10 +23,11 @@ WORKDIR /invidious
RUN addgroup -g 1000 -S invidious && \
adduser -u 1000 -S invidious -G invidious
COPY ./assets/ ./assets/
-COPY ./config/config.yml ./config/config.yml
+COPY --chown=invidious ./config/config.yml ./config/config.yml
+RUN sed -i 's/host: \(127.0.0.1\|localhost\)/host: postgres/' config/config.yml
COPY ./config/sql/ ./config/sql/
COPY ./locales/ ./locales/
-RUN sed -i 's/host: \(127.0.0.1\|localhost\)/host: postgres/' config/config.yml
COPY --from=builder /invidious/invidious .
+
USER invidious
CMD [ "/invidious/invidious" ]
diff --git a/docker/Dockerfile.postgres b/docker/Dockerfile.postgres
deleted file mode 100644
index 3b25b802..00000000
--- a/docker/Dockerfile.postgres
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM postgres:10
-
-ENV POSTGRES_USER postgres
-# Do not require a PostgreSQL superuser password.
-# See https://github.com/docker-library/postgres/issues/681.
-ENV POSTGRES_HOST_AUTH_METHOD trust
-
-ADD ./config/sql /config/sql
-ADD ./docker/entrypoint.postgres.sh /entrypoint.sh
-
-ENTRYPOINT [ "/entrypoint.sh" ]
-CMD [ "postgres" ]
diff --git a/docker/entrypoint.postgres.sh b/docker/entrypoint.postgres.sh
deleted file mode 100755
index 1588c56c..00000000
--- a/docker/entrypoint.postgres.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env bash
-
-CMD="$@"
-if [ ! -f /var/lib/postgresql/data/setupFinished ]; then
- echo "### first run - setting up invidious database"
- /usr/local/bin/docker-entrypoint.sh postgres &
- sleep 10
- until runuser -l postgres -c 'pg_isready' 2>/dev/null; do
- >&2 echo "### Postgres is unavailable - waiting"
- sleep 5
- done
- >&2 echo "### importing table schemas"
- su postgres -c 'createdb invidious'
- su postgres -c 'psql -c "CREATE USER kemal WITH PASSWORD '"'kemal'"'"'
- su postgres -c 'psql invidious kemal < config/sql/channels.sql'
- su postgres -c 'psql invidious kemal < config/sql/videos.sql'
- su postgres -c 'psql invidious kemal < config/sql/channel_videos.sql'
- su postgres -c 'psql invidious kemal < config/sql/users.sql'
- su postgres -c 'psql invidious kemal < config/sql/session_ids.sql'
- su postgres -c 'psql invidious kemal < config/sql/nonces.sql'
- su postgres -c 'psql invidious kemal < config/sql/annotations.sql'
- su postgres -c 'psql invidious kemal < config/sql/privacy.sql'
- su postgres -c 'psql invidious kemal < config/sql/playlists.sql'
- su postgres -c 'psql invidious kemal < config/sql/playlist_videos.sql'
- touch /var/lib/postgresql/data/setupFinished
- echo "### invidious database setup finished"
- exit
-fi
-
-echo "running postgres /usr/local/bin/docker-entrypoint.sh $CMD"
-exec /usr/local/bin/docker-entrypoint.sh $CMD
diff --git a/docker/init-invidious-db.sh b/docker/init-invidious-db.sh
new file mode 100755
index 00000000..3808e673
--- /dev/null
+++ b/docker/init-invidious-db.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+set -eou pipefail
+
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
+ CREATE USER postgres;
+EOSQL
+
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql