diff --git a/mastodon/Dockerfile b/mastodon/Dockerfile new file mode 100644 index 0000000..61e9057 --- /dev/null +++ b/mastodon/Dockerfile @@ -0,0 +1,72 @@ +FROM alpine:3.6 + +ARG VERSION=master +ARG REPOSITORY=tootsuite/mastodon + +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 + +RUN apk -U upgrade \ + && apk add \ + ca-certificates \ + ffmpeg \ + file \ + git \ + imagemagick \ + libpq \ + libressl \ + libxml2 \ + libxslt \ + nodejs-current-npm \ + nodejs-current \ + protobuf \ + ruby \ + ruby-bigdecimal \ + ruby-io-console \ + ruby-irb \ + ruby-json \ + s6 \ + su-exec \ + && apk add -t build-dependencies \ + build-base \ + libffi-dev \ + libxml2-dev \ + libxslt-dev \ + postgresql-dev \ + protobuf-dev \ + python \ + ruby-dev \ + ruby-rdoc \ + tar \ + && update-ca-certificates \ + && wget -qO- https://github.com/${REPOSITORY}/archive/${VERSION}.tar.gz | tar xz --strip 1 \ + && gem install bundler \ + && bundle install --deployment --clean --no-cache --without test development \ + && npm install -g npm@3 && npm install -g yarn \ + && yarn --ignore-optional --pure-lockfile \ + && SECRET_KEY_BASE=$(rake secret) rake assets:precompile \ + && npm -g cache clean && yarn cache clean \ + && mv public/assets /tmp/assets && mv public/packs /tmp/packs \ + && apk del build-dependencies \ + && rm -rf /tmp/* /var/cache/apk/* + +COPY rootfs / + +RUN chmod +x /usr/local/bin/* /etc/s6.d/*/* /etc/s6.d/.s6-svscan/* + +VOLUME /mastodon/public/system /mastodon/public/assets /mastodon/public/packs + +EXPOSE 3000 4000 + +LABEL maintainer="Wonderfall " \ + description="A GNU Social-compatible microblogging server" + +ENTRYPOINT ["/usr/local/bin/run"] +CMD ["/bin/s6-svscan", "/etc/s6.d"] diff --git a/mastodon/rootfs/etc/s6.d/.s6-svscan/finish b/mastodon/rootfs/etc/s6.d/.s6-svscan/finish new file mode 100644 index 0000000..039e4d0 --- /dev/null +++ b/mastodon/rootfs/etc/s6.d/.s6-svscan/finish @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/mastodon/rootfs/etc/s6.d/sidekiq/run b/mastodon/rootfs/etc/s6.d/sidekiq/run new file mode 100644 index 0000000..e075fbd --- /dev/null +++ b/mastodon/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 diff --git a/mastodon/rootfs/etc/s6.d/streaming/run b/mastodon/rootfs/etc/s6.d/streaming/run new file mode 100644 index 0000000..6e4c24f --- /dev/null +++ b/mastodon/rootfs/etc/s6.d/streaming/run @@ -0,0 +1,3 @@ +#!/bin/sh +cd /mastodon +exec npm run start diff --git a/mastodon/rootfs/etc/s6.d/web/run b/mastodon/rootfs/etc/s6.d/web/run new file mode 100644 index 0000000..d9ac3f2 --- /dev/null +++ b/mastodon/rootfs/etc/s6.d/web/run @@ -0,0 +1,3 @@ +#!/bin/sh +cd /mastodon +exec bundle exec rails s -p 3000 -b '0.0.0.0' diff --git a/mastodon/rootfs/usr/local/bin/run b/mastodon/rootfs/usr/local/bin/run new file mode 100644 index 0000000..f9f585f --- /dev/null +++ b/mastodon/rootfs/usr/local/bin/run @@ -0,0 +1,48 @@ +#!/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 +--------------------------------------------- +User ID : ${UID} +Group ID : ${GID} +--------------------------------------------- +" + +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 "Moving assets to volumes..." +mv /tmp/assets/* public/assets &>/dev/null +mv /tmp/packs/* public/packs &>/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 rake db:migrate +fi + +echo "Executing process..." +if [ '$@' == '' ]; then + exec su-exec mastodon:mastodon /bin/s6-svscan /etc/s6.d +else + exec su-exec mastodon:mastodon "$@" +fi