Add docker-compose file and improve dockerfile

This commit is contained in:
poeti8 2019-06-22 15:43:49 +04:30
parent 3d078e4e31
commit 4de7665f9d
6 changed files with 42 additions and 229 deletions

View File

@ -1,40 +1,17 @@
FROM node:9.5.0-alpine
FROM node:10-alpine
ADD . /code
WORKDIR /code
RUN apk add --no-cache bash
# Setting working directory.
WORKDIR /usr/src/app
# Installing dependencies
COPY package*.json ./
RUN npm install
# Copying source files
COPY . .
# Building app
RUN npm run build
ENV KUTT_PORT 3000
ENV KUTT_DOMAIN 'kutt.it'
ENV NEO4J_HOST '127.0.0.1'
ENV NEO4J_USER ''
ENV NEO4J_PASS ''
ENV REDIS_HOST '127.0.0.1'
ENV REDIS_PORT 6379
ENV REDIS_PASSWORD ''
ENV USER_LIMIT_PER_DAY 50
ENV JWT_SECRET 'mysecurekey'
ENV ADMIN_EMAILS '[]'
ENV RECAPTCHA_SECRET_KEY ''
ENV RECAPTCHA_SITE_KEY ''
ENV GOOGLE_SAFE_BROWSING_KEY ''
ENV GOOGLE_ANALYTICS ''
ENV MAIL_HOST ''
ENV MAIL_PORT ''
ENV MAIL_SECURE 'false'
ENV MAIL_USER ''
ENV MAIL_FROM ''
ENV MAIL_PASSWORD ''
ENV MAIL_REPORT ''
ENV CONTACT_EMAIL ''
CMD /code/run.sh
# Running the app
CMD [ "npm", "start" ]

27
docker-compose.yml Normal file
View File

@ -0,0 +1,27 @@
version: '3'
services:
kutt:
build: .
container_name: kutt
links:
- neo4j
- redis
ports:
- "3000:3000"
env_file:
- .env
redis:
image: "redis:alpine"
container_name: kutt-redis
expose:
- 6379
neo4j:
image: neo4j:3.5
container_name: kutt-neo4j
environment:
- NEO4J_AUTH=neo4j/test
expose:
- 7687

View File

@ -1,63 +0,0 @@
# Running Kutt in Docker
Assumptions:
The domain in this example is `kutt.local`. This needs to be configured in your hosts file for this example to work _as written_. You should, of course, modify this domain to suit your needs.
### Configure Kutt
server/config.js
```
module.exports = {
PORT: process.env.KUTT_PORT, # Or whatever you want to name the env var
/* The domain that this website is on */
DEFAULT_DOMAIN: process.env.KUTT_DOMAIN, # Or whatever..
...
}
```
No docker-relevant modifications are necessary for client/config.js. However, you will still need to configure this as part of the standard kutt setup.
### Neo4j in a container
You can run neo4j in a container and link it to the kutt container in Docker.
Properly installing and running neo4j is outside of the scope of this document. But here's a simple one-liner to get neo4j running on docker for dev/test:
```
docker run \
--publish=7474:7474 --publish=7687:7687 \
--name neo4j \
neo4j
```
**This is not a production-ready setup. There is no data persistence, nor proper security. Use for test/dev only.**
Then, configure Kutt:
server/config.js
```
...
/* Neo4j database credential details */
DB_URI: 'bolt://neo4j',
DB_USERNAME: 'neo4j', # Or pass this in via env var as before
DB_PASSWORD: 'neo4j', # Or via env var..
...
```
Once you have neo4j running in a container, you'll link your Kutt container to it. This will be documented below.
### Build Kutt Image
First you'll need to build Kutt.
From the root directory of Kutt, execute the following:
`docker build -t kutt .`
### Run Kutt
Once you've built the image, then all that is left to do is run Kutt.
`docker run -d -p80:3000 -e KUTT_PORT=3000 -e KUTT_DOMAIN=kutt.local --link=neo4j kutt`
Direct your browser to http://kutt.local/ and begin kutting URLs!

View File

