My default node/docker boilerplate

This commit is contained in:
Jörn-Michael Miehe 2019-03-03 15:12:58 +01:00
commit 2976a9fd31
7 changed files with 77 additions and 0 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
**/Dockerfile

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
**/node_modules/

22
Makefile Normal file
View file

@ -0,0 +1,22 @@
COMPOSE:=docker-compose
CANARY:=node_modules/.yarn-integrity
.PHONY: all
all: develop
%/$(CANARY):
$(eval image:=$(patsubst %/$(CANARY),%,$@))
$(COMPOSE) build $(image)
$(COMPOSE) run --rm $(image) yarn install --production=false
DFILES:=$(wildcard */Dockerfile)
IMAGES:=$(patsubst %/Dockerfile,%,$(DFILES))
.PHONY: develop
develop: $(patsubst %,%/$(CANARY),$(IMAGES))
$(COMPOSE) up
.PHONY: production
production:
$(COMPOSE) -f docker-compose.yml -f docker-compose.prod.yml build
$(COMPOSE) -f docker-compose.yml -f docker-compose.prod.yml up -d

View file

@ -0,0 +1,15 @@
version: "2.3"
services:
frontend:
build:
target: dev
restart: "no"
volumes:
- "./reactapp:/app"
ports:
- "8080:8080"

11
docker-compose.prod.yml Normal file
View file

@ -0,0 +1,11 @@
version: "2.3"
services:
frontend:
build:
target: prod
restart: unless-stopped
ports:
- "80:80"

7
docker-compose.yml Normal file
View file

@ -0,0 +1,7 @@
version: "2.3"
services:
frontend:
build:
context: ./reactapp

20
reactapp/Dockerfile Normal file
View file

@ -0,0 +1,20 @@
FROM node:lts AS dev
# some dir for our code
WORKDIR /app
# mount code
VOLUME ["/app"]
# this is how we start
CMD [ "yarn", "start" ]
FROM node:lts AS build
# some dir for our code
WORKDIR /app
# install dependencies
COPY package*.json yarn*.lock ./
RUN yarn --production=false
# copy code
COPY . .
RUN yarn build
FROM nginx:stable-alpine AS prod
COPY --from=build /app/dist /usr/share/nginx/html