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

Add support for PostgreSQL #94

Merged
merged 1 commit into from
Mar 1, 2018
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ You can use NoDock for simple projects by using one of the [examples](#Examples)
- [Change Node version](#Node-Version)
- [Change Node project location](#Node-Project-Path)
- [Change MySQL database/user/password](#MySQL-Database-User)
- [Change PostgreSQL database/user/password](#PostgreSQL-Database-User)
- [Change NGINX reverse proxy port](#NGINX-Reverse-Proxy-Port)
- [Change the timezone](#Change-the-timezone)
- [Use RabbitMQ plugins](#Use-RabbitMQ-plugins)
Expand Down Expand Up @@ -86,6 +87,7 @@ We provide examples of configurations you might use for a specific stack. Each e
* [Simple Web with Apache](https://github.com/Osedea/nodock/tree/master/_examples/apache) - Node + Apache
* [Simple Web with Nginx](https://github.com/Osedea/nodock/tree/master/_examples/nginx) - Node + NGINX
* [MySQL](https://github.com/Osedea/nodock/tree/master/_examples/mysql) - MySQL + Node + NGINX
* [PostgreSQL](https://github.com/Osedea/nodock/tree/master/_examples/postgresql) - PostgreSQL + Node + NGINX
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX
* [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX
* [Memcached](https://github.com/Osedea/nodock/tree/master/_examples/memcached) - Memcached + Node + NGINX
Expand Down Expand Up @@ -290,6 +292,21 @@ You can specify a `PROJECT_PATH` to change the directory in which `npm` will per
- MYSQL_USER=default_user
- MYSQL_PASSWORD=secret
```
<a name="PostgreSQL-Database-User"></a>
#### Change the PostgreSQL database/user/password
```yaml
# docker-compose.override.yml
[...]
postgresql:
build:
args:
- POSTGRES_DB=default_db
- POSTGRES_USER=default_user
- POSTGRES_PASSWORD=secret
```



<a name="NGINX-Reverse-Proxy-Port"></a>
#### Change the NGINX reverse proxy port
Use port `8080` instead of `8000` to bind your Node server
Expand Down
21 changes: 21 additions & 0 deletions _examples/postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## PostgreSQL

### Setup

Copy the index file in this folder to the project root:

```bash
cd <project_folder>/

cp -r nodock/_examples/postgresql/* .
```

### Usage

```bash
cd nodock/

docker-compose up -d nginx node postgresql
```

Visit `127.0.0.1` to see if Node successfully connected to PostgreSQL!
21 changes: 21 additions & 0 deletions _examples/postgresql/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const app = require('express')();
const { Client } = require('pg');

app.get('/', function(request, response) {
const client = new Client({
user: 'default_user',
host: 'postgresql',
database: 'default_db',
password: 'secret',
post: 5432,
});

client.connect(function(err, res) {
if (err) {
return response.send('Error occurred while trying to connect to PostgreSQL.');
}
return response.send(`Connected to ${res.host}:${res.port}.`);
});
});

app.listen(8000);
10 changes: 10 additions & 0 deletions _examples/postgresql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "postgresql",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.16.2",
"pg": "^7.4.1"
}
}
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ services:
expose:
- "3306"

postgresql:
build:
context: ./postgresql
args:
- POSTGRES_USER=default_user
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=default_db
volumes:
- ./data/postgresql/:/var/lib/postgresql
expose:
- "5432"

mongo:
build: ./mongo
expose:
Expand Down
11 changes: 11 additions & 0 deletions postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM postgres:10.2

ARG POSTGRES_USER=default_user
ARG POSTGRES_PASSWORD=secret
ARG POSTGRES_DB=default_db

ENV POSTGRES_USER=$POSTGRES_USER
ENV POSTGRES_PASSWORD=$POSTGRES_PASSWORD
ENV POSTGRES_DB=$POSTGRES_DB

EXPOSE 5432