might work now

This commit is contained in:
Jeffrey Paul 2019-12-09 01:15:23 -08:00
parent c7b081f5b9
commit 72a9dc7d78
11 changed files with 159 additions and 20 deletions

View File

@ -11,6 +11,12 @@ ENV \
NODE_ENV=production \ NODE_ENV=production \
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/mastodon/app/bin PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/mastodon/app/bin
ARG UID=991
ARG GID=991
# mastodon v3.0.1
ARG REPO_URL=https://github.com/tootsuite/mastodon.git
ARG REPO_REV=c4118ba71ba31e408c02d289e111326ccc6f6aa2
# install os prereq stuff to image # install os prereq stuff to image
ADD prereqs.sh /tmp/prereqs.sh ADD prereqs.sh /tmp/prereqs.sh
@ -25,7 +31,13 @@ RUN chpst -u mastodon:mastodon bash /tmp/install.sh
ADD ./rootfs / ADD ./rootfs /
RUN chmod +x /usr/local/bin/* /etc/service/*/run RUN chmod +x /etc/service/postfix/run
RUN chmod +x /etc/service/redis/run
RUN chmod +x /etc/service/postgres/run
RUN chmod +x /etc/service/startup/run
RUN chmod +x /etc/service/sidekiq/run
RUN chmod +x /etc/service/web/run
RUN chmod +x /etc/service/streaming/run
VOLUME /state VOLUME /state

View File

@ -6,4 +6,5 @@ build:
docker build -t $(NAME) . docker build -t $(NAME) .
run: run:
docker run -ti $(NAME) -docker rm -f mastodon
docker run --env WEB_DOMAIN="test123.example.com" --hostname mastodon --name mastodon -ti $(NAME)

View File

@ -14,10 +14,9 @@ rbenv global 2.6.5
gem update --system gem update --system
gem install bundler --no-document gem install bundler --no-document
git clone https://github.com/tootsuite/mastodon.git /mastodon/app git clone $REPO_URL /mastodon/app
cd /mastodon/app cd /mastodon/app
# v3.0.1: git checkout $REPO_REV
git checkout c4118ba71ba31e408c02d289e111326ccc6f6aa2
bundle config build.nokogiri --use-system-libraries bundle config build.nokogiri --use-system-libraries
bundle install \ bundle install \

View File

@ -50,16 +50,19 @@ apt install -y \
libxml2-dev \ libxml2-dev \
libxslt1-dev \ libxslt1-dev \
libyaml-dev \ libyaml-dev \
mailutils \
nginx \ nginx \
nodejs \ nodejs \
pkg-config \ pkg-config \
postfix \
postgresql \ postgresql \
postgresql-contrib \ postgresql-contrib \
protobuf-compiler \ protobuf-compiler \
redis-server \ redis-server \
redis-tools \ redis-tools \
rsync \
yarn \ yarn \
zlib1g-dev zlib1g-dev
addgroup --gid 991 mastodon addgroup --gid $GID mastodon
useradd --uid 991 --gid 991 -m -d /mastodon mastodon useradd --uid $UID --gid $GID --shell /bin/bash -m -d /mastodon mastodon

View File

