Skip to content

Commit bbee6f7

Browse files
authored
Merge pull request #51 from blocknotes/dev/docker-setup-2
Update Docker dev setup
2 parents 728e3fa + 57e151a commit bbee6f7

14 files changed

Lines changed: 124 additions & 163 deletions

File tree

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
--require rails_helper
2+
--format documentation

Gemfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@
22

33
source 'https://rubygems.org'
44

5-
if ENV["DEVEL"] == "1"
6-
gem 'rails', '~> 7.1.0'
5+
if ENV['DEVEL'] == '1'
6+
# for Docker dev
7+
rails_ver = ENV.fetch('RAILS_VERSION')
8+
gem 'rails', rails_ver
79

8-
gem 'activeadmin', '~> 3.3'
10+
gem 'activeadmin', ENV.fetch('ACTIVEADMIN_VERSION')
911
gem 'activeadmin_quill_editor', path: './'
12+
13+
if rails_ver.start_with?('7.0')
14+
gem 'concurrent-ruby', '1.3.4'
15+
gem 'sqlite3', '~> 1.4'
16+
else
17+
gem 'sqlite3'
18+
end
1019
else
1120
gemspec
21+
22+
gem 'sqlite3'
1223
end
1324

25+
gem 'bigdecimal'
26+
gem 'mutex_m'
1427
gem 'puma'
1528
gem 'sassc'
1629
gem 'sprockets-rails'
17-
gem 'sqlite3'
1830

1931
# Testing
2032
gem 'capybara'

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,50 @@ the editor will not destroy them, you'll need to implement a purge logic for tha
105105

106106
Project created by [Mattia Roccoberton](http://blocknot.es), thanks also to the good guys that opened issues and pull requests from time to time.
107107

108-
A Docker dev setup is provided if you like to work with it:
108+
There 3 ways to interact with this project:
109+
110+
1) Using Docker:
109111

110112
```sh
111113
# Run rails server on the dummy app (=> http://localhost:3000 to access to ActiveAdmin):
112114
make up
113-
# Enter in a console of the dummy app after it has been started:
115+
# Enter in a Rails console (with the dummy app started):
114116
make console
115-
# Enter in a shell of the dummy app after it has been started:
117+
# Enter in a shell (with the dummy app started):
116118
make shell
117-
# Run the linter on the project:
119+
# Run the linter on the project (with the dummy app started):
118120
make lint
119-
# Remove container and image after stopping the app:
121+
# Run the test suite (with the dummy app started):
122+
make specs
123+
# Remove container and image:
120124
make cleanup
125+
# To try different versions of Ruby/Rails/ActiveAdmin edit docker-compose.yml
126+
# For more commands please check the Makefile
127+
```
128+
129+
2) Using Appraisal:
130+
131+
```sh
132+
export RAILS_ENV=development
133+
# Install dependencies
134+
bin/appraisal
135+
# Run server (or any command)
136+
bin/appraisal rails s
137+
# Or with specific versions
138+
bin/appraisal rails71-activeadmin rails s
121139
```
122140

123-
For more commands please check the [Makefile](Makefile).
141+
3) With a local setup:
142+
143+
```sh
144+
# Dev setup (set the required envs)
145+
source extra/dev_setup.sh
146+
# Install dependencies
147+
bundle
148+
# Run server (or any command)
149+
bin/rails s
150+
# To try different versions of Rails/ActiveAdmin edit extra/dev_setup.sh
151+
```
124152

125153
## Do you like it? Star it!
126154

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ services:
44
build:
55
context: .
66
dockerfile: ./extra/Dockerfile
7+
# dockerfile: ./extra/Dockerfile_alpine
78
args:
8-
RUBY_VERSION: 3.3.6
9+
# Debian-based Ruby image:
10+
RUBY_IMAGE: ruby:3.4-slim
911
UID: ${UID}
12+
environment:
13+
ACTIVEADMIN_VERSION: ~> 3.3
14+
RAILS_VERSION: ~> 8.0
1015
user: "${UID}:${GID}"
1116
ports:
1217
- '3000:3000'

extra/Dockerfile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG RUBY_VERSION=3
2-
FROM ruby:${RUBY_VERSION}
1+
ARG RUBY_IMAGE=ruby:3
2+
FROM ${RUBY_IMAGE}
33

44
ARG UID
55

@@ -8,19 +8,14 @@ ENV LANG=C.UTF-8
88
ENV RAILS_ENV=development
99

1010
RUN apt-get update -qq
11-
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends build-essential chromium libyaml-dev
11+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends build-essential chromium libyaml-dev nano
1212

1313
RUN gem install bundler
1414
RUN echo 'gem: --no-document' > /etc/gemrc
1515

16-
COPY . /app
17-
18-
RUN mkdir -p /home/app
1916
RUN useradd -u ${UID} --shell /bin/bash app
17+
RUN mkdir -p /home/app && chown -R app:app /home/app
2018
RUN chown -R app /usr/local/bundle
21-
RUN chown -R app:app /home/app && chown -R app:app /app
2219

2320
USER ${UID}
24-
25-
WORKDIR /app
26-
RUN bundle update
21+
COPY . /app

extra/Dockerfile_alpine

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ruby:3.3-alpine
2+
3+
ARG UID
4+
5+
ENV DEVEL=1
6+
ENV LANG=C.UTF-8
7+
ENV RAILS_ENV=development
8+
9+
RUN apk update && apk add --no-cache build-base chromium tzdata yaml-dev
10+
11+
RUN gem install bundler
12+
RUN echo 'gem: --no-document' > /etc/gemrc
13+
14+
RUN adduser -u ${UID} -D app
15+
RUN mkdir -p /home/app && chown -R app:app /home/app
16+
RUN chown -R app /usr/local/bundle
17+
18+
COPY . /app

extra/dev_setup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
export DEVEL=1
4+
5+
export RAILS_VERSION=7.2.2.1
6+
export ACTIVEADMIN_VERSION=3.3.0
7+
8+
export RAILS_ENV=development

extra/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
echo "> Install dependencies"
2+
rm -f Gemfile.lock && bundle install
3+
4+
echo "> Run pending migrations"
15
cd spec/dummy && bundle exec rails db:migrate
2-
cd - && rm -f spec/dummy/tmp/pids/server.pid && bundle exec rails s -b 0.0.0.0
6+
7+
echo "> Start Rails server"
8+
cd /app && rm -f spec/dummy/tmp/pids/server.pid && bundle exec rails s -b 0.0.0.0

spec/dummy/config/environments/development.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@
5959
# Use an evented file watcher to asynchronously detect changes in source code,
6060
# routes, locales, etc. This feature depends on the listen gem.
6161
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
62+
63+
###
64+
65+
config.active_support.to_time_preserves_timezone = :zone if Gem::Version.new(Rails.version) >= Gem::Version.new('8.0')
6266
end

spec/dummy/config/environments/production.rb

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)