Skip to content

Commit c5823ac

Browse files
committed
add proper dev setup
1 parent e616da3 commit c5823ac

8 files changed

+215
-10
lines changed

Dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ FROM base AS complete
5252
# ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
5353
# ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
5454

55+
# Copy binary and configuration files for magick
56+
COPY --from=imagemagick_builder /usr/local/bin/magick /usr/local/bin/magick
57+
COPY --from=imagemagick_builder /usr/local/etc/ImageMagick-7 /usr/local/etc/ImageMagick-7
58+
COPY --from=imagemagick_builder /usr/local/share/ImageMagick-7 /usr/local/share/ImageMagick-7
59+
5560
RUN npm install -g terser uglify-js pnpm@9 patch-package ember-cli express yarn
5661

5762

@@ -164,10 +169,6 @@ COPY --from=builder --chown=discourse:discourse /home/discourse/discourse/plugin
164169
COPY --from=builder --chown=discourse:discourse /home/discourse/discourse/public ./public
165170
COPY --from=builder --chown=discourse:discourse /home/discourse/discourse/tmp ./tmp
166171

167-
# Copy binary and configuration files for magick
168-
COPY --from=imagemagick_builder /usr/local/bin/magick /usr/local/bin/magick
169-
COPY --from=imagemagick_builder /usr/local/etc/ImageMagick-7 /usr/local/etc/ImageMagick-7
170-
COPY --from=imagemagick_builder /usr/local/share/ImageMagick-7 /usr/local/share/ImageMagick-7
171172
# Create symlinks to imagemagick tools
172173
RUN ln -s /usr/local/bin/magick /usr/local/bin/animate &&\
173174
ln -s /usr/local/bin/magick /usr/local/bin/compare &&\

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Discourse Docker Image for foodcoops.at
22

3+
## Run production
4+
```
5+
docker-compose up -d --remove-orphans
6+
```
7+
8+
## Run in dev mode
9+
```
10+
docker-compose -f docker-compose-dev.yml up -d --remove-orphans
11+
```
12+
13+
314
## Test
415

516
* import db dump of real data:

