Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Add ability to use Docker Dev containers locally (#303)
Browse files Browse the repository at this point in the history
Co-authored-by: ns065186 <[email protected]>
  • Loading branch information
nikhitasharma and ns065186 authored Mar 27, 2023
1 parent 7f916ed commit f245e26
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM docker.cernerrepos.net/ion/ion-node:5
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "TerraGraphs",
"dockerComposeFile": "docker-compose.yml",
"service": "vscode",
"shutdownAction": "stopCompose",
"workspaceFolder": "/workspace",
"postCreateCommand": "",
"runServices": [
"vscode"
],
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"james-yu.latex-workshop",
"eamodio.gitlens",
"shardulm94.trailing-spaces",
"stkb.rewrap",
"vscode-icons-team.vscode-icons",
"streetsidesoftware.code-spell-checker"
]
}
},
"forwardPorts": [8080]
}
43 changes: 43 additions & 0 deletions .devcontainer/docker-compose-wdio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "3"

services:
selenium-hub:
image: selenium/hub:3.141.59-zirconium
container_name: selenium-hub
ports:
- "4444:4444"
healthcheck:
test: ["CMD", "/opt/bin/check-grid.sh"]
interval: 15s
timeout: 30s
retries: 5

chrome:
image: selenium/node-chrome:3.141.59-zirconium
# Volume mounting is necessary to ensure the browser does not crash inside the docker container.
# For more details see:
# https://github.com/SeleniumHQ/docker-selenium#running-the-images
# https://bugs.chromium.org/p/chromium/issues/detail?id=519952
# https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444

firefox:
image: selenium/node-firefox:3.141.59-zirconium
# Volume mounting is necessary to ensure the browser does not crash inside the docker container.
# For more details see:
# https://github.com/SeleniumHQ/docker-selenium#running-the-images
# https://bugs.chromium.org/p/chromium/issues/detail?id=519952
# https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
14 changes: 14 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"

