-
Notifications
You must be signed in to change notification settings - Fork 1k
Support for Development Containers (devcontainers) #6424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac1c197
8ea801e
6a09691
84d500f
7b70407
3a1c693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Make sure RUBY_VERSION matches the Ruby version in .ruby-version | ||
| ARG RUBY_VERSION=3.4.7 | ||
| FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION | ||
|
|
||
| USER root | ||
| ENV DEBIAN_FRONTEND=noninteractive | ||
|
|
||
| # Required on Windows | ||
| RUN mkdir -p /workspaces/openstreetmap-website \ | ||
| && chown -R vscode:vscode /workspaces/openstreetmap-website | ||
|
|
||
| # Install system packages then clean up to minimize image size | ||
| RUN apt-get update \ | ||
| && apt-get install --no-install-recommends -y \ | ||
| file \ | ||
| libarchive-dev \ | ||
| libgd-dev \ | ||
| osmosis \ | ||
| && apt-get clean \ | ||
| && apt-get distclean | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: "open_street_map" | ||
|
|
||
| services: | ||
| rails-app: | ||
| build: | ||
| context: .. | ||
| dockerfile: .devcontainer/Dockerfile | ||
|
|
||
| volumes: | ||
| - ../..:/workspaces:cached | ||
| - mise-cache:/home/vscode/.local/share/mise | ||
|
|
||
| # Overrides default command so things don't shut down after the process ends. | ||
| command: sleep infinity | ||
|
|
||
| # Uncomment the next line to use a non-root user for all processes. | ||
| # user: vscode | ||
|
|
||
| # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
| # (Adding the "ports" property to this file will not forward from a Codespace.) | ||
| depends_on: | ||
| - selenium-default | ||
| - selenium-de | ||
| - selenium-nolang | ||
| - postgres | ||
|
|
||
| selenium-default: | ||
| image: selenium/standalone-firefox | ||
| restart: unless-stopped | ||
|
|
||
| selenium-de: | ||
| image: selenium/standalone-firefox | ||
| restart: unless-stopped | ||
|
|
||
| selenium-nolang: | ||
| image: selenium/standalone-firefox | ||
| restart: unless-stopped | ||
|
|
||
| postgres: | ||
| image: postgres:16.1 | ||
| restart: unless-stopped | ||
| networks: | ||
| - default | ||
| volumes: | ||
| - postgres-data:/var/lib/postgresql/data | ||
| environment: | ||
| POSTGRES_DB: openstreetmap | ||
| POSTGRES_USER: openstreetmap | ||
| POSTGRES_PASSWORD: openstreetmap | ||
|
|
||
| volumes: | ||
| postgres-data: | ||
| mise-cache: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // For format details, see https://containers.dev/implementors/json_reference/. | ||
| // For config options, see the README at: https://github.com/devcontainers/templates/tree/main/src/ruby | ||
| { | ||
| "name": "open_street_map", | ||
| "dockerComposeFile": "compose.yaml", | ||
| "service": "rails-app", | ||
| "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
|
|
||
| // Features to add to the dev container. More info: https://containers.dev/features. | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/github-cli:1": {}, | ||
| "ghcr.io/devcontainers/features/node:1": {}, | ||
| "ghcr.io/rails/devcontainer/features/activestorage": {}, | ||
| "ghcr.io/rails/devcontainer/features/postgres-client": {} | ||
| }, | ||
|
|
||
| "containerEnv": { | ||
| "CAPYBARA_SERVER_PORT": "45678", | ||
| "DB_HOST": "postgres" | ||
| }, | ||
|
|
||
| // Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
| "forwardPorts": [3000, 5432], | ||
|
|
||
| // Configure tool-specific properties. | ||
| // "customizations": {}, | ||
|
|
||
| // Uncomment to connect as root instead. More info: https://containers.dev/implementors/json_reference/#remoteUser. | ||
| // "remoteUser": "root", | ||
|
|
||
|
|
||
| // Use 'postCreateCommand' to run commands after the container is created. | ||
| "postCreateCommand": ".devcontainer/start" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| # This setup uses https://mise.jdx.dev to manage language versions. | ||
| # Mark the config file as trusted to avoid an interactive prompt. | ||
| mise trust /workspaces/mise.local.toml | ||
pablobm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cp config/devcontainer.database.yml config/database.yml | ||
| cp config/example.storage.yml config/storage.yml | ||
| touch config/settings.local.yml | ||
|
|
||
| bin/setup --skip-server | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: devcontainer | ||
|
|
||
| on: | ||
| - push | ||
| - pull_request | ||
|
|
||
pablobm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout (GitHub) | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
|
|
||
| - name: Build and run dev container task | ||
| uses: devcontainers/ci@8bf61b26e9c3a98f69cb6ce2f88d24ff59b785c6 # v0.3.1900000417 | ||
| with: | ||
| runCmd: bin/rails test:all | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Using Development Containers for development and testing | ||
|
|
||
| You can set up a development environment for this project using [Development Containers](https://containers.dev/), aka devcontainers. | ||
|
|
||
| There are different ways of working with devcontainers. Some are automated and integrated in IDE applications, while others are more manual and require CLI tools. This guide will use [Visual Studio Code](https://code.visualstudio.com) and assumes that it's installed already. | ||
|
|
||
| Be aware that the containers will take significant space in your hard drive, in the region of 6GB. | ||
|
|
||
| ## Install Git | ||
|
|
||
| You will need Git to clone (download) the code repository and push changes. How to install Git will depend on your operating system. | ||
|
|
||
| ### Ubuntu 24.04 LTS, Debian 13 (Trixie) | ||
|
|
||
| ```bash | ||
| sudo apt-get update | ||
| sudo apt-get install git-core | ||
| ``` | ||
|
|
||
| ### Fedora | ||
|
|
||
| ```bash | ||
| sudo dnf install git | ||
| ``` | ||
|
|
||
| ### macOS | ||
|
|
||
| For macOS, you will need [Xcode Command Line Tools](https://mac.install.guide/commandlinetools/); macOS 14 (Sonoma) or later; and some familiarity with Unix development via the Terminal. | ||
|
|
||
pablobm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ### Windows | ||
|
|
||
| You can install Git using [WinGet](https://learn.microsoft.com/en-gb/windows/package-manager/winget/): | ||
|
|
||
| ```bash | ||
| winget install --id Git.Git -e --source winget | ||
| ``` | ||
|
|
||
| Alternatively, see [other install options](https://git-scm.com/install/windows). | ||
|
|
||
| ## Install Docker | ||
|
|
||
| You will need to install Docker in order to run devcontainers. Again, the methods will depend on your operating system. | ||
|
|
||
| In general: if you get an error about not having permission to use Docker, you may need to add your user to the `docker` group. The details vary, but often this is a case of running the following command: | ||
|
|
||
| ```bash | ||
| sudo usermod --append --group docker $USERNAME | ||
| ``` | ||
|
|
||
| Substitute `$USERNAME` with your actual username in the command above. After that, reboot your computer to ensure that this change takes effect. | ||
|
|
||
| ### Windows | ||
|
|
||
| 1. Use Docker Desktop via [docker.com Download](https://www.docker.com/products/docker-desktop/). | ||
|
|
||
| 2. You have to enable git symlinks before cloning the repository. | ||
| This repository uses symbolic links that are not enabled by default on Windows git. To enable them, [turn on Developer Mode](https://windowsreport.com/windows-11-developer-mode/) on Windows and run `git config --global core.symlinks true` to enable symlinks in Git. See [this StackOverflow question](https://stackoverflow.com/questions/5917249/git-symbolic-links-in-windows) for more information. | ||
|
|
||
| ### Mac | ||
|
|
||
| - Use Docker Desktop via [docker.com Download](https://www.docker.com/products/docker-desktop/). | ||
| - Or [Homebrew](https://formulae.brew.sh/cask/docker). | ||
|
|
||
| ### Linux | ||
|
|
||
| Use [Docker Engine](https://docs.docker.com/engine/install/ubuntu/) with the [docker-compose-plugin](https://docs.docker.com/compose/install/linux/) | ||
|
|
||
| ## Clone the repository | ||
|
|
||
| The repository is reasonably large (~560MB) and it's unlikely that you'll need the full history. Therefore you can probably do with a shallow clone (~100MB): | ||
| ```bash | ||
| git clone --depth=1 https://github.com/openstreetmap/openstreetmap-website.git | ||
| ``` | ||
|
|
||
| If you want to add in the full history later on, perhaps to run `git blame` or `git log`, run `git fetch --unshallow`. | ||
|
|
||
| > [!TIP] | ||
| > To download the full history from the start, run: | ||
| > ```bash | ||
| > git clone https://github.com/openstreetmap/openstreetmap-website.git | ||
| > ``` | ||
|
|
||
| ## Install Dev Containers extension | ||
|
|
||
| Start by opening the project with VS Code. Within it, you will need to install the extension _Dev Containers_, which can be done from the _Extensions_ section, reachable via the sidebar icons. Or VS Code may show a popup recommending this extension, with a button to install it directly. | ||
|
|
||
|  | ||
|
|
||
| ## Open the project in a container | ||
|
|
||
| If everything is correct, this should make a few new commands available to you within VS Code. Find and run the command "Dev Containers: Reopen in Container". | ||
|
|
||
|  | ||
|
|
||
| The first time you do this, it will go into a bit of a process. It will create the devcontainer, pull the Docker images, install the dependencies, etc. Go drink some water while this runs. | ||
pablobm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| Eventually this will present you with a development environment ready to go. In subsequent occasions this should be much faster. | ||
|
|
||
| ## Done! | ||
|
|
||
| If everything went well, you are done! For example, now you can open a shell in this environment using the VS Studio command "Create New Terminal (With Profile)": | ||
|
|
||
|  | ||
|
|
||
| From this terminal, you can run the test suite with `bundle exec rails test:all`: | ||
|
|
||
|  | ||
|
|
||
| Hopefully it should be all green? 🤞 You can also start a development server with `bundle exec rails s`: | ||
|
|
||
|  | ||
|
|
||
| It will take a moment to start, after which you will be able to take a browser to http://localhost:3000 and visit your own local version of the site. | ||
|
|
||
| ## Other useful configuration | ||
|
|
||
| See [`CONFIGURE.md`](CONFIGURE.md) for information on how to manage users and enable OAuth for iD, JOSM etc. | ||
|
|
||
| ## Other tools | ||
|
|
||
| VS Code is not the only way to work with devcontainers. Other options include: | ||
|
|
||
| - [RubyMine](https://www.jetbrains.com/help/ruby/start-dev-container-inside-ide.html): another popular environment to work with Ruby. | ||
| - [DevPod](https://devpod.sh): a CLI tool to work with devcontainers. | ||
| - [VSCodium](https://vscodium.com): a Free/Libre alternative to VS Code. | ||
| - [GitHub Codespaces](https://github.com/codespaces): GitHub's hosted IDE. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### `‘ruby’: No such file or directory` | ||
|
|
||
| In some cases Ruby may not install correctly. If you see this message, run these two commands: | ||
|
|
||
| ``` | ||
| mise install | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what mise is used for, particularly when it's referring to installing ruby. Is the ruby binary not already installed in the container ( I can see the mise cache being configured, but I can see any mise commands being run here (other than mise trust, see separate comment).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's in the container image (you already figured this out by the next comment 😉) which instead of providing a system Ruby and Node.js, uses mise to provide them. I guess it's so that multiple versions can be tested? The readme (https://github.com/rails/devcontainer) does say that the image "includes an installation of Ruby" along with mise, but I can't find it anywhere (tried some |
||
| bundle install | ||
| ``` | ||
|
|
||
| This has been observed particularly when using RubyMine. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # This configuration is tailored for use with devcontainers. See DEVCONTAINER.md for more information. | ||
|
|
||
| development: | ||
| adapter: postgresql | ||
| database: openstreetmap | ||
| username: openstreetmap | ||
| password: openstreetmap | ||
| host: <%= ENV["DB_HOST"] %> | ||
| encoding: utf8 | ||
| pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
|
|
||
| test: | ||
| adapter: postgresql | ||
| database: osm_test | ||
| username: openstreetmap | ||
| password: openstreetmap | ||
| host: <%= ENV["DB_HOST"] %> | ||
| encoding: utf8 | ||
| pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.