This dir contains the docker files to setup a complete development environment without installing anything on your system.
You can use it to develop changes, run ruby and E2E tests, and check the live preview of the documentation.
- recent
docker
- recent
docker-compose
- basic knowledge of
docker
/docker-compose
It works well on Linux. Other platforms are not tested but should work as well.
Visual Studio Code
orRubyMine
(the repo contains a complete and ready to use setup that will make your life super easy)
The pagy docker environment has been designed to be a complete setup for development. It provides the infrastructure required (right version of ruby, development gems, jekyll server, env variables, tests, cypress, etc.) without the hassle to install and maintain anything in your system.
Here are a few highlights:
- The
pagy-dev
container is run as your user (same name, UID and GID) and the localpagy
dir is mounted at the container dir/pagy
so you can edit the files in your local pagy dir or in the container: they are the same files edited by the same user. - The gems are installed and persisted in the container
BUNDLE_PATH=/usr/local/bundle
and that dir ischown
ed to your user, and mounted as the docker volumepagy_bundle
: no need to rebuild the image no mixup with your own ruby/rubies. - Your container user
HOME
is persisted in thepagy_user_home
volume, so you can even get back to the shell history in future sessions. - The
node_modules
dir is persisted in thepagy_node_modules
volume: no mixup with your localnode
- The
opt/site
is persisted in thedocs_site
volume and updated live athttp://0.0.0.0:4000
, so you can check how the documentation looks while editing it.
- Exec docker-related commands from your local
<local-pagy-dir>/docker
dir (repodocker
dir) - Exec commands from the container
/pagy
dir (repo root dir)
Run in the local terminal:
<local-pagy-dir>/docker $ ./setup-env.sh && DOCKER_BUILDKIT=1 docker-compose build
Notice: the setup-env.sh
creates an .env
file with what is needed to build the docker images with docker-compose
. You can further customize the .env
file after it is created.
Notice: see VSCode or RubyMine for specific setups.
In order to complete the setup, you need to issue a couple of commands from the container terminal, so first open a bash session:
<local-pagy-dir>/docker $ docker-compose run --rm pagy-dev bash
Then run the following commands in it:
/pagy $ bundle install
/pagy $ npm ci
Start the services:
<local-pagy-dir>/docker $ docker-compose up
Open a shell in the running pagy-dev
service (useful to interactively run commands):
<local-pagy-dir>/docker $ docker-compose exec pagy-dev bash
then run from the container shell a few useful commands:
# IRB with the `pagy` gem loaded and ready to try
/pagy $ irb -I lib -r pagy
# run the `test`, `rubocop`, `coverage_summary` and `manifest:check` tasks in one command
/pagy $ rake
# get also the coverage report (check it by opening the `coverage/index.html` in a browser)
/pagy $ HTML_REPORTS=true rake
# get list of tests available (so you can run them individually)
/pagy $ rake -D test_*
# run the e2e tests in the terminal
/pagy/e2e $ npm run test
# open cypress and run the test in its GUI
/pagy/e2e $ npm run test-open
Check the live docs site at http://localhost:4000
. It reflects in real-time any update you do to the *.md
page files (no page reload needed).
Stop the services:
<local-pagy-dir>/docker $ docker-compose down
Or run a service only for the execution of a specific command (it does not require up
and down
):
# run all the ruby tests, including rubocop and coverage tasks
<local-pagy-dir>/docker $ docker-compose run --rm pagy-dev rake
# run the e2e tests in the terminal
<local-pagy-dir>/docker $ docker-compose run --rm pagy-dev npm -w e2e run test
# open cypress and run the test in its GUI
<local-pagy-dir>/docker $ docker-compose run --rm pagy-dev npm -w e2e run test-open
The Pagy repository comes with the VSCode files that setup a complete Development Environment on your local installation almost automatically.
- Read the comments in the
docker/docker-compose.override-example.yml
file and create your owndocker-compose.override. yml
before anything else. - You need the Remote Containers extension. Installation instructions:
- Open VS Code, and hit:
Ctrl+P
- Paste
ext install ms-vscode-remote.remote-containers
- Hit
Enter
- Open VS Code, and hit:
- Run the
Remote-Containers: Open Folder in Container...
command and pick your localpagy
repository dir (VSCode will prepare the environment). - Run
bundle install
in the container terminal to complete the ruby setup. - Run
npm ci
in the container terminal to complete the e2e setup. - Open Cypress from the container terminal with
cypress open
go to Settings and choose VSCode as the File Opener.
- Run in container terminal
bundle exec yard gems
- VSCode command
Solargraph: Rebuild all gem documentation
- VSCode command
Solargraph: Download current Ruby documentation
- VSCode command
Solargraph: Restart Solargraph
- Rubocop linting and formatting
- Solargraph intellisense
- One-click-run all the tasks from the
Task Manager
list (find its Icon in the Activity Bar) - Ready to use generic and pagy-specific debugger launch configurations
- The most useful extensions for developing pagy (take a look in the
Pagy Dev Container: Pagy - Installed
Extension group) - Intelligent code completion for Cypress and the custom Pagy commands already setup
- Eslint + VSCode Eslint extension configured for Cypress
- Instead of typing
irb -I lib -r pagy
you can run IRB from the command paletteRun Terminal Command...
- Run all the
test
,rubocop
,coverage_summary
andmanifest:check
tasks by picking thetest: All
from theTask Manager
- Run the
test: All With HTML Reports
from theTask Manager
to get also a nice HTML coverage report. Check it by opening thecoverage/index.html
in a browser. - Check the live docs site at
http://localhost:4000
. It updates in real-time any update you do to the*.md
page files (no page reload needed).
Pagy offers an unconventional setup for RubyMine that makes it work as it was installed directly in the container (VSCode style). That means that RubyMine will be using a regular local SDK from the container. That usage is simpler and works also where you can find quite a few problems with the traditional remote docker-compose SDK.
The pagy docker-compose setup works well for the pagy docker environment, and it works also with VSCode or with different level of integration with other IDEs or CLI. Unfortunately I've got quite a lot of problems to run it as a standard Docker-compose as a remote interpreter, so I abandoned the official remote way and found this way. You can try the official way if you feel adventurous :).
In order to make RubyMine work inside the container, you need to take a look at the docker/docker-compose.override-example.yml
: it contains a working example and the comments that should allow you to customize it for your own system.
The basic target/stage for using RubyMine from the container is the (docker-custom-dev
: the default). That enables 98% of capabilities of RubyMine. The only small limitation is that the link won't work from inside RubyMine, since there is no browser installed in the container, nor drivers to share one from your host. However that is the simplest target and the one you should probably pick.
If you are really picky and want to have 100% of browser features, the Dockerfile
includes also stages for NVIDIA cards. That are bigger builds but you can run also any browser from inside RubyMine, even if the browser is installed on the host. That is what I use for my own development environment (see the docker/docker-compose.override-example.yml
).
After you create your own overriding, you should build normally (see Build). It will build the pagy-custom-dev
and everything should work. As soon as you run docker-compose up
Rubymine should open from the container and you can create a local SDK.
Open the terminal and run this in order to complete the setup:
/pagy $ bundle install
/pagy $ npm ci
IMPORTANT: If the Ruby SDK does not find all the gems after installing them, then you may want to check whether the GEM_PATH
environment variable contains also /usr/local/bundle/ruby/3.0.0
(Tools
>Show Gem Environment
) and add it if needed. To add it you an create a New local with custom configurator...
SDK, adding the env GEM_PATH=/usr/local/bundle/ruby/3.0.0:/home/dd/.local/share/gem/ruby/3.0.0:/usr/local/lib/ruby/gems/3.0.0
as Custom configurator
.
A few run configurations are provided for interacting with docker-compose
and the development, giving you the menus to run the more important tasks and tools. RubyMine will pick them up automatically. They work in this setup, but they might have to be adapted if you want to use them in a traditional remote docker-compose SDK.
The coverage has an advanced Simplecov setup and RubyMine may not handle it. If the usual RubyMine coverage tools don't work, you can trigger the coverage by running the task without the RubyMine coverage, or userake
or HTML_REPORTS=true rake
in the terminal.
When you want to get rid of everything related to the pagy
docker development on your system, here is a list of the commands to find them:
- Volumes:
docker volume ls | grep pagy
- Images:
docker images | grep -E 'pagy|cypress'
- Image dependencies: if you are not using them for other containers, you may also want to check
docker images | grep -E 'ruby|alpine|debian'
- Containers:
docker ps -a | grep pagy
- Networks:
docker network ls | grep pagy