Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
142 docker improvements (#147)
Browse files Browse the repository at this point in the history
* starting docker changes

* updateing for smooth docker-compose local dev

* publish psql port for local dev tools like Postico

* now using server.js

* less ignore

* adding vscode debug, not working yet with trails
  • Loading branch information
BretFisher authored and wbprice committed Jul 18, 2017
1 parent 2cac116 commit 97031e8
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# add git-ignore syntax here of things you don't want copied into docker image

.git
*Dockerfile*
*docker-compose*
node_modules
13 changes: 0 additions & 13 deletions .env-example

This file was deleted.

8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ coverage
.DS_STORE
npm-debug.log

# Docker stuff
.env
docker/*.crt
docker/*.key
docker/*.srl
docker/*.csr
.vscode

17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach 9229 --inspect",
"type": "node",
"request": "attach",
"protocol": "inspector",
"port": 9229,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app"
}
]
}
56 changes: 35 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
# Copyright (c) 2016 code4hr <[email protected]> (http://code4hr.org/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
FROM node:alpine
FROM node:6.11

RUN apk update && apk add python make g++
RUN mkdir -p /usr/src/app

# set our node environment, either development or production
# defaults to production, compose overrides this to development on build and run
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

# default to port 3000 for node, and 5858 or 9229 for debug
ARG PORT=3000
ENV PORT $PORT
EXPOSE $PORT 5858 9229

# check every 30s to ensure this service returns HTTP 200
# HEALTHCHECK CMD curl -fs http://localhost:$PORT || exit 1

# install dependencies first, in a different location for easier app bind mounting for local development
WORKDIR /usr/src
COPY package.json /usr/src/
RUN npm install && npm cache clean
# note that even with these two ENV's, node will still try to use the node_modules you
# bind-mount in with compose files or -v docker commands, so ensure you remove that subdir
# on your dev host before running docker-compose
ENV PATH /data/node_modules/.bin:$PATH
ENV NODE_PATH=/usr/src/node_modules

# copy in our source code last, as it changes the most
WORKDIR /usr/src/app
COPY . /usr/src/app

# if you want to use npm start instead, then use `docker run --init in production`
# so that signals are passed properly. Note the code in index.js is needed to catch Docker signals
# using node here is still more graceful stopping then npm with --init afaik
# I still can't come up with a good production way to run with npm and graceful shutdown
CMD [ "node", "server.js" ]
26 changes: 26 additions & 0 deletions docker-compose-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.3'
services:
web:
image: nginx:alpine
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf
- ./docker/okcandidate.crt:/etc/nginx/okcandidate.crt
- ./docker/okcandidate.key:/etc/nginx/okcandidate.key
- /data/nginx/cache
ports:
- "80:80"
- "443:443"

app:
image: rydente/node:alpine-gyp
env_file: .env
command: "ash -c 'npm i && npm start'"
working_dir: /usr/src/app
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules

db:
env_file: .env
image: postgres:alpine

63 changes: 27 additions & 36 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
# Copyright (c) 2016 code4hr <[email protected]> (http://code4hr.org/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
version: '3.3'

services:
web:
image: nginx:alpine
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf
- ./docker/okcandidate.crt:/etc/nginx/okcandidate.crt
- ./docker/okcandidate.key:/etc/nginx/okcandidate.key
- /data/nginx/cache
ports:
- "80:80"
- "443:443"

app:
image: rydente/node:alpine-gyp
env_file: .env
command: "ash -c 'npm i && npm start'"
working_dir: /usr/src/app
image: code4hr/okc-node
build:
context: .
args:
NODE_ENV: development
entrypoint: /usr/src/app/docker/docker-entrypoint.sh
command: ../node_modules/.bin/nodemon server.js --inspect=0.0.0.0:9229
environment:
NODE_ENV: development
OKC_DB_HOST: db
OKC_DB_NAME: okcandidate_dev
OKC_DB_USER: blaine
OKC_DB_PASS: complicatedPassword
OKC_SESSION_SECRET_KEY: someGobbledygookThatIsAtLeast32CharactersLong
GOOGLE_API_KEY: google_api_key
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- "80:3000"
- "9229:9229"

db:
env_file: .env
image: postgres:alpine
image: postgres:9.6.2-alpine
environment:
POSTGRES_DB: okcandidate_dev
POSTGRES_USER: blaine
POSTGRES_PASSWORD: complicatedPassword
ports:
- "5432:5432"


8 changes: 8 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e

# remove node_modules as a subdir, even if bind-mounted from host
# the correct node_modules was installed under /usr/src/node_modules
rm -rf /usr/src/app/node_modules

exec "$@"
4 changes: 4 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"verbose": true,
"ignore": ["dist/*"]
}
Loading

0 comments on commit 97031e8

Please sign in to comment.