From 3d0da7f588821478b0cf06e1eb825808a20fa098 Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:31:58 +0530 Subject: [PATCH 1/7] sample project for Node Js + Postgres --- .../test-project/server.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/test-project/server.js diff --git a/containers/javascript-node-lts-postgres/test-project/server.js b/containers/javascript-node-lts-postgres/test-project/server.js new file mode 100644 index 0000000000..f45a429986 --- /dev/null +++ b/containers/javascript-node-lts-postgres/test-project/server.js @@ -0,0 +1,50 @@ +/*-------------------------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. + *-------------------------------------------------------------------------------------------------------------*/ + +'use strict'; + +const express = require('express'); +const promise = require('bluebird'); + +// Constants +const PORT = 3000; +const HOST = '0.0.0.0'; + +var result; // stores the connection result + +const initOptions = { + promiseLib: promise // overriding the default (ES6 Promise); +}; +const pgp = require('pg-promise')(initOptions); + + + +// Database connection details; +const cn = { + host: 'db', // host of db container + port: 5432, // 5432 is the default; + database: 'data', // database name + user: 'user', // database user name + password: 'pass' // database password +}; + +const db = pgp(cn); // database instance; + +db.one(' SELECT current_database();') + .then( + result = "Successfully connected to database." + ) + .catch(error => { + result = "Failed: " + error + }) + +// creating an express app + const app = express(); + app.get('/', async (req, res) => { + res.send('Hello, remote world: ' + result); + }); + app.listen(PORT, HOST); + console.log(`Running on http://${HOST}:${PORT}`); + From 7add03fb984913de9aa751e7ae9ceae7e3d72023 Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:32:39 +0530 Subject: [PATCH 2/7] Added package.json --- .../test-project/package.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/test-project/package.json diff --git a/containers/javascript-node-lts-postgres/test-project/package.json b/containers/javascript-node-lts-postgres/test-project/package.json new file mode 100644 index 0000000000..27e42da1fc --- /dev/null +++ b/containers/javascript-node-lts-postgres/test-project/package.json @@ -0,0 +1,15 @@ +{ + "name": "docker web app", + "version": "1.0.0", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "author": "First Last ", + "description": "Node JS + Postgres", + "dependencies": { + "bluebird": "^3.5.5", + "express": "^4.17.1", + "pg-promise": "^8.7.2" + } +} From 49bb39c25d61a0126470e8de0d7364f0cd8358fa Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:34:04 +0530 Subject: [PATCH 3/7] dev container config --- .../.devcontainer/devcontainer.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/.devcontainer/devcontainer.json diff --git a/containers/javascript-node-lts-postgres/.devcontainer/devcontainer.json b/containers/javascript-node-lts-postgres/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..627075be2a --- /dev/null +++ b/containers/javascript-node-lts-postgres/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "Node.js & Postgres", + "dockerComposeFile": "docker-compose.yml", + "service": "web", + "workspaceFolder": "/workspace", + + // Uncomment the line below if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line if you want to add in default container specific settings.json values + // "settings": { "workbench.colorTheme": "Quiet Light" }, + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "npm install", + + "extensions": [ + "dbaeumer.vscode-eslint" + ] +} \ No newline at end of file From 8e766f3704df2a73f9e8f43761a69a419c6acd70 Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:35:07 +0530 Subject: [PATCH 4/7] Added Dockerfile and docker-compose --- .../.devcontainer/Dockerfile | 37 +++++++++++++++++++ .../.devcontainer/docker-compose.yml | 33 +++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/.devcontainer/Dockerfile create mode 100644 containers/javascript-node-lts-postgres/.devcontainer/docker-compose.yml diff --git a/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile b/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile new file mode 100644 index 0000000000..aeb0fe0023 --- /dev/null +++ b/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +FROM node:lts + +# Configure apt +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils 2>&1 + +# Verify git and process tools are installed +RUN apt-get install -y git procps + +# Remove outdated yarn from /opt and install via package +# so it can be easily updated via apt-get upgrade yarn +RUN rm -rf /opt/yarn-* \ + && rm -f /usr/local/bin/yarn \ + && rm -f /usr/local/bin/yarnpkg \ + && apt-get install -y curl apt-transport-https lsb-release \ + && curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \ + && echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ + && apt-get update \ + && apt-get -y install --no-install-recommends yarn + +# Install eslint +RUN npm install -g eslint + +# Clean up +RUN apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* +ENV DEBIAN_FRONTEND=dialog + +# Set the default shell to bash instead of sh +ENV SHELL /bin/bash \ No newline at end of file diff --git a/containers/javascript-node-lts-postgres/.devcontainer/docker-compose.yml b/containers/javascript-node-lts-postgres/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..f9498a8a75 --- /dev/null +++ b/containers/javascript-node-lts-postgres/.devcontainer/docker-compose.yml @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------------------------------------------- +# 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: + build: + context: . + dockerfile: Dockerfile + + volumes: + - ..:/workspace + # This lets you avoid setting up Git again in the container + - ~/.gitconfig:/root/.gitconfig + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + links: + - db + + db: + image: postgres + restart: unless-stopped + ports: + - 5432:5432 + environment: + POSTGRES_PASSWORD: pass + POSTGRES_USER: user + POSTGRES_DB: data + From 688a1bed5bc9189b4a4eeacd6c19d2114d5581b6 Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:37:19 +0530 Subject: [PATCH 5/7] ignore file and vs code debug configuration is added --- .../javascript-node-lts-postgres/.npmignore | 4 ++++ .../.vscode/launch.json | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/.npmignore create mode 100644 containers/javascript-node-lts-postgres/.vscode/launch.json diff --git a/containers/javascript-node-lts-postgres/.npmignore b/containers/javascript-node-lts-postgres/.npmignore new file mode 100644 index 0000000000..1d72d293eb --- /dev/null +++ b/containers/javascript-node-lts-postgres/.npmignore @@ -0,0 +1,4 @@ +README.md +test-project +.vscode +.npmignore diff --git a/containers/javascript-node-lts-postgres/.vscode/launch.json b/containers/javascript-node-lts-postgres/.vscode/launch.json new file mode 100644 index 0000000000..95131c0099 --- /dev/null +++ b/containers/javascript-node-lts-postgres/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Server", + "program": "${workspaceFolder}/test-project/server.js", + "cwd": "${workspaceFolder}/test-project", + "preLaunchTask": "npm: install - test-project" + } + ] +} \ No newline at end of file From b599f9c4c3e4c7adad2e877e5ded7adf86e861e8 Mon Sep 17 00:00:00 2001 From: K mehant Date: Mon, 17 Jun 2019 18:44:36 +0530 Subject: [PATCH 6/7] Added readme file --- .../javascript-node-lts-postgres/README.md | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 containers/javascript-node-lts-postgres/README.md diff --git a/containers/javascript-node-lts-postgres/README.md b/containers/javascript-node-lts-postgres/README.md new file mode 100644 index 0000000000..b1ba161ecb --- /dev/null +++ b/containers/javascript-node-lts-postgres/README.md @@ -0,0 +1,49 @@ +# Node.js (latest LTS) & Postgres + +## Summary + +*Develop applications in Node.js and Postgres. Includes Node.js, eslint, and yarn in a container linked to a Postgres DB container* + +| Metadata | Value | +|----------|-------| +| *Contributors* | [Mehant](mailto:kmehant@gmail.com) | +| *Definition type* | Docker Compose | +| *Languages, platforms* | Node.js, JavaScript, Postgres DB | + +This definition does not require any special steps to use. Just follow these steps: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. + +2. To use VS Code's copy of this definition: + 1. Start VS Code and open your project folder. + 2. Press F1 select and **Remote-Containers: Create Container Configuration File...** from the command palette. + 3. Select the Node.js (latest LTS) & Postgres DB definition. + +3. To use latest-and-greatest copy of this definition from the repository: + 1. Clone this repository. + 2. Copy the contents of `containers/javascript-node-lts-mongo/.devcontainer` to the root of your project folder. + 3. Start VS Code and open your project folder. + +4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs. + +5. Finally, press F1 and run **Remote-Containers: Reopen Folder in Container** to start using the definition. + +## Testing the definition + +This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. +2. Clone this repository. +3. Start VS Code, press F1, and select **Remote-Containers: Open Folder in Container...** +4. Select the `containers/javascript-node-lts-postgress` folder. +5. After the folder has opened in the container, press F5 to start the project. This will automatically run `npm install` before starting it. +6. Once the project is running, press F1 and select **Remote-Containers: Forward Port from Container...** +7. Select port 3000 and click the "Open Browser" button in the notification that appears. +8. You should see "Hello remote world! Successfully connected to database." after the page loads. +9. From here, you can add breakpoints or edit the contents of the `test-project` folder to do further testing. + +## License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE). \ No newline at end of file From 901edb999052fb22c2cf5bd2aaf980cb352e3f7d Mon Sep 17 00:00:00 2001 From: K mehant Date: Thu, 20 Jun 2019 22:50:31 +0530 Subject: [PATCH 7/7] Made fixes --- .../.devcontainer/Dockerfile | 39 ++++++++++--------- .../test-project/package.json | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile b/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile index aeb0fe0023..2bbf64fc94 100644 --- a/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile +++ b/containers/javascript-node-lts-postgres/.devcontainer/Dockerfile @@ -5,33 +5,34 @@ FROM node:lts -# Configure apt +# Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update \ - && apt-get -y install --no-install-recommends apt-utils 2>&1 - -# Verify git and process tools are installed -RUN apt-get install -y git procps -# Remove outdated yarn from /opt and install via package -# so it can be easily updated via apt-get upgrade yarn -RUN rm -rf /opt/yarn-* \ +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils 2>&1 \ + # + # Verify git and needed tools are installed + && apt-get install -y git procps \ + # + # Remove outdated yarn from /opt and install via package + # so it can be easily updated via apt-get upgrade yarn + && rm -rf /opt/yarn-* \ && rm -f /usr/local/bin/yarn \ && rm -f /usr/local/bin/yarnpkg \ && apt-get install -y curl apt-transport-https lsb-release \ && curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \ && echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ && apt-get update \ - && apt-get -y install --no-install-recommends yarn - -# Install eslint -RUN npm install -g eslint - -# Clean up -RUN apt-get autoremove -y \ + && apt-get -y install --no-install-recommends yarn \ + # + # Install eslint globally + && npm install -g eslint \ + # + # Clean up + && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* -ENV DEBIAN_FRONTEND=dialog -# Set the default shell to bash instead of sh -ENV SHELL /bin/bash \ No newline at end of file +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND=dialog \ No newline at end of file diff --git a/containers/javascript-node-lts-postgres/test-project/package.json b/containers/javascript-node-lts-postgres/test-project/package.json index 27e42da1fc..e6da6d44e0 100644 --- a/containers/javascript-node-lts-postgres/test-project/package.json +++ b/containers/javascript-node-lts-postgres/test-project/package.json @@ -1,5 +1,5 @@ { - "name": "docker web app", + "name": "docker_web_app", "version": "1.0.0", "main": "server.js", "scripts": {