@ -1,5 +1,70 @@
#!/bin/bash #!/bin/bash
POSTFIX='/usr/sbin/postfix'
MONITOR_INTERVAL=10 # seconds
exec 2>&1
if [[ ! -d /state/envdir ]]; then
mkdir -p /state/envdir
chown mastodon:mastodon /state/envdir
fi
if [[ ! -e /state/envdir/WEB_DOMAIN ]]; then
if [[ -n "$WEB_DOMAIN" ]]; then
echo "$WEB_DOMAIN" > /state/envdir/WEB_DOMAIN
else
hostname --fqdn > /state/envdir/WEB_DOMAIN
fi
chown mastodon:mastodon /state/envdir/*
fi
cat /etc/postfix/main.cf | grep -v '^myhostname' > /etc/postfix/main.new
rm /etc/postfix/main.cf
echo "myhostname = $(cat /state/envdir/WEB_DOMAIN)" >> /etc/postfix/main.cf
echo "myorigin = $(cat /state/envdir/WEB_DOMAIN)" >> /etc/postfix/main.cf
cat /etc/postfix/main.new >> /etc/postfix/main.cf
rm /etc/postfix/main.new
running() {
pkill -0 master
}
start() {
echo "postfix starting..." echo "postfix starting..."
/etc/init.d/postfix start
}
exec /usr/lib/postfix/master stop() {
if running; then
echo Stopping
/etc/init.d/postfix stop
fi
}
reload() {
echo Reloading
/etc/init.d/postfix reload
}
check() {
echo Checking
"$POSTFIX" check
}
status() {
"$POSTFIX" status
}
trap 'echo INT; stop; exit' INT
trap 'echo QUIT; stop; exit' QUIT
trap 'echo TERM; stop; exit' TERM
trap 'echo STOP; stop' STOP
trap 'echo HUP; reload' HUP
trap 'echo USR1; check' USR1
trap 'echo USR2; status' USR2
while :; do
running || start
sleep $MONITOR_INTERVAL
done

View File

@ -2,7 +2,28 @@
echo "postgres starting..." echo "postgres starting..."
mkdir -p /state/db chown mastodon:mastodon /var/run/postgresql
chown mastodon:mastodon /state/db chown -R mastodon:mastodon /etc/postgresql
exec chpst -u mastodon:mastodon /usr/lib/postgresql/bin/postmaster \
-D /state/db 2>&1 echo "local all all peer" > /etc/postgresql/10/main/pg_hba.conf
echo "local all mastodon peer" >> /etc/postgresql/10/main/pg_hba.conf
echo "local all root peer" >> /etc/postgresql/10/main/pg_hba.conf
echo "host all all 127.0.0.0/8 trust" >> /etc/postgresql/10/main/pg_hba.conf
if [[ ! -d /state/db ]]; then
mkdir -p /state/db/data
rsync -a /var/lib/postgresql/10/main/ /state/db/data/
cp -a /etc/postgresql/10/main/* /state/db/
grep -v '^data_directory' /state/db/postgresql.conf |
grep -v "^ssl" |
grep -v "^stats_temp_directory" > /state/db/postgresql.new
echo "data_directory = '/state/db/data'" >> /state/db/postgresql.new
echo "stats_temp_directory = '/tmp'" >> /state/db/postgresql.new
mv /state/db/postgresql.new /state/db/postgresql.conf
chown -R mastodon:mastodon /state/db
chmod go-rwx /state/db/data
fi
exec \
chpst -u mastodon:mastodon \
/usr/lib/postgresql/10/bin/postmaster -D /state/db 2>&1

View File

@ -2,4 +2,11 @@
mkdir -p /state/redis mkdir -p /state/redis
chown mastodon:mastodon /state/redis chown mastodon:mastodon /state/redis
exec chpst -u mastodon:mastodon /usr/bin/redis-server /etc/redis/redis.conf exec chpst -u mastodon:mastodon /usr/bin/redis-server - <<EOF
daemonize no
dir /state/redis
save 900 1
save 300 10
save 60 10000
EOF

View File

@ -11,4 +11,4 @@ cd /mastodon/app
exec \ exec \
envdir /state/envdir \ envdir /state/envdir \
chpst -u mastodon:mastodon \ chpst -u mastodon:mastodon \
bash -c "bundle exec sidekiq -c $SIDEKIQ_WORKERS -q default -q push -q pull -q mailers" bash -i -c "bundle exec sidekiq -c $SIDEKIQ_WORKERS -q default -q push -q pull -q mailers"

View File

@ -5,18 +5,43 @@ echo "mastodon-startup starting up..."
if [[ ! -d /state/envdir ]]; then if [[ ! -d /state/envdir ]]; then
mkdir -p /state/envdir mkdir -p /state/envdir
chown mastodon:mastodon /state/envdir
fi fi
if [[ ! -e /state/envdir/HOME ]]; then if [[ ! -e /state/envdir/HOME ]]; then
echo "/mastodon" > /state/envdir/HOME echo "/mastodon" > /state/envdir/HOME
fi fi
if [[ ! -e /state/envdir/RAILS_ENV ]]; then
echo "production" > /state/envdir/RAILS_ENV
fi
chown mastodon:mastodon /state/envdir /state/envdir/*
cd /mastodon/app cd /mastodon/app
if [ "$RUN_DB_MIGRATIONS" == "true" ]; then if [[ ! -e /state/envdir/OTP_SECRET ]]; then
envdir /state/envdir \
chpst -u mastodon:mastodon \
bash -i -c "bundle exec rake secret > /state/envdir/OTP_SECRET"
fi
if [[ ! -e /state/envdir/SECRET_KEY_BASE ]]; then
envdir /state/envdir \
chpst -u mastodon:mastodon \
bash -i -c "bundle exec rake secret > /state/envdir/SECRET_KEY_BASE"
fi
echo "
create database mastodon_production;
create user mastodon createdb;
grant all privileges on database mastodon_production to mastodon;
" | chpst -u postgres:postgres psql
if [[ -n "$RUN_DB_MIGRATIONS" ]]; then
echo "Running database migrations..." echo "Running database migrations..."
envdir /state/envdir chpst -u mastodon:mastodon bash -c "bundle exec rake db:migrate" envdir /state/envdir \
chpst -u mastodon:mastodon \
bash -i -c "bundle exec rake db:migrate"
fi fi
rm /state/.starting rm /state/.starting

View File

@ -8,4 +8,7 @@ done
echo "streaming starting..." echo "streaming starting..."
cd /mastodon/app cd /mastodon/app
exec envdir /state/envdir chpst -u mastodon:mastodon bash -c "npm run start" exec \
envdir /state/envdir \
chpst -u mastodon:mastodon \
bash -i -c "npm run start"

View File

@ -8,4 +8,7 @@ done
echo "web starting..." echo "web starting..."
cd /mastodon/app cd /mastodon/app
exec envdir /state/envdir chpst -u mastodon:mastodon bash -c "bundle exec puma -C config/puma.rb" exec \
envdir /state/envdir \
chpst -u mastodon:mastodon \
bash -i -c "bundle exec puma -C config/puma.rb"