-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For new Rails apps, a suitable devcontainer is enabled by default. The setup provided has been tested and confirmed to work with a singe click in Visual Studio Code.
- Loading branch information
Showing
10 changed files
with
187 additions
and
9 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,3 @@ | ||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version | ||
ARG RUBY_VERSION=3.3.5 | ||
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION |
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,40 @@ | ||
name: "codeharbor" | ||
|
||
services: | ||
rails-app: | ||
build: | ||
context: .. | ||
dockerfile: .devcontainer/Dockerfile | ||
|
||
volumes: | ||
- ../..:/workspaces:cached | ||
|
||
# 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 | ||
- postgres | ||
|
||
selenium: | ||
image: selenium/standalone-chromium | ||
restart: unless-stopped | ||
|
||
postgres: | ||
image: postgres:16.4 | ||
restart: unless-stopped | ||
networks: | ||
- default | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
|
||
volumes: | ||
postgres-data: |
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,48 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby | ||
{ | ||
"name": "CodeHarbor", | ||
"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/git-lfs:1": {}, | ||
"ghcr.io/devcontainers/features/github-cli:1": {}, | ||
"ghcr.io/rails/devcontainer/features/activestorage": {}, | ||
"ghcr.io/devcontainers/features/node:1": { | ||
"installYarnUsingApt": false | ||
}, | ||
"ghcr.io/rails/devcontainer/features/postgres-client": {} | ||
}, | ||
|
||
"containerEnv": { | ||
"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0", | ||
"CAPYBARA_SERVER_PORT": "45678", | ||
"SELENIUM_HOST": "selenium", | ||
"DB_HOST": "postgres" | ||
}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
"forwardPorts": [3045, 7500], | ||
|
||
"portsAttributes": { | ||
"3045": { | ||
"label": "webpack-dev-server" | ||
}, | ||
"7500": { | ||
"label": "rails-server" | ||
} | ||
}, | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root", | ||
|
||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "bin/setup" | ||
} |
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
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
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,58 @@ | ||
# Devcontainer setup | ||
|
||
With the devcontainer-based setup, you won't need to (manually) install CodeHarbor and all dependencies on your local instance. Instead, a Docker setup containing all requirements will be configured. The development environment is defined in the `.devcontainer` repository folder and will be applied when you open the project in a supported editor or IDE. | ||
|
||
## Local setup | ||
|
||
In order to run the devcontainer locally, you need to have Docker installed on your machine. You can find the installation instructions for your operating system on the [official Docker website](https://docs.docker.com/get-docker/). Then, you'll need an editor or IDE that supports devcontainers. We recommend [Visual Studio Code](https://code.visualstudio.com/),[RubyMine](https://www.jetbrains.com/ruby/), [IntelliJ IDEA](https://www.jetbrains.com/idea/). | ||
|
||
### Clone the repository: | ||
|
||
You may either clone the repository via SSH (recommended) or HTTPS (hassle-free for read operations). If you haven't set up GitHub with your SSH key, you might follow [their official guide](https://docs.github.com/en/authentication/connecting-to-github-with-ssh). | ||
|
||
**SSH (recommended, requires initial setup):** | ||
```shell | ||
git clone git@github.com:openHPI/codeharbor.git | ||
``` | ||
|
||
**HTTPS (easier for read operations):** | ||
```shell | ||
git clone https://github.com/openHPI/codeharbor.git | ||
``` | ||
|
||
### Open the project in your editor or IDE: | ||
|
||
Open the project in your editor or IDE to get started: | ||
|
||
**Visual Studio Code:** | ||
```shell | ||
code codeharbor | ||
``` | ||
|
||
**RubyMine:** | ||
```shell | ||
rubymine codeharbor | ||
``` | ||
|
||
**IntelliJ IDEA:** | ||
```shell | ||
idea codeharbor | ||
``` | ||
|
||
### Install the recommended extensions: | ||
|
||
When you open the project in an supported editor or IDE, you'll be prompted to install the recommended extension(s) for support with devcontainers. Click on "Install" to install the recommended extensions. | ||
|
||
### Start the devcontainer: | ||
|
||
After you've installed the recommended extension(s), you can start the devcontainer by a simple click. | ||
|
||
**Visual Studio Code:** | ||
Click on the blue "Reopen in Container" button in the bottom right corner of your editor. [More information](https://code.visualstudio.com/docs/devcontainers/tutorial). | ||
|
||
**RubyMine:** / **IntelliJ IDEA:** | ||
Open the file `.devcontainer/devcontainer.json` and click on the blue Docker icon in the top left corner of your editor. More information for [RubyMine](https://www.jetbrains.com/help/ruby/connect-to-devcontainer.html#create_dev_container_inside_ide) or [IntelliJ IDEA](https://www.jetbrains.com/help/idea/connect-to-devcontainer.html#create_dev_container_inside_ide). | ||
|
||
# Start CodeHarbor | ||
|
||
When developing with the devcontainer, you can run CodeHarbor in the same way as you would on your local machine. The only difference is that you're running it inside the devcontainer. You can find more information on how to run CodeHarbor in the [LOCAL_SETUP.md](LOCAL_SETUP.md#start-codeharbor). All ports are forwarded to your local machine, so you can access CodeHarbor in your browser as usual. |
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
WebMock.disable_net_connect!(allow_localhost: true) | ||
allowed_hosts = [] | ||
|
||
# Allow connections to the Selenium server and the Rails app | ||
if ENV['SELENIUM_HOST'] | ||
allowed_hosts << ENV.fetch('SELENIUM_HOST') | ||
# This hostname is defined for devcontainers | ||
allowed_hosts << 'rails-app' | ||
end | ||
|
||
WebMock.disable_net_connect!(allow_localhost: true, allow: allowed_hosts) |