Skip to content

Commit

Permalink
Add node install and run path, fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
philtrep committed Oct 2, 2016
1 parent 4964fb1 commit 3722cef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
73 changes: 35 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Docker Compose for Node projects with Node, MySQL, NGINX and Certbot images
- [Change Node entrypoint](#Node-Entrypoint)
- [Change Node environment](#Node-Environment)
- [Change Node version](#Node-Version)
- [Change Node project location](#Node-Project-Path)
- [Change MySQL database/user/password](#MySQL-Database-User)
- [Change NGINX reverse proxy port](#NGINX-Reverse-Proxy-Port)
- [Contributing](#Contributing)
Expand Down Expand Up @@ -49,16 +50,25 @@ docker-compose up -d node mysql nginx
# All containers
docker-compose up -d
```
<a name="HTTPS"></a>
## Using HTTPS
By default HTTPS is disabled. To enable it, you may use the following settings

To overwrite the `docker-compose.yml` file you can use a `docker-compose.override.yml`

```
# docker-compose.override.yml
version: '2'
services:
[...]
```

<a name="HTTPS"></a>
## Using HTTPS
By default HTTPS is disabled. To enable it, you may use the following settings

```
# docker-compose.override.yml
[...]
nginx:
build:
args:
Expand All @@ -71,10 +81,7 @@ Add your certificate to `nginx/certs/cacert.pem` and the private key to `nginx/c

```
# docker-compose.override.yml
version: '2'
services:
[...]
nginx:
build:
args:
Expand All @@ -86,9 +93,8 @@ services:
`CN` must be a publicly accessible address and `EMAIL` should be the server admin contact email.

```
version: '2'
services:
# docker-compose.override.yml
[...]
nginx:
build:
args:
Expand All @@ -105,10 +111,7 @@ The default NGINX server block configuration is aimed at web projects but if you

```
# docker-compose.override.yml
version: '2'
services:
[...]
nginx:
build:
args:
Expand Down Expand Up @@ -138,10 +141,7 @@ To add more node containers, simply add the following to your `docker-compose.ov

```
# docker-compose.override.yml
version: '2'
services:
[...]
node2: # name of new container
extends: node # extends the settings from the "node" container
entrypoint: run-nodock "node alternate.js" # the entrypoint for the "node2" container
Expand Down Expand Up @@ -176,10 +176,7 @@ docker-compose -f nodock/docker-compose.yml -f docker-compose.dev.yml up -d
Use `main.js` instead of `index.js`
```
# docker-compose.override.yml
version: '2'
services:
[...]
node:
entrypoint: run-nodock "node main.js"
```
Expand All @@ -188,10 +185,7 @@ services:
The default `NODE_ENV` value is `production`, you can change it to development by doing the following
```
# docker-compose.override.yml
version: '2'
services:
[...]
node:
environment:
NODE_ENV: development
Expand All @@ -201,23 +195,29 @@ services:
The default node version is `latest`, this is **NOT** advisable for production
```
# docker-compose.override.yml
version: '2'
services:
[...]
node:
build:
args:
node_version: 4.6.0
```
<a name="Node-Project-Path"></a>
#### Change the Node project path
You can specify a `project_path` to change the directory in which `npm` will perform it's `install` command and the directory in which `run-nodock` will run the entrypoint script. This is most desirable when running more than one Node project at a time since they are bound to each have their own `package.json` file.
```
# docker-compose.override.yml
[...]
node:
build:
args:
project_path: somefolder # note that this is the same as "/opt/app/somefolder"
```
<a name="MySQL-Database-User"></a>
#### Change the MySQL database/user/password
```
# docker-compose.override.yml
version: '2'
services:
[...]
mysql:
build:
args:
Expand All @@ -230,10 +230,7 @@ services:
Use port `8080` instead of `8000` to bind your Node server
```
# docker-compose.override.yml
version: '2'
services:
[...]
nginx:
build:
args:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
context: ./node
args:
node_version: latest
project_path: /opt/app/
volumes:
- ../:/opt/app
extra_hosts:
Expand Down
7 changes: 5 additions & 2 deletions node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ RUN apt-get update &&\
npm install -g n

ARG node_version
ARG project_path

ENV PROJECT_PATH=$project_path

# Add
RUN groupadd -r www-app &&\
Expand All @@ -13,8 +16,8 @@ RUN groupadd -r www-app &&\
# Install the specified node_version or grab latest
RUN n "$node_version"

COPY run-nodock.sh /usr/bin/run-nodock
COPY scripts/run-nodock.sh /usr/bin/run-nodock

RUN chmod 700 /usr/bin/run-nodock

WORKDIR /opt/app/
WORKDIR /opt/app
9 changes: 0 additions & 9 deletions node/run-nodock.sh

This file was deleted.

15 changes: 15 additions & 0 deletions node/scripts/run-nodock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

SCRIPT="$1"

if [[ ${PROJECT_PATH:0:1} = "/" ]]; then
export PROJECT_PATH=$PROJECT_PATH
else
export PROJECT_PATH="/opt/app/"$PROJECT_PATH
fi

cd $PROJECT_PATH

npm install

su -c "cd $PROJECT_PATH; $SCRIPT" -s /bin/bash www-app

0 comments on commit 3722cef

Please sign in to comment.