commit a8e943364bf0260d0349f87c8e6ff52c0b4f8142 Author: Wonderfall Date: Tue Jun 12 16:54:14 2018 +0200 add files diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e907358 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,85 @@ +FROM ruby:2.4.4-alpine3.7 + +ARG VERSION=v2.4.1 +ARG REPOSITORY=tootsuite/mastodon +ARG LIBICONV_VERSION=1.15 + +ENV UID=991 GID=991 \ + RUN_DB_MIGRATIONS=true \ + SIDEKIQ_WORKERS=5 \ + RAILS_SERVE_STATIC_FILES=true \ + RAILS_ENV=production \ + NODE_ENV=production \ + PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/mastodon/bin + +WORKDIR /mastodon + +# Install dependencies +RUN apk -U upgrade \ + && apk add \ + ca-certificates \ + ffmpeg \ + file \ + git \ + icu-libs \ + imagemagick \ + libidn \ + libpq \ + libressl \ + nodejs-npm \ + nodejs \ + protobuf \ + s6 \ + su-exec \ + tzdata \ + +# Install build dependencies + && apk add -t build-dependencies \ + build-base \ + icu-dev \ + libidn-dev \ + libtool \ + postgresql-dev \ + protobuf-dev \ + python \ + tar \ + yarn \ + +# Update CA certificates + && update-ca-certificates \ + +# Install GNU Libiconv + && wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VERSION}.tar.gz -O /tmp/libiconv-${LIBICONV_VERSION}.tar.gz \ + && mkdir /tmp/src && tar xzf /tmp/libiconv-${LIBICONV_VERSION}.tar.gz -C /tmp/src \ + && cd /tmp/src/libiconv-${LIBICONV_VERSION} \ + && ./configure --prefix=/usr/local \ + && make -j$(getconf _NPROCESSORS_ONLN) && make install && libtool --finish /usr/local/lib \ + +# Install Mastodon + && cd /mastodon \ + && wget -qO- https://github.com/${REPOSITORY}/archive/${VERSION}.tar.gz | tar xz --strip 1 \ + && bundle config build.nokogiri --with-iconv-lib=/usr/local/lib --with-iconv-include=/usr/local/include \ + && bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --clean --no-cache --without test development \ + && yarn --ignore-optional --pure-lockfile \ + +# Precompile Mastodon assets + && SECRET_KEY_BASE=$(bundle exec rake secret) OTP_SECRET=$(bundle exec rake secret) SMTP_FROM_ADDRESS= bundle exec rake assets:precompile \ + +# Clean + && npm -g --force cache clean && yarn cache clean \ + && apk del build-dependencies \ + && rm -rf /var/cache/apk/* /tmp/src + +COPY rootfs / + +RUN chmod +x /usr/local/bin/* /etc/s6.d/*/* /etc/s6.d/.s6-svscan/* + +VOLUME /mastodon/public/system /mastodon/log + +EXPOSE 3000 4000 + +LABEL maintainer="Wonderfall " \ + description="Your self-hosted, globally interconnected microblogging community" + +ENTRYPOINT ["/usr/local/bin/run"] +CMD ["/bin/s6-svscan", "/etc/s6.d"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac48ade --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +## wonderfall/mastodon + +![Mastodon](https://github.com/tootsuite/mastodon/blob/master/app/javascript/images/mastodon-getting-started.png?raw=true) + +A GNU Social-compatible microblogging server : https://github.com/tootsuite/mastodon + +#### Why this image? +This image is not the official one. The main difference you can notice is that all processes (web, streaming, sidekiq) are running in a single container, thanks to s6 (a supervision suite). Therefore it's easier to deploy, but not recommended for scaling. + +#### Features +- Based on Alpine Linux. +- As lightweight as possible. +- All-in-one container (s6). +- Assets are precompiled. +- Database migrations can be run at startup. +- No root processes. + +#### Build-time variables +- **VERSION** : version of Mastodon, can be `v1.4.1` or `master`. *(default : latest version)* +- **REPOSITORY** : location of the code *(default : tootsuite/mastodon)* + +#### Environment variables you should change +- **UID** : mastodon user id *(default : 991)* +- **GID** : mastodon group id *(default : 991)* +- **RUN_DB_MIGRATIONS** : run `rake db:migrate` at startup *(default : true)* +- **SIDEKIQ_WORKERS** : number of Sidekiq workers *(default : 5)* +- Other environment variables : https://github.com/tootsuite/mastodon/blob/master/.env.production.sample + +#### Volumes +- **/mastodon/public/system** : shit like media attachments, avatars, etc. +- **/mastodon/public/assets** : Mastodon assets +- **/mastodon/public/packs** : Mastodon assets +- **/mastodon/log** : Mastodon logfiles (mount if you prefer to) + +#### Ports +- **3000** : Mastodon web +- **4000** : Mastodon streaming + +#### docker-compose sample + +``` +mastodon: + image: wonderfall/mastodon:stable + restart: always + container_name: mastodon + env_file: /home/docker/mastodon/.env.production + environment: + - WEB_CONCURRENCY=16 + - MAX_THREADS=20 + - SIDEKIQ_WORKERS=25 + - RUN_DB_MIGRATIONS=true + links: + - mastodon-pgb + - mastodon-redis + volumes: + - /home/docker/mastodon/public/system:/mastodon/public/system + - /home/docker/mastodon/public/assets:/mastodon/public/assets + - /home/docker/mastodon/public/packs:/mastodon/public/packs +``` + diff --git a/rootfs/etc/s6.d/.s6-svscan/finish b/rootfs/etc/s6.d/.s6-svscan/finish new file mode 100644 index 0000000..039e4d0 --- /dev/null +++ b/rootfs/etc/s6.d/.s6-svscan/finish @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/rootfs/etc/s6.d/sidekiq/run b/rootfs/etc/s6.d/sidekiq/run new file mode 100644 index 0000000..ff6aac6 --- /dev/null +++ b/rootfs/etc/s6.d/sidekiq/run @@ -0,0 +1,3 @@ +#!/bin/sh +cd /mastodon +exec bundle exec sidekiq -c $SIDEKIQ_WORKERS -q default -q push -q pull -q mailers > ./log/sidekiq.log 2>&1 diff --git a/rootfs/etc/s6.d/streaming/run b/rootfs/etc/s6.d/streaming/run new file mode 100644 index 0000000..372bc8a --- /dev/null +++ b/rootfs/etc/s6.d/streaming/run @@ -0,0 +1,3 @@ +#!/bin/sh +cd /mastodon +exec npm run start > ./log/streaming.log 2>&1 diff --git a/rootfs/etc/s6.d/web/run b/rootfs/etc/s6.d/web/run new file mode 100644 index 0000000..ec827bd --- /dev/null +++ b/rootfs/etc/s6.d/web/run @@ -0,0 +1,3 @@ +#!/bin/sh +cd /mastodon +exec bundle exec puma -C config/puma.rb > ./log/web.log 2>&1 diff --git a/rootfs/usr/local/bin/run b/rootfs/usr/local/bin/run new file mode 100644 index 0000000..8e4d2c5 --- /dev/null +++ b/rootfs/usr/local/bin/run @@ -0,0 +1,52 @@ +#!/bin/sh + +### 1. Adds local user (UID and GID are provided from environment variables). +### 2. Moves precompiled assets into them. +### 3. Updates permissions, except for ./public/system (should be chown on previous installations). +### NOTE : this can take a long time if overlay2 is the storage-driver (issue #3194). +### 4. If $RUN_DB_MIGRATIONS is set to true, runs the database migrations task. +### 5. Executes the command as that user. + +echo " +--------------------------------------------- + _____ _ _ + | |___ ___| |_ ___ _| |___ ___ + | | | | .'|_ -| _| . | . | . | | + |_|_|_|__,|___|_| |___|___|___|_|_| + +A GNU Social-compatible microblogging server + https://github.com/tootsuite/mastodon + 17j2g7vpgHhLuXhN4bueZFCvdxxieyRVWd +--------------------------------------------- +UID/GID settings +--------------------------------------------- +User ID : ${UID} +Group ID : ${GID} +--------------------------------------------- +Logs location +--------------------------------------------- +Sidekiq : /mastodon/log/sidekiq.log +Streaming : /mastodon/log/streaming.log +Web : /mastodon/log/web.log +--------------------------------------------- +" + +echo "Creating mastodon user..." +addgroup -g ${GID} mastodon &>/dev/null +adduser -h /mastodon -s /bin/sh -D -G mastodon -u ${UID} mastodon &>/dev/null + +echo "Updating permissions, this can take a while..." +find /mastodon -path /mastodon/public/system -prune -o -not -user mastodon -not -group mastodon -print0 | xargs -0 chown -f mastodon:mastodon +chown -R mastodon:mastodon /etc/s6.d + +if [ "$RUN_DB_MIGRATIONS" == "true" ]; then + echo "Running database migrations task..." + su-exec mastodon:mastodon bundle exec rake db:migrate +fi + +echo "Executing process(es)..." +if [ '$@' == '' ]; then + exec su-exec mastodon:mastodon /bin/s6-svscan /etc/s6.d +else + exec su-exec mastodon:mastodon "$@" +fi