Add SETUP instructions #19

Merged
Rin merged 18 commits from setup-instructions into main 2022-11-28 08:54:36 +00:00
9 changed files with 227 additions and 24 deletions

7
.env.development Normal file
View File

@ -0,0 +1,7 @@
LOCAL_DOMAIN=localhost
ALTERNATE_DOMAINS=mastodon.internal
DB_HOST=$(pwd)/data/postgres
DB_USER=mastodon
DB_NAME=mastodon_dev
REDIS_URL=unix://./data/redis/redis-dev.sock

View File

@ -3,3 +3,8 @@ NODE_ENV=tests
# Federation
LOCAL_DOMAIN=cb6e6126.ngrok.io
LOCAL_HTTPS=true
DB_HOST=$(pwd)/data/postgres
DB_USER=mastodon
DB_NAME=mastodon_dev
REDIS_URL=unix://./data/redis/redis-dev.sock

6
.gitignore vendored
View File

@ -4,6 +4,9 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore local dotenv overrides
.env.*.local
# Ignore bundler config and downloaded libraries.
/.bundle
/vendor/bundle
@ -12,6 +15,9 @@
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore local data directory
/data
# Ignore all logfiles and tempfiles.
.eslintcache
/log/*

View File

@ -1,6 +1,6 @@
# Contributing to Mastodon Glitch Edition #
# Contributing to Mastodon Glitch+Treehouse Edition #
Thank you for your interest in contributing to the `glitch-soc` project!
Thank you for your interest in contributing to the **Treehouse Mastodon** project!
Here are some guidelines, and ways you can help.
> (This document is a bit of a work-in-progress, so please bear with us.
@ -8,14 +8,19 @@ Here are some guidelines, and ways you can help.
## Planning ##
Right now a lot of the planning for this project takes place in our development Discord, or through GitHub Issues and Projects.
Right now a lot of the planning for this project takes place in the `#fediverse`
channel of the Treehouse Discord, or through Gitea Issues.
We're working on ways to improve the planning structure and better solicit feedback, and if you feel like you can help in this respect, feel free to give us a holler.
## Documentation ##
The documentation for this repository is available at [`glitch-soc/docs`](https://github.com/glitch-soc/docs) (online at [glitch-soc.github.io/docs/](https://glitch-soc.github.io/docs/)).
Right now, we've mostly focused on the features that make this fork different from upstream in some manner.
Adding screenshots, improving descriptions, and so forth are all ways to help contribute to the project even if you don't know any code.
The upstream Glitch documentation for this repository is available at [`glitch-soc/docs`](https://github.com/glitch-soc/docs) (online at [glitch-soc.github.io/docs/](https://glitch-soc.github.io/docs/)).
## Setup ##
For a some-batteries-required guide to setting up a development environment for this repository, read Rin's excellent
[SETUP.md](https://gitea.treehouse.systems/treehouse/mastodon/src/branch/main/SETUP.md).
## Frontend Development ##

View File

@ -1,14 +1,20 @@
# Mastodon Glitch Edition #
# Mastodon Glitch+Treehouse Edition #
> Now with automated deploys!
> Now with bunny ears!
[![Build Status](https://img.shields.io/circleci/project/github/glitch-soc/mastodon.svg)][circleci]
[![Code Climate](https://img.shields.io/codeclimate/maintainability/glitch-soc/mastodon.svg)][code_climate]
So here's the deal: we all work on this code, and anyone who uses that does so absolutely at their own risk. Can you dig it?
[circleci]: https://circleci.com/gh/glitch-soc/mastodon
[code_climate]: https://codeclimate.com/github/glitch-soc/mastodon
Specifically, this fork-of-a-fork is intended for Treehouse use only. Unless
otherwise communicated, we will not put effort into supporting other deployments
or upstreaming our patches.
So here's the deal: we all work on this code, and anyone who uses that does so absolutely at their own risk. can you dig it?
## Links
- You can view documentation for this project at [glitch-soc.github.io/docs/](https://glitch-soc.github.io/docs/).
- And contributing guidelines are available [here](CONTRIBUTING.md) and [here](https://glitch-soc.github.io/docs/contributing/).
- You can view upstream Glitch's documentation for this project at [glitch-soc.github.io/docs/](https://glitch-soc.github.io/docs/).
- Contributing guidelines are available [here](CONTRIBUTING.md).
## Known Deployments
- Treehouse Social: [social.treehouse.systems](https://social.treehouse.systems)
- VT Social: [vt.social](https://vt.social)
- Unstable Systems: [unstable.systems](https://unstable.systems)

143
SETUP.md Normal file
View File

@ -0,0 +1,143 @@
# Setting up a dev environment
## Prerequisites
Mastodon development requires the following:
- Ruby 3.0
- Ruby gems:
- `bundler`
- `irb`
- `foreman`
- NodeJS v18 (LTS)
- NPM packages:
- `yarn`
- Postgres
- Redis
### macOS
First, make sure you have Homebrew installed. Follow the instructions at
[brew.sh](https://brew.sh).
Run the following to install all necessary packages:
```
brew install ruby@3.0 foreman node yarn postgresql redis
```
Ruby 3.0 is **keg-only** by default. Follow the instructions in the **Caveat**
to add it to your path.
### Linux
We will assume that you know how to locate the correct packages for your distro.
That said, some distros package `bundler` and `irb` separately. Make sure that
you also install these.
On Arch, you will need:
- `ruby`
- `ruby-bundler`
- `ruby-irb`
- `ruby-foreman`
- `redis`
- `postgresql`
### Windows
Unfortunately, none of the authors use Windows. Contributions welcome!
## Database
In the root of this repository, go through the following script:
```sh
# Create a folder for local data
mkdir -p data
# Set up a local database
pg_ctl -D data/postgres initdb -o '-U mastodon --auth-host=trust'
# Use the data/postgres folder for the DB connection unix socket
#
# If you don't know what that means, it's just a way for Mastodon to communicate
# with a database on the same machine efficiently.
#
# See: https://manpages.ubuntu.com/manpages/jammy/man7/unix.7.html
echo 'unix_socket_directories = .' >> data/postgres/postgresql.conf
# Start the database
pg_ctl -D data/postgres start --silent
```
## Redis
In the root of this repository, run the following:
```sh
# Create a folder for redis data
mkdir -p data/redis
# Start Redis
redis-server ./redis-dev.conf
# [Optional] Stop Redis
kill "$(cat ./data/redis/redis-dev.pid)"
```
## Ruby
```sh
export RAILS_ENV=development
# Bundle installs all Ruby gems globally by default, which might cause problems.
bundle config set --local path 'vendor/bundle'
# [Apple Silicon] If using macOS on Apple Silicon, run the following:
# bundle config build.idn-ruby -- --with-idn-dir="$(brew --prefix libidn)"
# Install dependencies using bundle (Ruby) and yarn (JS)
bundle install
yarn install
# Setup the database using the pre-defined Rake task
#
# Rake is a command runner for Ruby projects. The `bundle exec` ensures that
# we use the version of Rake that this project requires.
bundle exec rake db:setup
# [Optional] If that fails, run the following and try again:
# bundle exec rake db:reset
```
## Running Mastodon
1. Run `export RAILS_ENV=development NODE_ENV=development`.
a. Put these in your shell's .rc, or a script you can source if you want to skip this step in the future.
2. Run `bundle exec rake assets:precompile`.
a. If this explodes, complaining about `Hash`, you'll need to `export NODE_OPTIONS=--openssl-legacy-provider`.
b. After doing this, you will need to run `bundle exec rake assets:clobber` and then re-run
`bundle exec rake assets:precompile`.
3. Run `foreman start`
# Updates/Troubleshooting
## RubyVM/DebugInspector Issues
Still unable to fix. Circumvent by removing `better_errors` and `binding_of_caller` from Gemfile.
Happy to troubleshoot with someone better with Ruby than us >_<'/.
## Webpack Issues
If Webpack compalins about being unable to find some assets or locales:
Try:
1. `rm -rf node_modules`
2. `yarn install`
If this doesn't help, try:
1. `yarn add webpack`
2. `git restore package.json yarn.lock`
3. `yarn install`
Then re-run `foreman`. No. We have no idea why this worked.
If the above instructions don't work, please contact @Rin here, or @tammy@social.treehouse.systems.

View File

@ -1,17 +1,36 @@
# frozen_string_literal: true
require 'pathname'
def setup_redis_env_url(prefix = nil, defaults = true)
prefix = prefix.to_s.upcase + '_' unless prefix.nil?
prefix = "#{prefix.to_s.upcase}_" unless prefix.nil?
prefix = '' if prefix.nil?
redis_url_key = "#{prefix}REDIS_URL"
return if ENV[prefix + 'REDIS_URL'].present?
if ENV[redis_url_key].present?
conn = +ENV["#{prefix}REDIS_URL"].sub(/redis:\/\//i, '')
password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults }
host = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults }
port = ENV.fetch(prefix + 'REDIS_PORT') { 6379 if defaults }
db = ENV.fetch(prefix + 'REDIS_DB') { 0 if defaults }
# Strip any prefixing `unix://`
unix = !conn.sub!(/^unix:\/\//i, '').nil?
# Strip any prefixing `./`
unix |= conn.sub!(/^(\.\/)+/, '')
unix |= conn.start_with?('/')
ENV[prefix + 'REDIS_URL'] = begin
if unix
pn = Pathname.new(conn)
pn = Pathname.getwd / pn if pn.relative?
ENV[redis_url_key] = "unix://#{pn}"
end
return
end
password = ENV.fetch("#{prefix}REDIS_PASSWORD") { '' if defaults }
host = ENV.fetch("#{prefix}REDIS_HOST") { 'localhost' if defaults }
port = ENV.fetch("#{prefix}REDIS_PORT") { 6379 if defaults }
db = ENV.fetch("#{prefix}REDIS_DB") { 0 if defaults }
ENV["#{prefix}REDIS_URL"] = begin
if [password, host, port, db].all?(&:nil?)
ENV['REDIS_URL']
else
@ -27,7 +46,7 @@ setup_redis_env_url(:cache, false)
setup_redis_env_url(:sidekiq, false)
namespace = ENV.fetch('REDIS_NAMESPACE', nil)
cache_namespace = namespace ? namespace + '_cache' : 'cache'
cache_namespace = namespace ? "#{namespace}_cache" : 'cache'
sidekiq_namespace = namespace
REDIS_CACHE_PARAMS = {

12
redis-dev.conf Normal file
View File

@ -0,0 +1,12 @@
# This redis configuration is for development only
daemonize yes
dir ./data/redis
pidfile ./redis-dev.pid
unixsocket ./redis-dev.sock
unixsocketperm 700
# Disable TCP
port 0

View File

@ -18,7 +18,7 @@ const env = process.env.NODE_ENV || 'development';
const alwaysRequireAuth = process.env.LIMITED_FEDERATION_MODE === 'true' || process.env.WHITELIST_MODE === 'true' || process.env.AUTHORIZED_FETCH === 'true';
dotenv.config({
path: env === 'production' ? '.env.production' : '.env',
path: env === 'production' || env === 'development' ? `.env.${env}` : '.env',
});
log.level = process.env.LOG_LEVEL || 'verbose';