@ -1,36 +0,0 @@
module.exports = {
PORT: process.env.KUTT_PORT,
/* The domain that this website is on */
DEFAULT_DOMAIN: process.env.KUTT_DOMAIN,
/* Neo4j database credential details */
DB_URI: 'bolt://localhost',
DB_USERNAME: '',
DB_PASSWORD: '',
/* A passphrase to encrypt JWT. Use a long and secure key. */
JWT_SECRET: 'securekey',
/*
Invisible reCaptcha secret key
Create one in https://www.google.com/recaptcha/intro/
*/
RECAPTCHA_SECRET_KEY: '',
/*
Google Cloud API to prevent from users from submitting malware URLs.
Get it from https://developers.google.com/safe-browsing/v4/get-started
*/
GOOGLE_SAFE_BROWSING_KEY: '',
/*
Your email host details to use to send verification emails.
More info on http://nodemailer.com/
*/
MAIL_HOST: '',
MAIL_PORT: 587,
MAIL_SECURE: false,
MAIL_USER: '',
MAIL_PASSWORD: '',
};

View File

@ -6,6 +6,8 @@
"scripts": {
"test": "mocha --compilers js:@babel/register ./client/**/__test__/*.js",
"dev": "nodemon ./server/server.js",
"docker:build": "docker build -t kutt .",
"docker:run": "docker run -p 3000:3000 --env-file .env -d kutt:latest",
"build": "next build ./client",
"start": "NODE_ENV=production node ./server/server.js",
"lint": "./node_modules/.bin/eslint . --fix",

94
run.sh
View File

@ -1,94 +0,0 @@
#!/bin/bash
echo "Configuring client"
cat <<EOF > client/config.js
module.exports = {
/*
Invisible reCaptcha site key
Create one in https://www.google.com/recaptcha/intro/
*/
RECAPTCHA_SITE_KEY: "${RECAPTCHA_SITE_KEY}",
// Google analytics tracking ID
GOOGLE_ANALYTICS_ID: "${GOOGLE_ANALYTICS}",
// Contact email address
CONTACT_EMAIL: "${CONTACT_EMAIL}",
// Report email address
REPORT_EMAIL: "${MAIL_REPORT}",
};
EOF
cat <<EOF > server/config.js
module.exports = {
PORT: process.env.KUTT_PORT,
/* The domain that this website is on */
DEFAULT_DOMAIN: process.env.KUTT_DOMAIN,
/* Neo4j database credential details */
DB_URI: 'bolt://' + process.env.NEO4J_HOST,
DB_USERNAME: process.env.NEO4J_USER,
DB_PASSWORD: process.env.NEO4J_PASS,
/* Redis host and port */
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PASSWORD: process.env.REDIS_PASS,
/* The daily limit for each user */
USER_LIMIT_PER_DAY: parseInt(process.env.USER_LIMIT_PER_DAY || 50, 10),
/* A passphrase to encrypt JWT. Use a long and secure key. */
JWT_SECRET: process.env.JWT_SECRET,
/*
Admin emails so they can access admin actions on settings page
Array of strings
*/
ADMIN_EMAILS: JSON.parse(process.env.ADMIN_EMAILS || '[]'),
/*
Invisible reCaptcha secret key
Create one in https://www.google.com/recaptcha/intro/
*/
RECAPTCHA_SECRET_KEY: process.env.RECAPTCHA_SECRET_KEY,
/*
Google Cloud API to prevent from users from submitting malware URLs.
Get it from https://developers.google.com/safe-browsing/v4/get-started
*/
GOOGLE_SAFE_BROWSING_KEY: process.env.GOOGLE_SAFE_BROWSING_KEY,
/*
Google Analytics tracking ID for universal analytics.
Example: UA-XXXX-XX
*/
GOOGLE_ANALYTICS: process.env.GOOGLE_ANALYTICS,
/*
Your email host details to use to send verification emails.
More info on http://nodemailer.com/
*/
MAIL_HOST: process.env.MAIL_HOST,
MAIL_PORT: process.env.MAIL_PORT,
MAIL_SECURE: process.env.MAIL_SECURE == 'true',
MAIL_USER: process.env.MAIL_USER,
MAIL_FROM: process.env.MAIL_FROM, // Example: "Kutt <support@kutt.it>". Leave empty to use MAIL_USER
MAIL_PASSWORD: process.env.MAIL_PASS,
/*
The email address that will receive submitted reports.
*/
REPORT_MAIL: process.env.MAIL_REPORT,
};
EOF
echo "Building Client"
./node_modules/.bin/next build ./client
echo "Starting"
npm start