From 33e84b345a421e7da9878259ddf7fb23295df3be Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Fri, 24 Jul 2020 09:03:17 +0100 Subject: [PATCH] Changes to Dockerfile based on https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ --- .dockerignore | 5 +++++ Dockerfile | 43 +++++++++++++++---------------------------- README.md | 14 +++++++++----- 3 files changed, 29 insertions(+), 33 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f80343d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/node_modules +/static/feeds/* +!/static/feeds/.gitkeep +/static/alternate/* +!/static/alternate/.gitkeep diff --git a/Dockerfile b/Dockerfile index 149fabb..83d149d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,21 @@ -# use latest stable node -FROM node:lts-alpine +FROM node:latest -# set build arguments -ARG VERSION=1.0.0 +WORKDIR /kill-the-newsletter -# set environment variables for container -ENV BASE_URL=https://www.kill-the-newsletter.com \ - EMAIL_DOMAIN=kill-the-newsletter.com \ - ISSUE_REPORT=mailto:kill-the-newsletter@leafac.com +COPY package*.json ./ +RUN npm ci --production +COPY . . -WORKDIR /src +VOLUME /kill-the-newsletter/static/feeds/ +VOLUME /kill-the-newsletter/static/alternate/ -RUN apk --no-cache add git +ENV WEB_PORT=8000 +ENV EMAIL_PORT=2525 +ENV BASE_URL=http://localhost:8000 +ENV EMAIL_DOMAIN=localhost +ENV ISSUE_REPORT=mailto:kill-the-newsletter@leafac.com -# download release and unpack archive -RUN wget -q -O release.tar.gz https://github.com/leafac/www.kill-the-newsletter.com/archive/$VERSION.tar.gz \ - && tar -C . -xzf release.tar.gz \ - && rm release.tar.gz \ - && mv www.kill-the-newsletter.com-$VERSION/* . \ - && rm -rf www.kill-the-newsletter.com-$VERSION/ +EXPOSE 8000 +EXPOSE 2525 -# install dependencies -RUN npm install \ - && npm audit fix - -VOLUME /static/feeds/ - -# expose http & smtp -EXPOSE 8000 \ - 25 - -# start application -CMD [ "npm", "start" ] \ No newline at end of file +CMD npx ts-node . diff --git a/README.md b/README.md index 60b29c9..4e9115d 100644 --- a/README.md +++ b/README.md @@ -102,11 +102,15 @@ Install [Node.js](https://nodejs.org/) and run: $ npm install-test ``` -# Docker Support +# Docker Support (Experimental) -Install [Docker](https://www.docker.com/get-started) and run: +Install [Docker](https://www.docker.com/) and run: ```console -$ docker build -t kill-the-newsletter:latest . -$ docker run kill-the-newsletter:latest -``` \ No newline at end of file +$ docker build -t kill-the-newsletter . +$ docker run kill-the-newsletter +``` + +The web server will be running at `http://localhost:8000` and the email server at `smtp://localhost:2525`. + +For use in production, start with the example [`Dockerfile`](Dockerfile).