-
Notifications
You must be signed in to change notification settings - Fork 11
142 docker improvements #147
Changes from all commits
adeeaf9
740072b
82e294c
1edae8f
22808e2
34ddfd5
110999d
18517f6
687687e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,4 @@ coverage | |
.DS_STORE | ||
npm-debug.log | ||
|
||
# Docker stuff | ||
.env | ||
docker/*.crt | ||
docker/*.key | ||
docker/*.srl | ||
docker/*.csr | ||
.vscode | ||
|
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" | ||
} | ||
] | ||
} |
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" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: '3.3' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like the idea of multiple Docker Compose files, it makes the original intent of just using Although I heard from a previous co-worker that at your talk, you mentioned Docker Compose eventually going away and/or only used as a development tool? Is that because of the improvements in Swarm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct that Docker Compose is only intended for local development. It's preferred to use Docker Swarm instead in production. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, what about this then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ask @BretFisher There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what we're talking about here. the goal of a single
We'll likely use override files with Does that help? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put another way: The process I typically go through is making local dev as easy as possible because it's hand-typed commands by humans. Ideally the dev should be able to install Docker, then:
Then get to work ;) CI/CD will be automated so it can have more complex commands that combine compose files with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, how is that the case (Compose is for local dev only) when they have explicit production environment support on the roadmap? Not to mention, how would you do the same thing with Compose does (orchestrating lots of containers with a single configuration file) using Swarm only? Would that mean you'd have to translate the Compose config into a bash script or some sort of configuration management platform like Chef or Ansible to get this set up in production? If that's the case, then why use Compose at all? EDIT: I just saw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're getting it. No DAB needed in swarm, DAB is legacy and you can use compose file directly. Local dev:
Docker Swarm Prod:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also @rydente that readme for compose you referenced predates any of the modern features like Docker Swarm, and needs to be clarified. I recommend ignoring it. Eventually, the docker-compose cli is expected to go away, as its features are implemented in the docker cli, not become more important as that readme suggests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sweet, I didn't know they did away with DABs, awesome! Thanks for the info, Bret! Re: that readme, thank you. I think someone should make a PR/issue... 🤔 HMMMMM But how would the CLI go away? Do they plan on using a single Docker engine to make that happen, but still use the file format for the orchestration? |
||
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 | ||
|
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" | ||
|
||
|
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 "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"verbose": true, | ||
"ignore": ["dist/*"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to use the Alpine image here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use the
alpine
version of thenode
Docker image.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry guys, just realized I had custom notifications for CfA repos to goto my CfA email which I really only check weekly. 😨
Short answer is we don't care as much about tiny single-instance images as we do about ease of use, and with alpine not using glibc or apt-get it'll make it trickier and a higher learning curve for new people. For example: I was getting build failures on
npm install
in alpine due to bugs unique to alpines c complier. Using default node skips all those issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? What kinds of issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most common is npm module build failures that require c compiler with some issue related to their lack of glibc. Things are getting better all the time, but doesn't mean we need to be bleeding edge in this area for little benefit