services:
vscode:
network_mode: host
build: .
volumes:
- ../:/workspace
# Docker socket to access Docker server
- /var/run/docker.sock:/var/run/docker.sock
environment:
- WATCHPACK_POLLING=true
- WDS_SOCKET_HOST=127.0.0.1
entrypoint: /bin/sh -c "while sleep 1000; do :; done"
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Terra Graphs is a graphing library built using D3 visualization library. It prov
- [Packages Requiring I18n](#packages-requiring-i18n)
- [Contributing](#contributing)
- [Local Development](#local-development)
- [Local Development using Docker (Dev Containers)](#docker-local-development)
- [LICENSE](#license)

---
Expand Down Expand Up @@ -177,6 +178,57 @@ npm run dev

---

<h2 id="docker-local-development">
Local Development using Docker (Dev Containers)
</h2>

1. Install [Rancher](https://rancherdesktop.io/) or [Docker](https://www.docker.com/).
- [Rancher](https://rancherdesktop.io/) is free and open-source and is highly recommended whereas Docker may require a license for use.
2. Install [Microsoft VS Code](https://code.visualstudio.com/Download).
3. Install the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
- Navigate to View -> Extension -> Search for and install _Dev Containers_ (or "ms-vscode-remote.remote-containers")
- More information on [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers)
4. Build the dev container:
- (Option 1) - Opening local workspace in dev container
- Clone the repository (or fork) locally and open the project in Visual Studio Code
- Navigate to View -> Command Palette and run **Dev Containers: Open Workspace in Container**
- (Option 2) - Recommended for Windows for hot-reloading to work during development and improved performance: Creating the dev container using dev volumes (for more information and guidance, see the [Official Guide](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-a-git-repository-or-github-pr-in-an-isolated-container-volume))
- If you have git setup and have global config file _~/.gitconfig_ locally, these settings should automatically be transferred to the dev container
- Navigate to View -> Command Palette and run **Dev Containers: Clone Repository in Container Volume**
- Paste the GitHub URL of this repository (or fork)
- VS Code will now reload the workspace and create/start the dev container and volume
- Please note: changes made using this option will only update files in the Docker volume. It is recommended to commit changes often in case the volume is deleted or dev container gets removed.
5. You're now running in a dev container. Use the terminal of the dev container in Visual Studio Code to issue any npm or bash commands.
6. Before running any WDIO tests, make sure to perform the following steps:
- Open a new terminal (outside the dev container) and navigate to ".devcontainer/" path in your repository.
- Execute the command `"docker compose -f docker-compose-wdio.yml up"`. Selenium hub should spin up. Leave this running in the background. If you see errors saying "container name already exists", run `"docker container prune"` command followed by pressing "y" to clear up any unused containers and try running the previous command again.
- You can now run `npm run test:docker` or `npm run wdio:docker` commands to run WDIO tests from inside the Dev Container.
- NOTE: Optionally, if you want to run other WDIO commands in the dev container, you can also edit the root package.json file WDIO scripts to include `--disableSeleniumService=true` flag. This will disable the selenium service from spinning up again.
For example:
```sh
"scripts": {
"wdio-fusion": "terra wdio --disableSeleniumService=true --themes orion-fusion-theme",
}
```
7. To terminate a dev container:
- Use command line or Rancher/Docker Desktop OR
- Using Visual Studio Code
- Select the Remote Explorer icon in the Activity Bar or View -> Command Palette and run **Remote Explorer: Focus on Containers View**
- Locate the **terra-graphs_devcontainer** or currently running dev container under "Dev Containers"
- Right click and select **Stop Container** and close the workspace
- You can also select **Rebuild Container** to restart the dev container
8. To reopen a dev container:
- Existing local workspace (for Option 1)
- Open the project in Visual Studio Code
- Ensure the workspace contains the .devcontainer folder
- Navigate to View -> Command Palette and run **Dev Containers: Open Workspace in Container**
- Isolated dev container volume (for Option 2)
- Open Visual Studio Code
- Use the Remote Explorer icon in the Activity Bar or View -> Command Palette and run **Remote Explorer: Focus on Containers View** to view containers
- Locate the **terra-graphs_devcontainer** under "Dev Containers"
- Hover over the dev container and click the Folder icon labelled **Open Folder in Container** or by right clicking and selecting **Open Folder in Container**


## LICENSE

Copyright 2020 - present Cerner Innovation, Inc.
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@
"start-prod": "webpack-dev-server --env.disableHotReloading -p",
"start-static": "npm run compile:prod && terra express-server --site ./build",
"test": "npm run lint && npm run jest && npm run karma && npm run wdio-default",
"test:docker": "npm run lint && npm run jest && && npm run karma && npm run wdio-default:docker",
"karma": "karma start ./packages/carbon-graphs/karma.config.js --single-run --no-auto-watch",
"wdio:compile": "npm run compile && npm run wdio-default",
"wdio-default": "terra wdio",
"wdio-default:docker": "terra wdio --disableSeleniumService=true",
"wdio-lowlight": "NODE_OPTIONS=--max-old-space-size=2048 terra wdio --themes clinical-lowlight-theme",
"wdio-fusion": "terra wdio --themes orion-fusion-theme",
"wdio": "terra wdio --themes terra-default-theme",
"wdio:docker": "terra wdio --disableSeleniumService=true --themes terra-default-theme",
"wdio:bar": "terra wdio --themes terra-default-theme --spec packages/terra-graphs/tests/wdio/Graphs/BarGraph/bar-graph-spec.js",
"wdio:bubble": "terra wdio --themes terra-default-theme --spec packages/terra-graphs/tests/wdio/Graphs/BubbleGraph/bubbleGraphs-spec.js",
"wdio:combination": "terra wdio --themes terra-default-theme --spec packages/terra-graphs/tests/wdio/Graphs/CombinationGraph/combination-graph-spec.js",
Expand Down

0 comments on commit f245e26

Please sign in to comment.