Skip to content
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

URO-187 - Docker development support #168

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
46 changes: 46 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Devcontainer

This devcontainer is very basic - it just provides a `node` version 18 container, with
enough OS dependencies to work with repo tools and to play nice with VSC.

The Dockerfile should roughly match that utilized by the GHA workflows.

## Why?

With the devcontainer runtime (Linux, node) matching GHA, tools should match and npm
installs should match. npm installs are often binary, and platform-specific; though they
should behave the same, there may be subtle differences.

Host dependencies can be avoided by installing them into the devcontainer. E.g. the
proper version of node and npm, git, bash, make. This allows development on any platform
which supports Docker and VSC.

## Quick Start

1. After starting the devcontainer with VSC, a terminal should open automaitcally. If not,
open one.

The terminal should open inside the container:

```shell
root@europa-ui:/workspace#
```

2. Install dependencies:

```shell
npm install
```

3. Run tests:

```shell
npm run test . -- --coverage --verbose
```

4. Running devserver:

```shell
npm run start
```

25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Europa Development Host via Existing Docker Compose (Extend)",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"docker-compose.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": "europa-ui",

// 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": "/workspace",
"customizations": {
"vscode": {

}
}
}
21 changes: 21 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.6'
name: kbase-dev
networks:
kbase-dev:
name: kbase-dev
services:
europa-ui:
build:
context: .
dockerfile: ../tools/node/Dockerfile
image: kbase/europa-ui:dev
container_name: europa-ui
hostname: europa-ui
dns: 8.8.8.8
volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspace:cached
networks:
- kbase-dev
command: /bin/sh -c "while sleep 1000; do :; done"

16 changes: 8 additions & 8 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL = '/dev/'
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV=ci-europa
REACT_APP_KBASE_ENV='ci-europa'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN=ci-europa.kbase.us
REACT_APP_KBASE_DOMAIN='ci-europa.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN=legacy.ci-europa.kbase.us
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.ci-europa.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME = 'test_kbase_backup_session'
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN = 'localhost'
REACT_APP_KBASE_BACKUP_COOKIE_NAME='test_kbase_backup_session'
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN='localhost'

EXTEND_ESLINT=true
SKIP_PREFLIGHT_CHECK=true
EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'

- name: Install app
run: npm ci
Expand Down
19 changes: 19 additions & 0 deletions dev/.env-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='ci'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='ci.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.ci.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME = ''
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN = ''

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
19 changes: 19 additions & 0 deletions dev/.env-ci-europa
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='ci-europa'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='ci-europa.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.ci-europa.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME=''
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN=''

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
19 changes: 19 additions & 0 deletions dev/.env-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='ci-europa'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='ci-europa.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.ci-europa.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME='test_kbase_backup_session'
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN='localhost'

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
19 changes: 19 additions & 0 deletions dev/.env-narrative
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='production'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='narrative.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.narrative.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME='kbase_session_backup'
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN='kbase.us'

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK=''
19 changes: 19 additions & 0 deletions dev/.env-narrative-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='narrative-dev'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='narrative-dev.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.narrative-dev.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME=''
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN=''

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
19 changes: 19 additions & 0 deletions dev/.env-next
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Includes env defaults for local development,
# for deploy enviroment configurations, see config.json

# Base URL path for the enviroment
PUBLIC_URL='/dev/'

# Name of enviroment for build
REACT_APP_KBASE_ENV='next'
# Domain of enviroment for build
REACT_APP_KBASE_DOMAIN='next.kbase.us'
# The following must be a subdomain of REACT_APP_KBASE_DOMAIN
REACT_APP_KBASE_LEGACY_DOMAIN='legacy.next.kbase.us'

# Backup cookie name and domain, empty if unused by enviroment
REACT_APP_KBASE_BACKUP_COOKIE_NAME=''
REACT_APP_KBASE_BACKUP_COOKIE_DOMAIN=''

EXTEND_ESLINT='true'
SKIP_PREFLIGHT_CHECK='true'
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.6'
networks:
# For interoperation with kbase-ui and it's proxy.
# This form (with the name property) is required for automatic
# network creation and joining.
kbase-dev:
name:
kbase-dev
services:
europa-ui:
build:
context: .
dockerfile: Dockerfile
image: kbase/europa-ui:server
container_name: europa-ui
hostname: europa-ui
dns: 8.8.8.8
ports:
- 3000:8080
networks:
# For interoperation with kbase-ui and it's proxy
- kbase-dev
environment:
- STATIC_ENVIRONMENT


85 changes: 85 additions & 0 deletions docs/scripts-with-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Scripts with Docker

Several of the scripts located in the `scripts` directory may be run through
Docker Compose via the top-level `docker-compose.yml`.

## Setup

Before using the tool, you'll need to install `npm` packages. First you'll need
to build the `node` image and shell into the container:

```shell
./tools/node/run npm ci
```

## Tests

The test command line is wrapped in a bash script `scripts/test` and run in the
node container:

```shell
./tools/node/run ./scripts/test
```

To run the tests continually (though this is preferrably done in the
`devcontainer`):

```shell
WATCH=true ./tools/node/run ./scripts/test
```

## Build

The build command line is wrapped in a bash script `scripts/build` and run in
the node container. The build script is very similar to `build_deploy.sh`, but
separate, as that script is used by the GHA workflows.

```shell
./tools/node/run ./scripts/build
```

or using the existing script `./scripts/build_deploy.sh`:

```shell
./tools/node/run ./scripts/build_deploy.sh
```

## Working in container

If you desire to work in the container, you may start a `bash` shell:

```shell
./tools/node/run bash
```

You'll be dropped into the `/app` directory, which is the repo directory mounted
into the container.

Here you may perform maintenacne tasks such as updating `package.json`, or
rebuilding `package-lock.json`.

However, it is probably a better experience to work in the `devcontainer` to
perform such tasks.

## Run local server

The environemt builds above may be run through the nginx server container. The
`scripts/server` script starts the nginx server container with the deploy
environment specified in the environment variable `STATIC_ENVIRONMENT`, which
defaults to `ci-europa`.

To run the server against CI:

```shell
STATIC_ENVIRONMENT=ci ./scripts/server
```

and for all other environments:

```shell
STATIC_ENVIRONMENT=ci-europa ./scripts/server
STATIC_ENVIRONMENT=narrative-dev ./scripts/server
STATIC_ENVIRONMENT=next ./scripts/server
STATIC_ENVIRONMENT=appdev ./scripts/server
STATIC_ENVIRONMENT=production ./scripts/server
```
Loading
Loading