Skip to content

Commit eab1e3e

Browse files
authored
Merge pull request #753 from lcreid/docker-use-ephemeral-ports
Docker use ephemeral ports
2 parents ef4bfd2 + ae7cff4 commit eab1e3e

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

.devcontainer/devcontainer.json renamed to .devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"name": "bootstrap_form",
55

66
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
7-
"dockerComposeFile": ["../compose.yml", "../compose.override.yml"],
7+
"dockerComposeFile": ["compose.yml", "compose.override.yml"],
88

99
// The 'service' property is the name of the service for the container that VS Code should
1010
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
11-
"service": "shell",
11+
"service": "web",
1212

1313
// The optional 'workspaceFolder' property is the path VS Code should open by default when
1414
// connected. This is typically a file mount in .devcontainer/docker-compose.yml

.yarnrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# yarn lockfile v1
33

44

5-
lastUpdateCheck 1741731093687
5+
lastUpdateCheck 1750996124491

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ cd demo
7676
bundle exec rails test:all # or test:system
7777
```
7878

79-
The [Docker development environment](#using-docker compose) appears to generate screenshots that are the same as what GitHub generates.
79+
The [Docker development environment](#developing-with-docker) appears to generate screenshots that are the same as what GitHub generates.
8080

8181
Finally, maintainers may sometimes push changes directly to `main` or use other workflows to update the code. If pushing to `main` generates a commit for screenshot changes, please consider reverting your change immediately by executing the above `pull` and `revert` and another `push`, for the sanity of users who are using the edge (`main` branch) version of the gem. At any rate, review the changes promptly and use your judgement.
8282

DOCKER.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ Put your personal and OS-specific configuration in a `compose.override.yml` file
1212
The following instructions work for an Ubuntu host, and will probably work for other common Linux distributions. Add a `compose.override.yml` in the local directory, that looks like this:
1313

1414
```compose.override.yml
15-
version: '3.3'
16-
1715
# https://blog.giovannidemizio.eu/2021/05/24/how-to-set-user-and-group-in-docker compose/
1816
1917
services:
20-
shell:
18+
web:
2119
# You have to set the user and group for this process, because you're going to be
2220
# creating all kinds of files from inside the container, that need to persist
2321
# outside the container.
@@ -50,23 +48,45 @@ docker compose up -d
5048
You may need to install or update the gems:
5149

5250
```bash
53-
docker compose exec -it shell bundle install
51+
docker compose exec web bundle install
5452
```
5553

5654
To get a shell in the container:
5755

5856
```bash
59-
docker compose exec -it shell /bin/bash
57+
docker compose exec web /bin/bash
58+
```
59+
60+
Once in the shell, run tests:
61+
62+
```bash
63+
bundle exec rake test
6064
```
6165

62-
Once in the shell:
66+
Run the demo app and browse to it:
67+
68+
```bash
69+
cd demo
70+
bin/dev
71+
```
72+
73+
On the host, not the Docker container, get the port number(s) you can use in the browser to access the test app running in the Docker container:
74+
75+
```bash
76+
docker compose port web 3001 | cut -d: -f 2 # Browser
77+
docker compose port web 7900 | cut -d: -f 2 # To watch the browser execute system tests.
78+
```
79+
80+
Browse to `localhost:<port number from above>`.
81+
82+
Run system tests:
6383

6484
```bash
6585
cd demo
6686
bundle exec rails test:system
6787
```
6888

69-
Note that this system test approach is highly experimental and has some rough edges. The docker compose file and/or steps to run system tests may change. The tests currently fail, because the files with which they're being compared were generated on a Mac, but the Docker containers are running Linux.
89+
Note that this system test approach is highly experimental and has some rough edges. The docker compose file and/or steps to run system tests may change.
7090

7191
## Troubleshooting Docker
7292

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
88
gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
99
gem "rails", BootstrapForm::REQUIRED_RAILS_VERSION
1010
gem "sprockets-rails", require: "sprockets/railtie"
11-
gem "sqlite3", ">= 1.4"
11+
gem "sqlite3", "~> 2.1"

compose.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# And:
44
# https://medium.com/@retrorubies/chrome-as-a-service-for-rails-testing-b1a45e70fec1
55
services:
6-
shell:
6+
web:
77
image: lenchoreyes/jade:rails-app-${RUBY_VERSION:-3.3}-sqlite-${DISTRO:-bookworm}
88
stdin_open: true
99
tty: true
@@ -16,8 +16,8 @@ services:
1616
- TEST_APP_HOST=shell
1717
- TEST_APP_PORT=3001
1818
ports:
19-
- "3000:3000"
20-
- "3001:3001"
19+
- "3000"
20+
- "3001"
2121
command: /bin/bash
2222

2323
selenium:
@@ -30,6 +30,4 @@ services:
3030
environment:
3131
- LANG=en_CA.UTF-8
3232
ports:
33-
- '4444:4444'
34-
- '5900:5900'
35-
- '7900:7900'
33+
- "7900"

0 commit comments

Comments
 (0)