Skip to content

Instantly share code, notes, and snippets.

@mattintosh4
Last active May 14, 2017 15:52
Show Gist options
  • Save mattintosh4/913c2ec8adc5e34753d6b80ec7a5de7b to your computer and use it in GitHub Desktop.
Save mattintosh4/913c2ec8adc5e34753d6b80ec7a5de7b to your computer and use it in GitHub Desktop.
LXC-Docker-Mastodon
#!/bin/bash
set -e
set -x
trap_exit(){
sudo lxc-stop -n mastodon_x || :
sudo lxc-destroy -n mastodon_x
}
trap trap_exit EXIT
sudo lxc-create -n mastodon_x -t ubuntu -- -r xenial
sudo tee -a /var/lib/lxc/mastodon_x/config <<!
lxc.aa_profile = unconfined
lxc.cgroup.cpu.shares = 512
!
sudo lxc-start -n mastodon_x
sudo lxc-attach -n mastodon_x -- bash -ex <<\!
echo 'nameserver 8.8.8.8' >>/etc/resolvconf/resolv.conf.d/head
echo 'nameserver 8.8.4.4' >>/etc/resolvconf/resolv.conf.d/head
resolvconf -u
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
software-properties-common \
curl \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce
apt-get autoremove
curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-$(uname -s)-$(uname -m) >/usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
usermod -aG docker ubuntu
!
sudo lxc-stop -n mastodon_x
sudo lxc-copy -n mastodon_x -N mastodon_0
#!/bin/bash
set -e
set -x
git clone https://github.com/tootsuite/mastodon.git
tar cf - mastodon | gzip >mastodon.tar.gz
cd mastodon
git checkout -f remotes/origin/1.3-stable
sed -i -e "/^# /s// /" docker-compose.yml
cp .env.production.sample \
.env.production
docker-compose build
set -- $(docker-compose run --rm web rake secret) \
$(docker-compose run --rm web rake secret) \
$(docker-compose run --rm web rake secret)
sed -i -e "
/^LOCAL_DOMAIN=/ s/=.*/=127.0.0.1/
/^LOCAL_HTTPS=/ s/=.*/false/
/^PAPERCLIP_SECRET=/s/=.*/=$1/
/^SECRET_KEY_BASE=/ s/=.*/=$2/
/^OTP_SECRET=/ s/=.*/=$3/
" .env.production
docker-compose run --rm web rails db:migrate
docker-compose run --rm web rails assets:precompile
@mattintosh4
Copy link
Author

mattintosh4 commented May 14, 2017

LXC と Docker を使って Mastodon のインスタンスを作る

  • Ubuntu 16.04 LTS Xenial で検証しています。
  • 準備用コンテナの作成に失敗した場合、自動的に消します。(成功しても準備用コンテナは消えます)
  • SMTP の設定は含まれていません。アカウントは手動で認証する必要があります。
  • HTTPS ではなく HTTP です。

母艦の Ubuntu で lxc-docker-mastodon_1.sh を実行します。スクリプトエリア右上の「Raw」から最新のリビジョンの URL を使用してください。

bash <(curl -L https://gist.github.com/mattintosh4/913c2ec8adc5e34753d6b80ec7a5de7b/raw/e02d50deeecf11f784bfea1bc82d91d9376bbe92/lxc-docker-mastodon_1.sh)

ベースとなるコンテナ(mastodon_0)を試験用コンテナ(mastodon_1)としてコピーします。

sudo lxc-copy -n mastodon_0 -N mastodon_1

試験用コンテナを起動して IP アドレスを確認します。

sudo lxc-start -n mastodon_1
sudo lxc-ls --fancy

母艦から SSH で試験用コンテナに接続します。SSH のユーザ名/パスワードは ubuntu/ubuntu です。

ssh ubuntu@試験用コンテナのIPアドレス

試験用コンテナ内で lxc-docker-mastodon_2.sh を実行します。ここでも URL は最新のリビジョンのものを使用してください。

bash <(curl -L https://gist.github.com/mattintosh4/913c2ec8adc5e34753d6b80ec7a5de7b/raw/e02d50deeecf11f784bfea1bc82d91d9376bbe92/lxc-docker-mastodon_2.sh)

~/mastodon に Mastodon の環境が出来上がるので Docker コンテナを起動します。デーモンとして起動する場合は -d オプションを使用してください。

cd ~/mastodon
docker-compose up

少し待って http://試験用コンテナのIPアドレス:3000 にアクセスすれば Mastodon を始めることができます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment