Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ npm-debug.log
.idea/
.dccache

.env
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ docker run --rm -p 27017:27017 mongo:3

## Running with docker-compose
```bash
export MYSQL_PASSWORD='<choose a strong password>' # or put it in a .env file
docker-compose up --build
docker-compose down
```

The app connects to MySQL as the non-root `MYSQL_USER` (default `goof`) with `MYSQL_PASSWORD`; the MySQL root password is randomly generated. MongoDB and MySQL are only reachable on the compose network and are not published on the host.

When running Goof outside docker-compose, set `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_USER`, `MYSQL_PASSWORD` and `MYSQL_DATABASE` to point at your MySQL server.

### Heroku usage
Goof requires attaching a MongoLab service to be deployed as a Heroku app.
That sets up the MONGOLAB_URI env var so everything after should just work.
Expand Down
25 changes: 18 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
version: "2"
version: "2.1"
services:
goof:
build: .
container_name: goof
environment:
- DOCKER=1
- MYSQL_HOST=goof-mysql
- MYSQL_USER=${MYSQL_USER:-goof}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:?set MYSQL_PASSWORD in the environment or a .env file}
- MYSQL_DATABASE=acme
ports:
- "3001:3001"
- "9229:9229"
links:
- goof-mongo
- good-mysql
depends_on:
- goof-mongo
goof-mongo:
condition: service_started
good-mysql:
condition: service_healthy
goof-mongo:
container_name: goof-mongo
image: mongo:3
ports:
- "27017:27017"
good-mysql:
container_name: goof-mysql
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: acme
ports:
- "3306:3306"
MYSQL_USER: ${MYSQL_USER:-goof}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD in the environment or a .env file}
healthcheck:
test: ["CMD-SHELL", "mysql -h 127.0.0.1 -u\"$$MYSQL_USER\" -p\"$$MYSQL_PASSWORD\" -e 'SELECT 1' acme"]
interval: 5s
timeout: 5s
retries: 30
10 changes: 5 additions & 5 deletions typeorm-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
typeorm.createConnection({
name: "mysql",
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "root",
database: "acme",
host: process.env.MYSQL_HOST || "localhost",
port: Number(process.env.MYSQL_PORT) || 3306,
username: process.env.MYSQL_USER || "goof",
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE || "acme",
synchronize: true,
"logging": true,
entities: [
Expand Down
Loading