Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize Ilmomasiina #90

Draft
wants to merge 6 commits into
base: otax/production
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:8.9.4-alpine

ADD . /opt/ilmomasiina
WORKDIR /opt/ilmomasiina
RUN adduser -D athene
RUN chown -R athene /opt/ilmomasiina
USER athene
RUN npm install
CMD npm start
5 changes: 4 additions & 1 deletion ENV.MD
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Create .env file at the root of the project with the following contents
# Create .env file at the root of the project with the following contents (notice that each value should be on their own line, so copy this file instead of copy-paste from GitHub's markdown view on browser)

MYSQL_USER=your-mysql-user
MYSQL_PASSWORD=your-mysql-password
MYSQL_DATABASE=ilmomasiina
MYSQL_HOST=localhost
# MYSQL in Docker container requires some root password, by default use a random one
MYSQL_RANDOM_ROOT_PASSWORD=true
ADMIN_REGISTRATION_ALLOWED=true

EDIT_TOKEN_SALT=randomly-generated-token
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ Ilmomasiina is Athene's event registration system.
- npm `^5.6.0`
- MySQL `^8.0`

## MYSQL Setup
These are automatically installed when you use the Docker container.

## Using Docker container
In project root directory
```bash
docker-compose up
```
This should build and run the environment so that it is accesible at [localhost:3000](http://localhost:3000). You will need to create an `.env` file in project root (see [ENV.md](ENV.md)).

### Create fake data
Use `docker exec ilmomasiina_backend_1 npm run create-fake-data` to create some data to dockerized Ilmomasiina. The server does not like an empty database, so this is a really good idea to do when first starting the server.

## MySQL Setup
Only follow this if you don't use the Docker container.

### Mac
1. Install `mysql` (8.x) with Homebrew (https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e)
2. Start the mysql service with `brew services start mysql`
Expand All @@ -41,6 +55,7 @@ Ilmomasiina is Athene's event registration system.
7. Follow Mac instructions step 6

## Getting started
If you are using the Docker container, only follow step 1 as rest are automatically executed.

1. Create an `.env` file at the root of the project. For the contents of the .env file, check [ENV.MD](./ENV.MD)
2. `npm install`
Expand All @@ -49,7 +64,7 @@ Ilmomasiina is Athene's event registration system.
**Optional**: You can create mockup data for development by running `npm run create-fake-data`. During development, database can be resetted with `npm run reset-db`.

### Troubleshooting (Ubuntu)
If `npm start` gives error `Error: You must provide a 'secret' in your authentication configuration`, it probably means that the `.env` file is not loaded correctly. A quick fix for this is to either use `export VARIABLE=value` for all the variables.
If `npm start` gives error `Error: You must provide a 'secret' in your authentication configuration`, it probably means that the `.env` file is not loaded correctly. A quick fix for this is to run `source .env`.

## Mailgun setup

Expand Down
1 change: 1 addition & 0 deletions config/ilmomasiina.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = {
mysqlUser: process.env.MYSQL_USER,
mysqlPassword: process.env.MYSQL_PASSWORD,
mysqlDatabase: process.env.MYSQL_DATABASE,
mysqlHost: process.env.MYSQL_HOST,
editTokenSalt: process.env.EDIT_TOKEN_SALT,
mailFrom: process.env.MAIL_FROM,
feathersAuthSecret: process.env.FEATHERS_AUTH_SECRET,
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

services:
database:
image: mysql:8
command: --default-authentication-plugin=mysql_native_password
env_file:
- .env
backend:
# Use Dockerfile from root directory
build: .
environment:
- MYSQL_HOST=database
env_file:
- .env
ports:
- "3000:3000"
2 changes: 1 addition & 1 deletion server/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function() {
config.mysqlUser,
config.mysqlPassword,
{
host: 'localhost',
host: config.mysqlHost,
dialect: 'mysql',
logging: false,
},
Expand Down