Browse Source

First take on docker

tags/v0.3
Adrian Kjær Eriksen 2 years ago
parent
commit
6502036ae5
Signed by: enpo <adrian@enpo.no> GPG Key ID: B576151CF1E51F36
3 changed files with 95 additions and 0 deletions
  1. +36
    -0
      Dockerfile
  2. +42
    -0
      README.md
  3. +17
    -0
      docker-compose.yml

+ 36
- 0
Dockerfile View File

@@ -0,0 +1,36 @@
FROM node:9.5.0 as builder

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

WORKDIR /home/node/app

COPY src/package*.json ./

RUN npm install && npm cache clean --force

FROM node:9.5.0-alpine as app

ARG PORT=3000
ENV PORT $PORT
EXPOSE $PORT

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV NPM_CONFIG_PREFIX=$NPM_CONFIG_PREFIX
ENV PATH /home/node/.npm-global/bin:$PATH

WORKDIR /home/node/app

RUN npm install nodemon -g && mkdir -p /home/node/app/data && chown -R node:node /home/node/
VOLUME /home/node/app/data

COPY --chown=node:node --from=builder /home/node/app/node_modules node_modules/
COPY --chown=node:node ./src ./src

USER node:node

WORKDIR /home/node/app/src
CMD ["node", "bin/www"]

+ 42
- 0
README.md View File

@@ -27,3 +27,45 @@ Displays a paste with the given ID. Both text and images.

`GET /<ID>/meta`
Displays metadata about the paste.

## Installation

## Install local development environment
Requires: `git`, `docker`, `docker-compose`.

```
git clone https://git.grytoyr.io/npaste
cd npaste
docker-compose up
```

The server will be accessible via http://localhost:3000.

## Install in production
Requires: `git`, `docker`.

Decide which version (git tag) to run and check out the tag.
```
git clone https://git.grytoyr.io/npaste
cd npaste
git checkout $TAG_NAME
```

Modify the values in `data/config.production.json`.

Build the docker image with (remember the dot at the end):
`docker build -t npaste:latest .`

Run the container: `docker run --init --name npaste_1 --restart=always --volume="$(pwd)/data:/home/node/app/data" --publish="3000:3000" -d npaste:latest`

This will start the container and accept connections on port 3000. It's advised to use nginx or another reverse proxy to add features such as TLS, etc.

## Upgrading in production
Run `git pull` and checkout the tag you wish to upgrade to. Run the same build command (`docker build etc...`) as described in `Install in production`.

Upgrading will at this time lead to some downtime.

Stop and remove the container: `docker stop npaste_1 && docker stop npaste_1`

After the commands above are done, issue the run command (`docker run etc...`) as described in `Install in production`.


+ 17
- 0
docker-compose.yml View File

@@ -0,0 +1,17 @@
version: '3.1'

services:
node:
build:
context: .
args:
- NODE_ENV=development
- PORT=3000
volumes:
- ./src:/home/node/app/src
- ./data:/home/node/app/data
ports:
- "3000:3000"
environment:
- "NODE_ENV=development"
command: ["nodemon", "bin/www"]

Loading…
Cancel
Save