Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Last active December 31, 2020 00:51
Show Gist options
  • Save takaheraw/e8e1ecc3dd97dc06e591b6afdc28be43 to your computer and use it in GitHub Desktop.
Save takaheraw/e8e1ecc3dd97dc06e591b6afdc28be43 to your computer and use it in GitHub Desktop.
Mastodon development

M1 Docker Mastodon VSCode

Docker Install

Mastodon

  • checkout
$ ghq get [email protected]:tootsuite/mastodon.git
  • cp -rp .env.production.sample .env.development
# Federation
# ----------
# This identifies your server and cannot be changed safely later
# ----------
LOCAL_DOMAIN=localhost:3000
LOCAL_HTTPS=false

# Redis
# -----
REDIS_HOST=redis
REDIS_PORT=6379

# PostgreSQL
# ----------
DB_HOST=db
DB_USER=postgres
DB_NAME=mastodon_development
DB_PASS=postgres
DB_PORT=5432
  • Dockerfile
% git diff Dockerfile
diff --git a/Dockerfile b/Dockerfile
index 95d45bab4..05b24cc82 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -71,8 +71,6 @@ RUN npm install -g yarn && \
 COPY Gemfile* package.json yarn.lock /opt/mastodon/

 RUN cd /opt/mastodon && \
-  bundle config set deployment 'true' && \
-  bundle config set without 'development test' && \
        bundle install -j$(nproc) && \
        yarn install --pure-lockfile

@@ -123,8 +121,8 @@ COPY --chown=mastodon:mastodon . /opt/mastodon
 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon

 # Run mastodon services in prod mode
-ENV RAILS_ENV="production"
-ENV NODE_ENV="production"
+ENV RAILS_ENV="development"
+ENV NODE_ENV="development"
  • Gemfile
% git diff Gemfile
diff --git a/Gemfile b/Gemfile
index cef134f27..58a1eb443 100644
--- a/Gemfile
+++ b/Gemfile
@@ -149,6 +149,8 @@ group :development do
   gem 'capistrano-yarn', '~> 2.0'

   gem 'stackprof'
+
+  gem 'foreman'
 end
  • docker-compose.yml
% git diff docker-compose.yml
diff --git a/docker-compose.yml b/docker-compose.yml
index 52eea7a74..2213be665 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -11,6 +11,8 @@ services:
       test: ["CMD", "pg_isready", "-U", "postgres"]
     volumes:
       - ./postgres:/var/lib/postgresql/data
+    environment:
+      POSTGRES_PASSWORD: 'postgres'

   redis:
     restart: always
@@ -45,8 +47,8 @@ services:
     build: .
     image: tootsuite/mastodon
     restart: always
-    env_file: .env.production
-    command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
+    env_file: .env.development
+    command: bundle exec foreman start -f Procfile.dev
     networks:
       - external_network
       - internal_network
@@ -60,12 +62,14 @@ services:
 #      - es
     volumes:
       - ./public/system:/mastodon/public/system
+    tty: true
+    stdin_open: true

   streaming:
     build: .
     image: tootsuite/mastodon
     restart: always
-    env_file: .env.production
+    env_file: .env.development
     command: node ./streaming
     networks:
       - external_network
@@ -82,7 +86,7 @@ services:
     build: .
     image: tootsuite/mastodon
     restart: always
-    env_file: .env.production
+    env_file: .env.development
     command: bundle exec sidekiq
     depends_on:
       - db
  • volumes
% mkdir postgres redis
  • docker-compose build
% docker-compose build
  • db:setup
% docker-compose run --rm web rails db:setup
  • assets:precompile
% docker-compose run --rm web rails assets:precompile
  • docker-compose up
% docker-compose up

localhost

VSCode

  • Remote Container

vscode1 vscode2 vscode3 vscode4

  • .devcontainer/devcontainer.json
{
	// Update the 'dockerComposeFile' list if you have more compose files or use different names.
	// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
	"dockerComposeFile": [
		"../docker-compose.yml",
	],

	// Set *default* container specific settings.json values on container create.
	"settings": {
		"terminal.integrated.shell.linux": null
	},

	// Add the IDs of extensions you want installed when the container is created.
	"extensions": [
		"rebornix.ruby",
	],
}

vscode5

  • Debug
% docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS                   PORTS                                NAMES
c07f76a6b726   tootsuite/mastodon    "/tini -- bundle exe…"   2 minutes ago    Up 2 minutes (healthy)   127.0.0.1:3000->3000/tcp, 4000/tcp   mastodon_web_1

% docker attach c07f76a6b726
22:08:56 web.1     | From: /opt/mastodon/app/controllers/about_controller.rb:18 AboutController#show:
22:08:56 web.1     |
22:08:56 web.1     |     16: def show
22:08:56 web.1     |     17:   binding.pry
22:08:56 web.1     |  => 18: end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment