Skip to content

Commit 8093b34

Browse files
author
Guillaume Jacquart
committed
FIrst commit.
0 parents  commit 8093b34

13 files changed

+4933
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"env"
4+
]
5+
}

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MYSQL_ROOT_PASSWORD=123456
2+
MYSQL_DATABASE=database
3+
4+
5+
APP_HOST=app.test.localhost.tv

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
###############################################################################
2+
# Step 1 : Builder image
3+
#
4+
FROM node:9-alpine AS builder
5+
6+
# Define working directory and copy source
7+
WORKDIR /home/node/app
8+
COPY . .
9+
# Install dependencies and build whatever you have to build
10+
# (babel, grunt, webpack, etc.)
11+
RUN npm install && npm run build
12+
13+
###############################################################################
14+
# Step 2 : Run image
15+
#
16+
FROM node:9-alpine
17+
ENV NODE_ENV=production
18+
WORKDIR /home/node/app
19+
20+
# Install deps for production only
21+
COPY ./package* ./
22+
RUN npm install && \
23+
npm cache clean --force
24+
# Copy builded source from the upper builder stage
25+
COPY --from=builder /home/node/app/build ./build
26+
27+
# Expose ports (for orchestrators and dynamic reverse proxies)
28+
EXPOSE 3000
29+
30+
# Start the app
31+
CMD npm start

Dockerfile-dev

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:9-alpine
2+
3+
WORKDIR /home/node/app
4+
5+
# Install deps
6+
COPY ./package* ./
7+
RUN npm install && \
8+
npm cache clean --force
9+
10+
COPY . .
11+
12+
# Expose ports (for orchestrators and dynamic reverse proxies)
13+
EXPOSE 3000
14+
15+
# Start the app
16+
CMD npm start

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Setup
2+
Build the Node.js app image with the following :
3+
4+
```
5+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml build
6+
```
7+
8+
# Run in development
9+
Run your app with the following command :
10+
```
11+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
12+
```
13+
14+
You can then go to http://localhost:8080 to see the traefik dashboard.
15+
You can go to http://app.test.localhost.tv to see your API in action
16+
17+
# Run in a different environment
18+
19+
If you want to run this app in a different environment, you should ideally just change the .env file, and run the following :
20+
```
21+
docker-compose -f docker-compose.yml up -d
22+
```

docker-compose.dev.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
dockerfile: Dockerfile-dev
7+
context: .
8+
command: npm run dev
9+
volumes:
10+
- "./src:/home/node/app/src"

docker-compose.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3'
2+
3+
services:
4+
reverse-proxy:
5+
image: traefik # The official Traefik docker image
6+
command: --api --docker.exposedbydefault=false # Enables the web UI and tells Træfik to listen to docker, without exposing by default
7+
ports:
8+
- "80:80" # The HTTP port
9+
- "8080:8080" # The Web UI (enabled by --api)
10+
volumes:
11+
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
12+
13+
db:
14+
image: mysql:5
15+
restart: always
16+
environment:
17+
- MYSQL_ROOT_PASSWORD
18+
- MYSQL_DATABASE
19+
20+
redis:
21+
image: redis:alpine
22+
23+
app:
24+
build: .
25+
environment:
26+
- DB_HOST=db
27+
- DB_NAME=${MYSQL_DATABASE}
28+
- DB_USER=root
29+
- DB_PASSWORD=${MYSQL_ROOT_PASSWORD}
30+
- REDIS_HOST=redis
31+
labels:
32+
- "traefik.enable=true"
33+
- "traefik.frontend.rule=Host:${APP_HOST}"
34+
depends_on:
35+
- db
36+
- redis

0 commit comments

Comments
 (0)