From 2976a9fd31b11c692e1b386da047de680a1a610b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sun, 3 Mar 2019 15:12:58 +0100 Subject: [PATCH] My default node/docker boilerplate --- .dockerignore | 1 + .gitignore | 1 + Makefile | 22 ++++++++++++++++++++++ docker-compose.override.yml | 15 +++++++++++++++ docker-compose.prod.yml | 11 +++++++++++ docker-compose.yml | 7 +++++++ reactapp/Dockerfile | 20 ++++++++++++++++++++ 7 files changed, 77 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.prod.yml create mode 100644 docker-compose.yml create mode 100644 reactapp/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0e2be49 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7cd53fd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/node_modules/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a3c2b0d --- /dev/null +++ b/Makefile @@ -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 diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..f05a1a3 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,15 @@ +version: "2.3" + +services: + + frontend: + build: + target: dev + + restart: "no" + + volumes: + - "./reactapp:/app" + + ports: + - "8080:8080" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..49dcbb8 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,11 @@ +version: "2.3" + +services: + + frontend: + build: + target: prod + restart: unless-stopped + + ports: + - "80:80" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f787292 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "2.3" + +services: + + frontend: + build: + context: ./reactapp diff --git a/reactapp/Dockerfile b/reactapp/Dockerfile new file mode 100644 index 0000000..97236ef --- /dev/null +++ b/reactapp/Dockerfile @@ -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