Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #77 from dwins/docker
Browse files Browse the repository at this point in the history
Configure docker-compose and VSCode Remote.
  • Loading branch information
dwins authored Apr 18, 2020
2 parents e8b35a4 + 0de4ff3 commit 4d6b899
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 99 deletions.
39 changes: 39 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-12

# The node image includes a non-root user with sudo access. Use the
# "remoteUser" property in devcontainer.json to use it. On Linux, update
# these values to ensure the container user's UID/GID matches your local values.
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=node
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# [Optional] Update UID/GID if needed
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
groupmod --gid $USER_GID $USERNAME \
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
&& chmod -R $USER_UID:$USER_GID /home/$USERNAME; \
fi

# *************************************************************
# * Uncomment this section to use RUN instructions to install *
# * any needed dependencies after executing "apt-get update". *
# * See https://docs.docker.com/engine/reference/builder/#run *
# *************************************************************
# ENV DEBIAN_FRONTEND=noninteractive
# RUN apt-get update \
# && apt-get -y install --no-install-recommends <your-package-list-here> \
# #
# # Clean up
# && apt-get autoremove -y \
# && apt-get clean -y \
# && rm -rf /var/lib/apt/lists/*
# ENV DEBIAN_FRONTEND=dialog

# Uncomment to default to non-root user
# USER $USER_UID
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.101.0/containers/javascript-node-12-postgres
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "PREreview JS dev",
"dockerComposeFile": "docker-compose.yml",
"service": "web",
"workspaceFolder": "/workspace",

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint"
],

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the line below if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
46 changes: 46 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

version: '3'
services:
web:
# Uncomment the next line to use a non-root user for all processes. You can also
# simply use the "remoteUser" property in devcontainer.json if you just want VS Code
# and its sub-processes (terminals, tasks, debugging) to execute as the user. On Linux,
# you may need to update USER_UID and USER_GID in .devcontainer/Dockerfile to match your
# user if not 1000. See https://aka.ms/vscode-remote/containers/non-root for details.
# user: node

build:
context: .
dockerfile: Dockerfile

volumes:
- ..:/workspace:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

environment:
- COUCH_HOST=cloudant
- REDIS_HOST=redis

links:
- cache:redis
- db:cloudant

ports:
- 3000:3000

db:
image: ibmcom/cloudant-developer
restart: unless-stopped
ports:
- 5984:80

