add mastodon image

This commit is contained in:
Wonderfall 2017-06-13 21:47:33 +02:00
parent 2206edc9f4
commit 02a80f96bc
6 changed files with 131 additions and 0 deletions

72
mastodon/Dockerfile Normal file
View File

@ -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 <wonderfall@targaryen.house>" \
description="A GNU Social-compatible microblogging server"
ENTRYPOINT ["/usr/local/bin/run"]
CMD ["/bin/s6-svscan", "/etc/s6.d"]

View File

@ -0,0 +1,2 @@
#!/bin/sh
exit 0

View File

@ -0,0 +1,3 @@
#!/bin/sh
cd /mastodon
exec bundle exec sidekiq -c $SIDEKIQ_WORKERS -q default -q push -q pull -q mailers

View File

@ -0,0 +1,3 @@
#!/bin/sh
cd /mastodon
exec npm run start

View File

@ -0,0 +1,3 @@
#!/bin/sh
cd /mastodon
exec bundle exec rails s -p 3000 -b '0.0.0.0'

View File

@ -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