dev_config/discourse.d/development.rb

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# frozen_string_literal: true
2+
3+
Discourse::Application.configure do
4+
# Settings specified here will take precedence over those in config/application.rb
5+
6+
# In the development environment your application's code is reloaded on
7+
# every request. This slows down response time but is perfect for development
8+
# since you don't have to restart the web server when you make code changes.
9+
config.cache_classes = false
10+
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
11+
12+
config.eager_load = ENV["DISCOURSE_ZEITWERK_EAGER_LOAD"] == "1"
13+
14+
# Use the schema_cache.yml file generated during db:migrate (via db:schema:cache:dump)
15+
config.active_record.use_schema_cache_dump = true
16+
17+
# Show full error reports and disable caching
18+
config.consider_all_requests_local = true
19+
config.action_controller.perform_caching = false
20+
21+
config.action_controller.asset_host = GlobalSetting.cdn_url
22+
23+
# Print deprecation notices to the Rails logger
24+
config.active_support.deprecation = :log
25+
26+
# Do not compress assets
27+
config.assets.compress = false
28+
29+
# Don't Digest assets, makes debugging uglier
30+
config.assets.digest = false
31+
32+
config.assets.debug = false
33+
34+
config.public_file_server.headers = { "Access-Control-Allow-Origin" => "*" }
35+
36+
# Raise an error on page load if there are pending migrations
37+
config.active_record.migration_error = :page_load
38+
config.watchable_dirs["lib"] = [:rb]
39+
40+
# we recommend you use mailhog https://github.com/mailhog/MailHog
41+
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
42+
43+
config.action_mailer.raise_delivery_errors = true
44+
45+
config.log_level = ENV["DISCOURSE_DEV_LOG_LEVEL"] if ENV["DISCOURSE_DEV_LOG_LEVEL"]
46+
47+
config.active_record.logger = nil if ENV["RAILS_DISABLE_ACTIVERECORD_LOGS"] == "1" ||
48+
ENV["ENABLE_LOGSTASH_LOGGER"] == "1"
49+
config.active_record.verbose_query_logs = true if ENV["RAILS_VERBOSE_QUERY_LOGS"] == "1"
50+
51+
if defined?(BetterErrors)
52+
BetterErrors::Middleware.allow_ip! ENV["TRUSTED_IP"] if ENV["TRUSTED_IP"]
53+
54+
if defined?(Unicorn) && ENV["UNICORN_WORKERS"].to_i != 1
55+
# BetterErrors doesn't work with multiple unicorn workers. Disable it to avoid confusion
56+
Rails.configuration.middleware.delete BetterErrors::Middleware
57+
end
58+
end
59+
60+
config.load_mini_profiler = true if !ENV["DISABLE_MINI_PROFILER"]
61+
62+
if hosts = ENV["DISCOURSE_DEV_HOSTS"]
63+
Discourse.deprecate("DISCOURSE_DEV_HOSTS is deprecated. Use RAILS_DEVELOPMENT_HOSTS instead.")
64+
config.hosts.concat(hosts.split(","))
65+
end
66+
67+
require "middleware/turbo_dev"
68+
config.middleware.insert 0, Middleware::TurboDev
69+
require "middleware/missing_avatars"
70+
config.middleware.insert 1, Middleware::MissingAvatars
71+
72+
config.enable_anon_caching = false
73+
require "rbtrace" if RUBY_ENGINE == "ruby"
74+
75+
if emails = GlobalSetting.developer_emails
76+
config.developer_emails = emails.split(",").map(&:downcase).map(&:strip)
77+
end
78+
79+
if ENV["DISCOURSE_SKIP_CSS_WATCHER"] != "1" &&
80+
(defined?(Rails::Server) || defined?(Puma) || defined?(Unicorn))
81+
require "stylesheet/watcher"
82+
STDERR.puts "Starting CSS change watcher"
83+
@watcher = Stylesheet::Watcher.watch
84+
end
85+
86+
config.after_initialize do
87+
config.colorize_logging = true if ENV["RAILS_COLORIZE_LOGGING"] == "1"
88+
89+
if ENV["RAILS_VERBOSE_QUERY_LOGS"] == "1"
90+
ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer do |line|
91+
line =~ %r{lib/freedom_patches}
92+
end
93+
end
94+
95+
if ENV["BULLET"]
96+
Bullet.enable = true
97+
Bullet.rails_logger = true
98+
end
99+
end
100+
101+
config.hosts << /\A(([a-z0-9-]+)\.)*localhost(\:\d+)?\Z/
102+
103+
config.generators.after_generate do |files|
104+
parsable_files = files.filter { |file| file.end_with?(".rb") }
105+
unless parsable_files.empty?
106+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
107+
end
108+
end
109+
end

dev_config/discourse.d/production.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
# Settings specified here will take precedence over those in config/application.rb
55

66
# Code is not reloaded between requests
7-
config.cache_classes = true
8-
config.eager_load = true
7+
config.cache_classes = false
8+
config.eager_load = false
99

1010
# Full error reports are disabled and caching is turned on
1111
config.consider_all_requests_local = true
12-
config.action_controller.perform_caching = true
12+
config.action_controller.perform_caching = false
1313

1414
# Disable Rails's static asset server (Apache or nginx will already do this)
15-
config.public_file_server.enabled = GlobalSetting.serve_static_assets || false
15+
config.public_file_server.enabled = true
1616

17-
config.assets.js_compressor = :uglifier
17+
# config.assets.js_compressor = :uglifier
1818

1919
# stuff should be pre-compiled
20-
config.assets.compile = false
20+
config.assets.compile = true
2121

2222
# Generate digests for assets URLs
2323
config.assets.digest = true
@@ -34,6 +34,9 @@
3434
# Send deprecation notices to registered listeners
3535
config.active_support.deprecation = :notify
3636

