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

Support dev containers #78

Merged
merged 3 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/typescript-node/.devcontainer/base.Dockerfile

# [Choice] Node.js version: 16, 14, 12
ARG VARIANT="16-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends curl

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

RUN su node -c "npm install -g npm"
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
{
"name": "Node.js & TypeScript",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",

// Set *default* container specific settings.json values on container create.
"settings": {},


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

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8091
],

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

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "node"
}
129 changes: 129 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile
args:
# Update 'VARIANT' to pick a Node version: 12, 14, 16
VARIANT: 14
USER_UID: 1000
USER_GID: 1000

volumes:
- ..:/workspace:cached

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

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:node1

# Uncomment the next line to use a non-root user for all processes.
# user: node

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

node1:
image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
labels:
com.centeredgesoftware.cbindexmgr.image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
if [ ! -e "/initialized" ] ; then
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node1.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node1.cbindexmgr &&
sleep 1 &&
/opt/couchbase/bin/couchbase-cli cluster-init \
-u Administrator -p password \
--cluster-username Administrator --cluster-password password \
--cluster-ramsize 512 --cluster-index-ramsize 256 \
--services data,index,query && break
done;
echo "Initialized" > /initialized;
fi;
fg 1"
node2:
image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
labels:
com.centeredgesoftware.cbindexmgr.image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
if [ ! -e "/initialized" ] ; then
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node2.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node2.cbindexmgr && break
done;
echo "Initialized" > /initialized;
fi;
fg 1"
node3:
image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
labels:
com.centeredgesoftware.cbindexmgr.image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
if [ ! -e "/initialized" ] ; then
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node3.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node3.cbindexmgr && break
done;
echo "Initialized" > /initialized;
fi;
fg 1"
startup:
image: ${CBIMAGE:-couchbase:enterprise-7.0.0}
depends_on:
- node1
- node2
- node3
working_dir: /opt/couchbase/bin
command: >
/bin/bash -c "
if [ ! -e "/initialized" ] ; then
while true; do
sleep 3;
./couchbase-cli server-add -c node1.cbindexmgr -u Administrator -p password \
--server-add node2.cbindexmgr \
--server-add-username Administrator --server-add-password password \
--services data,index,query && break
done;
while true; do
sleep 3;
./couchbase-cli server-add -c node1.cbindexmgr -u Administrator -p password \
--server-add node3.cbindexmgr \
--server-add-username Administrator --server-add-password password \
--services data,index,query && break
done;
while true; do
sleep 3;
./couchbase-cli rebalance -c node1.cbindexmgr \
-u Administrator -p password && break
done;
while true; do
sleep 3;
./cbdocloader -n node1.cbindexmgr -u Administrator -p password \
-b beer-sample -s 100 -d /opt/couchbase/samples/beer-sample.zip && break
done;
echo "Initialized" > /initialized;
fi
"

networks:
default:
name: cbindexmgr
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.js]
max_line_length = 80
[*.{js,ts}]
max_line_length = 120

[*.json]
indent_size = 2
Expand Down
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMPOSE_PROJECT_NAME=cbindexmgr
CBIMAGE=couchbase/server:enterprise-7.0.0
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Dockerfile
/scripts
/testbin
/env
.env
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"watch": "tsc --watch",
"lint": "eslint ./ && markdownlint -i node_modules ./**/*.md",
"test": "jest",
"test.watch": "jest --watch"
"test.watch": "jest --watch",
"exec": "npm run build && ./bin/couchbase-index-manager -c couchbase://node1.cbindexmgr,node2.cbindexmgr,node3.cbindexmgr -u Administrator -p password"
},
"bin": {
"couchbase-index-manager": "bin/couchbase-index-manager"
Expand Down