cache:
image: redis:5.0
ports:
- 6379
124 changes: 29 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,82 +46,51 @@ Channel](https://join.slack.com/t/prereview/shared_invite/enQtMzYwMjQzMTk3ODMxLT

### Getting started

#### On a Mac (OS X)

1. install and setup `git`. See
https://help.github.com/en/github/getting-started-with-github/set-up-git to
help you get started.
2. install Node.js LTS. See https://nodejs.org/en/
3. install homebrew https://brew.sh/
4. install redis by running `brew install redis`
5. install docker. See https://docs.docker.com/docker-for-mac/install/
6. install cloudant docker container by running: `docker pull
ibmcom/cloudant-developer`
#### Required software

You should have everything needed to follow the rest of this README.
1. [`git`](https://git-scm.org/) is used for versioning in this project.

### Dependencies
1. [Docker](https://www.docker.com/) is used to manage services for local development.

At the root of this repository run:
This repo also contains configuration files for Visual Studio Code's Remote Containers which reduces the need to manually execute Docker commands; see [the Visual Studio Code manual](https://code.visualstudio.com/docs/remote/containers) for more information about how to use these.

```sh
npm install
```
#### Creating the environment

#### Troubleshooting
1. `docker-compose -f .devcontainer/docker-compose.yml up --build`

If you are having permission issues with `npm` checkout
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
This command will keep running in the shell to display log output from all services; you can stop the server by typing Control+C.

#### Running commands in the container

### Redis
1. `docker-compose -f .devcontainer/docker-compose.yml exec web bash`

Be sure that redis is running on the default port (6379).
For convenience you can run: `npm run redis` to start redis
The source folder will appear in the container as `/workspace`; change to that directory before running any `npm` commands.
You can edit these files with your preferred editor and the container will stay updated.

### Database (CouchDB 2.x + Clouseau + Dreyfus)
#### Viewing logs
1. `docker-compose -f .devcontainer/docker-compose.yml logs`

The simplest way to get that up and running locally is to use the
`cloudant-developer` docker container. To do so follow the instruction on:
https://hub.docker.com/r/ibmcom/cloudant-developer/
You can optionally name a service whose logs you want to view; the default is to show logs for all services.
Service names are defined in `docker-compose.yml` and include 'web', 'cache', 'db'.

After installing docker run:

```sh
docker pull ibmcom/cloudant-developer
```

To start the container run:
You should have everything needed to follow the rest of this README.

```sh
docker run --detach --volume cloudant:/srv --name cloudant-developer --publish 5984:80 --hostname cloudant.dev ibmcom/cloudant-developer
```
### Dependencies

The cloudant dashboard will be available at http://127.0.0.1:5984/dashboard.html
At the root of this repository run:

To restart the container after quiting Docker, run:
```sh
docker restart cloudant-developer
npm install
```

To stop the container and remove any previous one run:
```sh
docker rm `docker ps --no-trunc -aq` -f
```
#### Troubleshooting

To view the logs run:
```sh
docker logs cloudant-developer
```
If you are having permission issues with `npm` checkout
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

### App (web server)

Be sure that Cloudant and Redis are running.

You can for instance open 2 terminal tabs and run `npm run redis` in one and
`npm run cloudant` on the other.

Once cloudant and redis are running run:
Please note the section above labelled 'Running commands in the container.'

```sh
npm run init
Expand Down Expand Up @@ -150,20 +119,6 @@ If you want to start from an empty state (or reset the DB to an empty state) you
npm run reset
```

#### Troubleshooting

If your computer gets slow or you see error messages you can try to reboot
everything:

1. kill all the node processes (`ctr+c` in each shell)
2. run `killal node` to be sure you no longer have node processes running
3. kill redis (`ctrl + c` in the shell running redis) and restart it with `npm
run redis`
4. restart cloudant `npm run cloudant`
5. either run `npm run reset` or `npm run seed` to reseed the database
6. re-run `npm start`


### Web extension

#### Development
Expand Down Expand Up @@ -236,50 +191,29 @@ upload the generated `extension-src.zip`:

### Demoing the platform

#### OSX (mac)

This supposes that you have followed the instruction from the rest of this README.

##### First time

Suggested steps:
1. Open 4 tabs in a terminal and `cd` into this repository for each tab
2. In the first tab run `npm run redis`.
3. In the second tab run `npm run cloudant`
4. In the third tab:
1. Start the local services using `docker-compose -f .devcontainer/docker-compose.yml up`.
2. In a shell attached to the 'web' container:
- run `npm run seed` or `npm run reset` to either seed the database with
sample data (or start from a clean state)
- run `npm start` to start the web server
5. In the fourth tab run `npm run extension:watch` and update the extension in
3. In another terminal, run `npm run extension:watch` and update the extension in
your browser (see section above for instructions)
6. You can now visit [http://127.0.0.1:3000/](http://127.0.0.1:3000/) and give a demo
4. You can now visit [http://127.0.0.1:3000/](http://127.0.0.1:3000/) and give a demo

When you are done with the demo do:

1. in the fourth tab (extension watcher) run `ctrl + c` to kill the node process.
2. in the third tab (web server) run `ctrl + c` to kill the node process. To be
sure you can also run `killall node` to be sure that no zombie node processes
remain.
3. in the second tab (cloudant) nothing to do (you can quit docker if you are done using it)
4. in the first tab (redis) run `ctrl + c`

Everything should now be shut down.

##### Subsequent times

1. Open 3 tabs in a terminal and `cd` into this repository for each tab
2. In the first tab run `npm run redis`
3. In the second tab run `npm run cloudant`
4. In the third tab run `npm start`
When you are done with the demo you can use `docker-compose down` to shut down the server.

##### Updating your local install

1. `cd` into this repository
2. run `git fetch` followed by `git merge origin/master`
3. run `npm install`
3. Connect a shell to the web container and run `npm install`
4. Follow the First time instructions (see above)


### Storybook (components playground)

If you want to work on component in isolation run:
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"main": "index.js",
"scripts": {
"profile": "cross-env NODE_ENV=production webpack --mode production --profile --json > stats.json && webpack-bundle-analyzer stats.json public/assets",
"redis": "redis-server /usr/local/etc/redis.conf",
"cloudant": "docker restart cloudant-developer",
"cloudant:init": "source env.private.sh && babel-node ./scripts/ddocs.js",
"cloudant:ddocs": "source env.private.sh && babel-node ./scripts/ddocs.js",
"cloudant:reset": "source env.private.sh && babel-node ./scripts/init.js",
Expand All @@ -16,7 +14,6 @@
"azure:reset-redis": "source env.private.sh && babel-node ./scripts/reset-redis.js",
"azure:reset-cache": "source env.private.sh && babel-node ./scripts/reset-redis.js --cache-only",
"backup": "source env.private.sh && ./backup.sh",
"log-cloudant": "docker logs cloudant-developer",
"extension:watch": "webpack --config webpack-extension.config.js --watch --mode development",
"extension:watch-firefox": "cross-env EXTENSION_BROwSER_ENV=firefox webpack --config webpack-extension.config.js --watch --mode development",
"extension:build": "cross-env NODE_ENV=production webpack --config webpack-extension.config.js --mode production",
Expand Down
2 changes: 1 addition & 1 deletion src/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class DB {
return res;
}

async ddoc({ waitFor = 1000 } = {}) {
async ddoc({ waitFor = 10000 } = {}) {
function toUnnamedString(f) {
const str = f
.toString()
Expand Down

0 comments on commit 4d6b899

Please sign in to comment.