-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Docker Compose and Devcontainer (#725)
* Devcontainer * WIP Docker broken? * Initial split of Docker documentation * WIP * More .gitignore * yarn update * Update compose, etc.
- Loading branch information
Showing
8 changed files
with
142 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose | ||
{ | ||
"name": "bootstrap_form", | ||
|
||
// Update the 'dockerComposeFile' list if you have more compose files or use different names. | ||
"dockerComposeFile": ["../compose.yml", "../compose.override.yml"], | ||
|
||
// The 'service' property is the name of the service for the container that VS Code should | ||
// use. Update this value and .devcontainer/docker-compose.yml to the real service name. | ||
"service": "shell", | ||
|
||
// The optional 'workspaceFolder' property is the path VS Code should open by default when | ||
// connected. This is typically a file mount in .devcontainer/docker-compose.yml | ||
"workspaceFolder": "/app", | ||
// "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Uncomment the next line if you want start specific services in your Docker Compose config. | ||
// "runServices": [], | ||
|
||
// Uncomment the next line if you want to keep your containers running after VS Code shuts down. | ||
"shutdownAction": "none" | ||
|
||
// Uncomment the next line to run commands after the container is created. | ||
// "postCreateCommand": "cat /etc/os-release", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "reid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
lastUpdateCheck 1698606246341 | ||
lastUpdateCheck 1709415989700 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Working With Docker | ||
|
||
This repository offers experimental support support for developing using Docker, if you're interested. Docker is _not_ required to work on this gem. | ||
|
||
The `docker compose` approach should link to enough of your networking configuration that you can release the gem. | ||
However, you have to do some of the configuration yourself, because it's dependent on your host operating system. | ||
|
||
## Set-Up | ||
|
||
Put your personal and OS-specific configuration in a `compose.override.yml` file. | ||
|
||
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: | ||
|
||
```compose.override.yml | ||
version: '3.3' | ||
# https://blog.giovannidemizio.eu/2021/05/24/how-to-set-user-and-group-in-docker compose/ | ||
services: | ||
shell: | ||
# You have to set the user and group for this process, because you're going to be | ||
# creating all kinds of files from inside the container, that need to persist | ||
# outside the container. | ||
# Change `1000:1000` to the user and default group of your laptop user. | ||
user: 1000:1000 | ||
volumes: | ||
- /etc/passwd:/etc/passwd:ro | ||
- ~/.gem/credentials:/app/.gem/credentials:ro | ||
# $HOME here is your host computer's `~`, e.g. `/home/reid`. | ||
# `ssh` explicitly looks for its config in the home directory from `/etc/passwd`, | ||
# so the target for this has to look like your home directory on the host. | ||
- ~/.ssh:${HOME}/.ssh:ro | ||
- ${SSH_AUTH_SOCK}:/ssh-agent | ||
environment: | ||
- SSH_AUTH_SOCK=/ssh-agent | ||
``` | ||
|
||
You may have to change the `1000:1000` to the user and group IDs of your laptop. You may also have to change the `version` parameter to match the version of the `docker compose.yml` file. | ||
|
||
Adapting the above `compose.override.yml` for MacOS should be relatively straight-forward. Windows users, I'm afraid you're on your own. If you figure this out, a PR documenting how to do it would be most welcome. | ||
|
||
## Running | ||
|
||
Start the containers: | ||
|
||
```bash | ||
docker compose up -d | ||
``` | ||
|
||
You may need to install or update the gems: | ||
|
||
```bash | ||
docker compose exec -it shell bundle install | ||
``` | ||
|
||
To get a shell in the container: | ||
|
||
```bash | ||
docker compose exec -it shell /bin/bash | ||
``` | ||
|
||
Once in the shell: | ||
|
||
```bash | ||
cd demo | ||
bundle exec rails test:system | ||
``` | ||
|
||
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. | ||
|
||
## Troubleshooting Docker | ||
|
||
- With the above configuration, the gems are kept in `vendor/bundle` on your hosts, which is `$GEM_HOME` or `/app/vendor/bundle` in the running Docker container. If you're having permission problems when switching versions of Ruby or Rails, you can try `sudo rm -rf vendor/bundle` on the host, then run `BUNDLE_GEMFILES=gemfiles/7.0.gemfile bundle update` in the Docker container to re-install all the gems with the right permissions. | ||
- Sometimes, on shutdown, the Rails server PID file isn't removed, and so the above will fail. `rm demo/tmp/pids/server.pid` will fix it. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.