37+
require "middleware/turbo_dev"
38+
config.middleware.insert 0, Middleware::TurboDev
39+
3740
# allows developers to use mini profiler
3841
config.load_mini_profiler = GlobalSetting.load_mini_profiler
3942

dev_config/roundcube.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
$config['cipher_method'] = 'AES-256-CBC';
4+
$config['enable_spellcheck'] = true;
5+
$config['identities_level'] = 1;
6+
$config['log_driver'] = 'stdout';
7+
$config['managesieve_host'] = 'tls://srv01.foodcoops.at';
8+
$config['oauth_auth_uri'] = "https://app.local.at/discourse-virtmail/oauth2/authorize";
9+
$config['oauth_client_id'] = "roundcube";
10+
$config['oauth_client_secret'] = file_get_contents('/run/secrets/roundcube_oauth_client_secret');
11+
$config['oauth_identity_uri'] = "https://app.local.at/discourse-virtmail/oauth2/introspect.json";
12+
$config['oauth_provider_name'] = 'Forum';
13+
$config['oauth_provider'] = 'generic';
14+
$config['oauth_scope'] = "email";
15+
$config['oauth_token_uri'] = "https://app.local.at/discourse-virtmail/oauth2/token.json";
16+
$config['plugins'] = [];
17+
$config['product_name'] = 'FoodCoops Österreich Webmail';
18+
$config['skin_logo'] = '/images/foodcoops_logo.png';
19+
$config['spellcheck_engine'] = 'pspell';
20+
$config['use_https'] = true;
21+
$config['zipdownload_selection'] = true;

dev_config/roundcube_secret

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

docker-compose-dev.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
services:
2+
roundcube:
3+
extends:
4+
file: docker-compose.yml
5+
service: roundcube
6+
mkcert:
7+
extends:
8+
file: docker-compose.yml
9+
service: mkcert
10+
traefik:
11+
extends:
12+
file: docker-compose.yml
13+
service: traefik
14+
redis:
15+
extends:
16+
file: docker-compose.yml
17+
service: redis
18+
postgres:
19+
extends:
20+
file: docker-compose.yml
21+
service: postgres
22+
whoami:
23+
extends:
24+
file: docker-compose.yml
25+
service: whoami
26+
mailcatcher:
27+
extends:
28+
file: docker-compose.yml
29+
service: mailcatcher
30+
discourse:
31+
extends:
32+
file: docker-compose.yml
33+
service: discourse_sidekiq
34+
build:
35+
context: .
36+
target: complete
37+
environment:
38+
- RAILS_ENV=production
39+
- DISCOURSE_HOSTNAME=discourse
40+
- DISCOURSE_DB_HOST=postgres
41+
- DISCOURSE_REDIS_HOST=redis
42+
- DISCOURSE_SMTP_ADDRESS=mailcatcher
43+
- DISCOURSE_SMTP_DOMAIN=mailcatcher.local.at
44+
- DISCOURSE_DB_PASSWORD=iZ2nF2KBjzL3nLLDYkpCGQ
45+
command: bin/rails server --port 4000
46+
discourse_frontend:
47+
extends:
48+
file: docker-compose.yml
49+
service: discourse
50+
build:
51+
context: .
52+
target: complete
53+
command: node /usr/bin/pnpm --dir=app/assets/javascripts/discourse ember server --proxy http://discourse:4000 --host 0.0.0.0 --port 3000
54+
healthcheck:
55+
test: 'curl -f -H ''Host: forum.test.net'' http://localhost:3000/'
56+
start_period: 100s
57+
start_interval: 1s
58+
interval: 10s

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ services:
113113
test: 'curl -f -H ''Host: forum.test.net'' http://localhost:3000/'
114114
start_period: 10s
115115
start_interval: 1s
116+
interval: 10s
116117
discourse_nginx:
117118
<<: *discourse
118119
command: nginx

0 commit comments

Comments
 (0)