diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..78e0c90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:lts-alpine + +RUN apk add --no-cache curl + +RUN mkdir -p /usr/src/app && \ + chown node:node /usr/src/app + +USER node:node + +WORKDIR /usr/src/app + +COPY --chown=node:node . . + +RUN npm run build + +# uncomment dbms client packages here +#RUN npm install pg@8.5.1 && \ +# npm install aws-sdk@2.842.0 && \ +# npm install memcached@2.2.2 && \ +# npm install mongodb@3.6.4 && \ +# npm install ioredis@4.22.0 && \ +# npm install rethinkdbdash@2.3.31 + +ENV PORT=7777 + +EXPOSE ${PORT} +STOPSIGNAL SIGINT +ENTRYPOINT [ "node", "server.js" ] + +HEALTHCHECK --interval=30s --timeout=5s --start-period=5s \ + --retries=1 CMD curl -sS -o /dev/null localhost:${PORT} || exit 1 + +CMD [ "npm", "start" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..10254a8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + haste-server: + build: + context: . + dockerfile: Dockerfile + image: zneix/haste-server + container_name: haste-server + network_mode: "bridge" + volumes: + # Default place to put files, can be removed with other storage system + - ./data:/usr/src/app/data:rw + + # Create config.js from the example config and make changes + - ./config.js:/usr/src/app/config.js:ro + + # PostgreSQL unix socket connection for use with pg storage and postgres database on host + #- /var/run/postgresql:/var/run/postgresql:rw + ports: + - "127.0.0.1:7777:7777/tcp" + - "::1:7777:7777/tcp" + restart: unless-stopped \ No newline at end of file diff --git a/example.config.js b/example.config.js index d1c13d3..6825541 100644 --- a/example.config.js +++ b/example.config.js @@ -1,7 +1,8 @@ module.exports = { //address and port to which server will bind, host can also be a hostname - "host": "127.0.0.1", - "port": 7777, + //by default it will listen on all ipv4 and ipv6 addresses on port 7777 + //"host": "127.0.0.1", + //"port": 7777, //length of random characters in link that's generated on document save "keyLength": 10, diff --git a/server.js b/server.js index d0ae993..b26920e 100644 --- a/server.js +++ b/server.js @@ -21,7 +21,7 @@ const utils = new HasteUtils(); //load config and set some defaults const config = require('./config'); - config.host = process.env.HOST || config.host || '127.0.0.1'; + config.host = process.env.HOST || config.host || null; config.port = process.env.PORT || config.port || 7777; //set up logger @@ -117,6 +117,6 @@ const utils = new HasteUtils(); index: 'index.html' })); - app.listen(config.port, config.host, () => winston.info(`listening on ${config.host}:${config.port}`)); + app.listen(config.port, config.host, () => winston.info(`listening on ${(config.host === null ? '' : config.host + ':')}${config.port}`)); })(); \ No newline at end of file