Skip to content

Commit 2427d6a

Browse files
committed
build: Docker dev setup
1 parent 1cbdfde commit 2427d6a

File tree

12 files changed

+286
-26
lines changed

12 files changed

+286
-26
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UID=1000
2+
GID=1000

Gemfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

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

5-
gemspec
5+
if ENV['DEVEL'] == '1'
6+
rails_ver = ENV.fetch('RAILS_VERSION')
7+
gem 'rails', rails_ver
8+
9+
gem 'activeadmin', ENV.fetch('ACTIVEADMIN_VERSION')
10+
gem 'activeadmin_dynamic_fields', path: './'
11+
12+
if rails_ver.start_with?('7.0')
13+
gem 'concurrent-ruby', '1.3.4'
14+
gem 'sqlite3', '~> 1.4'
15+
else
16+
gem 'sqlite3'
17+
end
18+
else
19+
gemspec
20+
end
621

722
gem 'bigdecimal'
823
gem 'mutex_m'

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
help:
2+
@echo "Main targets: up / down / console / shell"
3+
4+
# Docker commands
5+
down:
6+
docker compose down
7+
8+
up:
9+
docker compose up
10+
11+
attach:
12+
docker compose attach app
13+
14+
up_attach:
15+
docker compose up -d && docker compose attach app
16+
17+
cleanup:
18+
docker container rm -f activeadmin_dynamic_fields_app && docker image rm -f activeadmin_dynamic_fields-app
19+
20+
# Rails specific commands
21+
console:
22+
docker compose exec -e "PAGER=more" app bin/rails console
23+
24+
routes:
25+
docker compose exec app bin/rails routes
26+
27+
specs:
28+
docker compose exec app bin/rspec --fail-fast
29+
30+
# Other commands
31+
bundle:
32+
docker compose exec app bundle
33+
34+
shell:
35+
docker compose exec -e "PAGER=more" app bash
36+
37+
lint:
38+
docker compose exec app bin/rubocop

README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,61 @@ end
234234
235235
The link url is loaded via AJAX before opening the dialog.
236236
237+
## Development
238+
239+
Project created by [Mattia Roccoberton](http://blocknot.es), thanks also to the good guys that opened issues and pull requests from time to time.
240+
241+
There 3 ways to interact with this project:
242+
243+
1) Using Docker:
244+
245+
```sh
246+
# Run rails server on the dummy app (=> http://localhost:3000 to access to ActiveAdmin):
247+
make up
248+
# Enter in a Rails console (with the dummy app started):
249+
make console
250+
# Enter in a shell (with the dummy app started):
251+
make shell
252+
# Run the linter on the project (with the dummy app started):
253+
make lint
254+
# Run the test suite (with the dummy app started):
255+
make specs
256+
# Remove container and image:
257+
make cleanup
258+
# To try different versions of Ruby/Rails/ActiveAdmin edit docker-compose.yml
259+
# For more commands please check the Makefile
260+
```
261+
262+
2) Using Appraisal:
263+
264+
```sh
265+
export RAILS_ENV=development
266+
# Install dependencies:
267+
bin/appraisal
268+
# Run server (or any command):
269+
bin/appraisal rails s
270+
# Or with a specific configuration:
271+
bin/appraisal rails80-activeadmin rails s
272+
```
273+
274+
3) With a local setup:
275+
276+
```sh
277+
# Dev setup (set the required envs):
278+
source extra/dev_setup.sh
279+
# Install dependencies:
280+
bundle update
281+
# Run server (or any command):
282+
bin/rails s
283+
# To try different versions of Rails/ActiveAdmin edit extra/dev_setup.sh
284+
```
285+
237286
## Do you like it? Star it!
238287
239288
If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other [Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source).
240289
241290
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
242291
243-
## Contributors
244-
245-
- [Mattia Roccoberton](http://blocknot.es): author
246-
- The good guys that opened issues and pull requests from time to time
247-
248292
## License
249293
250294
The gem is available as open-source under the terms of the [MIT](LICENSE.txt).

docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
app:
3+
container_name: 'activeadmin_dynamic_fields_app'
4+
build:
5+
context: .
6+
dockerfile: ./extra/Dockerfile
7+
# dockerfile: ./extra/Dockerfile_alpine
8+
args:
9+
# Debian-based Ruby image:
10+
RUBY_IMAGE: ruby:3.4-slim
11+
UID: ${UID}
12+
environment:
13+
ACTIVEADMIN_VERSION: ~> 3.3
14+
RAILS_VERSION: ~> 8.0
15+
user: "${UID}:${GID}"
16+
ports:
17+
- '3000:3000'
18+
working_dir: '/app'
19+
volumes:
20+
- '.:/app'
21+
stdin_open: true
22+
tty: true
23+
entrypoint:
24+
- /bin/sh
25+
- ./extra/entrypoint.sh

extra/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARG RUBY_IMAGE=ruby:3
2+
FROM ${RUBY_IMAGE}
3+
4+
ARG UID
5+
6+
ENV DEVEL=1
7+
ENV LANG=C.UTF-8
8+
ENV RAILS_ENV=development
9+
10+
RUN apt-get update -qq
11+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends build-essential chromium libyaml-dev nano
12+
13+
RUN gem install bundler
14+
RUN echo 'gem: --no-document' > /etc/gemrc
15+
16+
RUN useradd -u ${UID} --shell /bin/bash app
17+
RUN mkdir -p /home/app && chown -R app:app /home/app
18+
RUN chown -R app /usr/local/bundle
19+
20+
USER ${UID}
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/README.md

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

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=8.0.2
6+
export ACTIVEADMIN_VERSION=3.3.0
7+
8+
export RAILS_ENV=development

extra/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo "> Install dependencies"
2+
rm -f Gemfile.lock && bundle install
3+
4+
echo "> Run pending migrations"
5+
cd spec/dummy && bundle exec rails db:migrate
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

0 commit comments

Comments
 (0)