Skip to content

Commit baafa8d

Browse files
authored
Merge pull request #558 from better-together-org/fix/js
This PR sees the deployment of working app javascript at long last! Importmaps are correctly configured to autoload files from the javascript directory and make them available in production. This means that the Bootstrap js and the local Stimulus controllers now get referenced correctly in the production environment. Previously, I was incorrectly using relative references because I had made a mistake when configuring importmaps. There is some quirk of my development and production setups that mean that the normal way of looking up files inside my app did not work in the importmap config. I think this has something to do with Docker. This PR marks the first stable version of the Community Engine in production, and should be considered the completion of a major project milestone!
2 parents c557ea3 + 3c952ad commit baafa8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1113
-198
lines changed

.dokku/predeploy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
bundle install
3+
bundle exec rails db:migrate

.dokku/release.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
# Ensure Sentry CLI is installed
7+
if ! command -v sentry-cli &> /dev/null
8+
then
9+
echo "sentry-cli could not be found, please install it."
10+
exit 1
11+
fi
12+
13+
# Set the release version
14+
RELEASE_VERSION=$(git rev-parse --short HEAD)
15+
16+
# Export the release version as an environment variable
17+
export SENTRY_RELEASE=$RELEASE_VERSION
18+
19+
# Notify Sentry of the new release
20+
sentry-cli releases new $SENTRY_RELEASE
21+
sentry-cli releases finalize $SENTRY_RELEASE
22+
23+
echo "Sentry release $SENTRY_RELEASE has been set."
24+
25+
# Run any pending migrations (if needed)
26+
bundle exec rails db:migrate
27+
28+
echo "Release step completed."

.dokku/web.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# release.sh
2+
#!/bin/bash
3+
set -e
4+
5+
mkdir -p spec/dummy/tmp/pids
6+
bash -c "rm -f spec/dummy/tmp/pids/server.pid && cd ./spec/dummy && bundle exec puma -C config/puma.rb"

.env.sample

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ALLOWED_HOSTS='http://localhost:3001'
2+
APP_HOST='http://localhost:3001'
3+
ASSET_HOST=
4+
AWS_ACCESS_KEY_ID=
5+
AWS_SECRET_ACCESS_KEY=
6+
BASE_URL='http://localhost:3001'
7+
CDN_DISTRIBUTION_ID=
8+
DATABASE_URL='postgres://postgres:postgres@better-together-db:5435/better_together_production'
9+
FOG_DIRECTORY=
10+
FOG_HOST=
11+
FOG_REGION='ca-central-1'
12+
GIT_REV=
13+
LANG='en_US.UTF-8'
14+
PORT='5000'
15+
RACK_ENV='production'
16+
RAILS_ENV='production'
17+
RAILS_LOG_LEVEL='debug'
18+
RAILS_LOG_TO_STDOUT='true'
19+
RAILS_SERVE_STATIC_FILES='true'
20+
REDIS_URL='redis://better-together-redis:6379'
21+
S3_BUCKET_NAME=
22+
S3_REGION=
23+
SECRET_KEY_BASE=
24+
SENTRY_DSN=
25+
SMTP_PASSWORD=
26+
SMTP_USERNAME='apikey'
27+
SMTP_address='smtp.sendgrid.net'

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ node_modules/
5252

