diff --git a/Dockerfile b/Dockerfile index d17131e..70034c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,15 @@ FROM phusion/baseimage:0.11 # Use baseimage-docker's init system. CMD ["/sbin/my_init"] +ENV \ + 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/app/bin + + # install os prereq stuff to image ADD prereqs.sh /tmp/prereqs.sh RUN bash /tmp/prereqs.sh @@ -10,6 +19,8 @@ RUN bash /tmp/prereqs.sh # install mastodon: ADD install.sh /tmp/install.sh +WORKDIR /mastodon +ENV HOME /mastodon RUN chpst -u mastodon:mastodon bash /tmp/install.sh ADD ./rootfs / @@ -19,3 +30,6 @@ RUN chmod +x /usr/local/bin/* /etc/service/*/run VOLUME /state EXPOSE 3000 4000 + +LABEL maintainer="Jeffrey Paul " \ + description="Your self-hosted, globally interconnected microblogging community" diff --git a/Makefile b/Makefile index 0652912..cb5ea2a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,9 @@ +NAME := sneak/mastodon + default: build build: - docker build -t sneak/mastodon . + docker build -t $(NAME) . + +run: + docker run -ti $(NAME) diff --git a/install.sh b/install.sh index c3dde69..2386bdd 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,5 @@ #!/bin/bash -export HOME="/mastodon" export PATH="$HOME/.rbenv/bin:$PATH" export RUBY_CONFIGURE_OPTS="--with-jemalloc" @@ -10,8 +9,8 @@ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bashrc echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build eval "$(rbenv init -)" -rbenv install 2.6.1 -rbenv global 2.6.1 +rbenv install 2.6.5 +rbenv global 2.6.5 gem update --system gem install bundler --no-document @@ -20,7 +19,12 @@ cd /mastodon/app # v3.0.1: git checkout c4118ba71ba31e408c02d289e111326ccc6f6aa2 +bundle config build.nokogiri --use-system-libraries bundle install \ -j$(getconf _NPROCESSORS_ONLN) \ --deployment --without development test -yarn install --pure-lockfile +yarn install --pure-lockfile --ignore-engines + +OTP_SECRET=precompile_placeholder \ +SECRET_KEY_BASE=precompile_placeholder \ +bundle exec rails assets:precompile diff --git a/rootfs/etc/service/postfix/run b/rootfs/etc/service/postfix/run new file mode 100644 index 0000000..fa28a60 --- /dev/null +++ b/rootfs/etc/service/postfix/run @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "postfix starting..." + +exec /usr/lib/postfix/master diff --git a/rootfs/etc/service/postgres/run b/rootfs/etc/service/postgres/run index e69de29..6854ae0 100644 --- a/rootfs/etc/service/postgres/run +++ b/rootfs/etc/service/postgres/run @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "postgres starting..." + +mkdir -p /state/db +chown mastodon:mastodon /state/db +exec chpst -u mastodon:mastodon /usr/lib/postgresql/bin/postmaster \ + -D /state/db 2>&1 diff --git a/rootfs/etc/service/redis/run b/rootfs/etc/service/redis/run index e69de29..308099c 100644 --- a/rootfs/etc/service/redis/run +++ b/rootfs/etc/service/redis/run @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir -p /state/redis +chown mastodon:mastodon /state/redis +exec chpst -u mastodon:mastodon /usr/bin/redis-server /etc/redis/redis.conf diff --git a/rootfs/etc/service/sidekiq/run b/rootfs/etc/service/sidekiq/run index e69de29..b1dbb6a 100644 --- a/rootfs/etc/service/sidekiq/run +++ b/rootfs/etc/service/sidekiq/run @@ -0,0 +1,14 @@ +#!/bin/bash +sleep 2 + +while [[ -e /state/.starting ]]; do + sleep 1 +done + +echo "sidekiq starting..." + +cd /mastodon/app +exec \ + envdir /state/envdir \ + chpst -u mastodon:mastodon \ + bash -c "bundle exec sidekiq -c $SIDEKIQ_WORKERS -q default -q push -q pull -q mailers" diff --git a/rootfs/etc/service/startup/run b/rootfs/etc/service/startup/run new file mode 100644 index 0000000..f050beb --- /dev/null +++ b/rootfs/etc/service/startup/run @@ -0,0 +1,25 @@ +#!/bin/bash + +touch /state/.starting +echo "mastodon-startup starting up..." + +if [[ ! -d /state/envdir ]]; then + mkdir -p /state/envdir + chown mastodon:mastodon /state/envdir +fi + +if [[ ! -e /state/envdir/HOME ]]; then + echo "/mastodon" > /state/envdir/HOME +fi + +cd /mastodon/app + +if [ "$RUN_DB_MIGRATIONS" == "true" ]; then + echo "Running database migrations..." + envdir /state/envdir chpst -u mastodon:mastodon bash -c "bundle exec rake db:migrate" +fi + +rm /state/.starting +while true ; do + sleep 86400 +done diff --git a/rootfs/etc/service/streaming/run b/rootfs/etc/service/streaming/run index e69de29..44f5d61 100644 --- a/rootfs/etc/service/streaming/run +++ b/rootfs/etc/service/streaming/run @@ -0,0 +1,11 @@ +#!/bin/bash +sleep 2 + +while [[ -e /state/.starting ]]; do + sleep 1 +done + +echo "streaming starting..." + +cd /mastodon/app +exec envdir /state/envdir chpst -u mastodon:mastodon bash -c "npm run start" diff --git a/rootfs/etc/service/web/run b/rootfs/etc/service/web/run index e69de29..6a92d54 100644 --- a/rootfs/etc/service/web/run +++ b/rootfs/etc/service/web/run @@ -0,0 +1,11 @@ +#!/bin/bash +sleep 2 + +while [[ -e /state/.starting ]]; do + sleep 1 +done + +echo "web starting..." + +cd /mastodon/app +exec envdir /state/envdir chpst -u mastodon:mastodon bash -c "bundle exec puma -C config/puma.rb"