5353
spec/dummy/storage/og/9g/og9gmixuxfbx1sl5rgk6brbjmvms
5454
spec/dummy/storage/va/ri/variants/og9gmixuxfbx1sl5rgk6brbjmvms/6e7b83b26e6f33c216f6d559f3b939a455b14b656f2fc1797c3cfcef371301b5
55-
spec/dummy/storage/*
55+
spec/dummy/storage/*
56+
.env.dev
57+
.env.prod

Dockerfile

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,84 @@
1+
# Stage 1: Build environment
2+
FROM ruby:3.2.2 AS builder
13

2-
FROM ruby:3.2.2
4+
# Define build-time variables
5+
ARG AWS_ACCESS_KEY_ID
6+
ARG AWS_SECRET_ACCESS_KEY
7+
ARG FOG_DIRECTORY
8+
ARG FOG_HOST
9+
ARG FOG_REGION
10+
ARG ASSET_HOST
11+
ARG CDN_DISTRIBUTION_ID
12+
13+
# Set environment variables for asset precompilation
14+
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
15+
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
16+
ENV FOG_DIRECTORY=${FOG_DIRECTORY}
17+
ENV FOG_HOST=${FOG_HOST}
18+
ENV FOG_REGION=${FOG_REGION}
19+
ENV ASSET_HOST=${ASSET_HOST}
20+
ENV CDN_DISTRIBUTION_ID=${CDN_DISTRIBUTION_ID}
321

22+
# Install dependencies
423
RUN apt-get update -qq \
5-
&& apt-get install -y build-essential postgresql-client libpq-dev nodejs libssl-dev apt-transport-https ca-certificates libvips42
24+
&& apt-get install -y --no-install-recommends \
25+
build-essential \
26+
postgresql-client \
27+
libpq-dev \
28+
nodejs \
29+
libssl-dev \
30+
apt-transport-https \
31+
ca-certificates \
32+
libvips42 \
33+
curl
34+
35+
# Set working directory
36+
WORKDIR /community-engine
37+
38+
# Copy Gemfile and Gemfile.lock
39+
COPY Gemfile Gemfile.lock better_together.gemspec ./
40+
41+
COPY lib lib
42+
43+
# Install bundler and gems
44+
RUN gem uninstall bundler \
45+
&& gem install bundler:2.4.13 \
46+
&& bundle install --jobs 4 --retry 3
647

7-
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
8-
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
48+
# Copy the rest of the application code
49+
COPY . .
950

10-
RUN apt-get update -qq && apt-get install -y yarn
51+
# Precompile assets and sync to S3
52+
RUN bundle exec rake app:assets:precompile
53+
RUN bundle exec rake app:assets:sync
1154

12-
RUN mkdir /community-engine
55+
# Stage 2: Runtime environment
56+
FROM ruby:3.2.2
57+
58+
# Install runtime dependencies
59+
RUN apt-get update -qq \
60+
&& apt-get install -y --no-install-recommends \
61+
libpq-dev \
62+
nodejs \
63+
libssl-dev \
64+
libvips42 \
65+
curl \
66+
&& curl -sL https://sentry.io/get-cli/ | bash \
67+
&& rm -rf /var/lib/apt/lists/*
68+
69+
# Set working directory
1370
WORKDIR /community-engine
14-
COPY Gemfile /community-engine/Gemfile
15-
COPY Gemfile.lock /community-engine/Gemfile.lock
1671

17-
RUN gem uninstall bundler
18-
RUN gem install bundler:2.4.13
72+
# Copy the application code from the build stage
73+
COPY --from=builder /community-engine /community-engine
74+
75+
# Create and set permissions for spec/dummy/tmp/pids directory
76+
RUN mkdir -p spec/dummy/tmp/pids
77+
RUN chmod -R 755 spec/dummy/tmp
78+
79+
# Set environment variables
80+
ENV RAILS_ENV=production
81+
ENV RACK_ENV=production
1982

20-
COPY . /community-engine
83+
# Run the application
84+
CMD ["./spec/dummy","bundle", "exec", "puma", "-C", "config/puma.rb"]

Dockerfile.dev

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ruby:3.2.2
2+
3+
RUN apt-get update -qq \
4+
&& apt-get install -y build-essential postgresql-client libpq-dev nodejs libssl-dev apt-transport-https ca-certificates libvips42
5+
6+
RUN mkdir /community-engine
7+
WORKDIR /community-engine
8+
COPY Gemfile /community-engine/Gemfile
9+
COPY Gemfile.lock /community-engine/Gemfile.lock
10+
11+
RUN gem uninstall bundler
12+
RUN gem install bundler:2.4.13
13+
14+
COPY . /community-engine

Dockerfile.old

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
FROM ruby:3.2.2
3+
4+
RUN apt-get update -qq \
5+
&& apt-get install -y build-essential postgresql-client libpq-dev nodejs libssl-dev apt-transport-https ca-certificates libvips42
6+
7+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
8+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
9+
10+
RUN apt-get update -qq && apt-get install -y yarn
11+
12+
RUN mkdir /community-engine
13+
WORKDIR /community-engine
14+
COPY Gemfile /community-engine/Gemfile
15+
COPY Gemfile.lock /community-engine/Gemfile.lock
16+
17+
RUN gem uninstall bundler
18+
RUN gem install bundler:2.4.13
19+
20+
COPY . /community-engine

Gemfile

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,110 @@
33
source 'https://rubygems.org'
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6+
ruby '3.2.2'
7+
68
gemspec
79

8-
gem 'pundit-resources',
9-
github: 'better-together-org/pundit-resources'
10+
gem 'asset_sync'
11+
gem 'aws-sdk-s3', require: false
1012

11-
group :development do
13+
# bcrypt for secure password handling
14+
gem 'bcrypt', '~> 3.1.20'
15+
# Bootsnap for faster boot times
16+
gem 'bootsnap', '>= 1.7.0', require: false
17+
18+
gem 'fog-aws'
19+
20+
# Database adapter for PostgreSQL
21+
gem 'pg', '>= 0.18', '< 2.0'
22+
# Puma as the app server
23+
gem 'puma', '~> 6.4'
24+
25+
# Pundit for authorization, custom fork for Better Together
26+
gem 'pundit-resources', '~> 1.1.4', github: 'better-together-org/pundit-resources'
27+
28+
# Core Rails gem
29+
gem 'rack-protection'
30+
gem 'rails', '~> 7.0.8'
31+
32+
# Redis for ActionCable and background jobs
33+
gem 'redis', '~> 5.2'
34+
35+
gem 'rswag'
36+
37+
# Sidekiq for background processing
38+
gem 'sidekiq', '~> 7.2.4'
39+
40+
# Error and performance monitoring with Sentry
41+
gem 'sentry-rails'
42+
gem 'sentry-ruby'
43+
gem 'stackprof'
44+
45+
# Uglifier for JavaScript compression
46+
gem 'uglifier', '>= 1.3.0'
47+
48+
group :development, :test do
49+
# Better errors for enhanced error pages
1250
gem 'better_errors'
51+
# Binding of caller provides pry console at breakpoints
1352
gem 'binding_of_caller'
14-
gem 'execjs'
15-
gem 'listen'
16-
gem 'pg'
17-
gem 'puma', '~> 6.0'
18-
gem 'rack-mini-profiler'
19-
gem 'rb-readline'
20-
gem 'rbtrace'
53+
# Debugger tool
54+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
55+
# Faker for generating fake data
56+
gem 'faker'
57+
# FactoryBot for setting up test data
58+
gem 'factory_bot_rails'
59+
# Fuubar for fancy test progress bar
60+
gem 'fuubar'
61+
# Pry for a powerful shell alternative to IRB
62+
gem 'pry'
63+
# RuboCop for static code analysis
2164
gem 'rubocop'
22-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
23-
gem 'spring'
24-
gem 'spring-watcher-listen', '~> 2.1.0'
25-
gem 'web-console', '>= 3.3.0'
2665
end
2766

28-
group :development, :test do
67+
group :development do
68+
# Brakeman for static analysis security vulnerability scanning
2969
gem 'brakeman', require: false
70+
# Bundler audit for checking gem vulnerabilities
3071
gem 'bundler-audit', require: false
31-
gem 'byebug'
32-
gem 'factory_bot_rails'
33-
gem 'faker'
34-
gem 'pry'
35-
gem 'rswag'
72+
# Listen for file system changes
73+
gem 'listen', '>= 3.0.5', '< 3.10'
74+
# Rack mini profiler for performance profiling
75+
gem 'rack-mini-profiler'
76+
# Readline implementation for Ruby
77+
gem 'rb-readline'
78+
# Spring for fast Rails actions via pre-loading
79+
gem 'spring'
80+
# Spring watcher for file changes
81+
gem 'spring-watcher-listen', '~> 2.1.0'
82+
# Tracing tool
83+
gem 'rbtrace'
84+
# Web-console for an interactive console on exception pages
85+
gem 'web-console', '>= 3.3.0'
3686
end
3787

3888
group :test do
39-
# gem 'capybara'
40-
# gem 'chromedriver-helper'
89+
# Capybara for integration testing
90+
gem 'capybara', '>= 2.15'
91+
# Coveralls for test coverage reporting
4192
gem 'coveralls'
93+
# Database cleaner for test database cleaning
94+
gem 'database_cleaner'
4295
gem 'database_cleaner-active_record'
43-
gem 'fuubar'
96+
# # Easy installation and use of chromedriver to run system tests with Chrome
97+
gem 'webdrivers'
98+
# RuboCop RSpec for RSpec-specific code analysis
99+
gem 'rubocop-rspec'
100+
# RSpec for unit testing
101+
gem 'rspec'
102+
# RSpec Rails integration
44103
gem 'rspec-rails'
104+
# Selenium WebDriver for browser automation
105+
gem 'selenium-webdriver'
106+
# Shoulda Callback Matchers for testing callbacks
45107
gem 'shoulda-callback-matchers'
108+
# Shoulda Matchers for simplifying model tests
46109
gem 'shoulda-matchers'
110+
# SimpleCov for test coverage analysis
47111
gem 'simplecov', require: false
48-
# gem 'selenium-webdriver'
49112
end

0 commit comments

Comments
 (0)