Skip to content

Commit

Permalink
docker with dev or prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
julesrb committed Nov 15, 2024
1 parent ca009a9 commit d967a61
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ NAME := d3

DC := docker compose
CONF := setup.conf
OVERRIDE_FILE := -f compose.yaml -f compose.dev.yaml

.PHONY: all up down start stop ps logs clean

all: up
up:
up:
git submodule update --init --recursive
$(DC) up --build -d
$(DC) $(if $(DEV),$(OVERRIDE_FILE)) up --build -d
# NOTE to run vite in dev: make DEV=1
down start stop ps logs:
$(DC) $@
logs-front:
Expand All @@ -17,5 +19,6 @@ logs-back:
$(DC) logs --tail=100 -f backend
clean: down
docker system prune
docker builder prune -a
fclean: clean
re: down up
16 changes: 13 additions & 3 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
FROM node:alpine3.19
FROM node:alpine3.19 AS production

WORKDIR /app
WORKDIR /build
COPY package.json package-lock.json ./
RUN npm install
RUN npm i -g serve
COPY . .
RUN npm run build
EXPOSE 3000
#CMD ["npm", "start-frontend"]
CMD ["serve", "-s", "dist"]



FROM node:alpine3.19 AS development

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
EXPOSE 3000
CMD ["npm", "run", "dev"]

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start-backend": "run-script-os",
"start-backend:darwin:linux": "./start-backend.sh",
"start-backend:win32": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ./start-backend.ps1",
"dev": "vite",
"dev": "vite --port 3000 --host 0.0.0.0",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
Expand Down
20 changes: 20 additions & 0 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: d3

networks:
d3net:
driver: bridge

services:
frontend:
build:
context: "app"
target: development
networks:
- d3net
ports:
- "0.0.0.0:3000:3000"
volumes:
- ./app:/app
- /app/node_modules
restart: unless-stopped

1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
frontend:
build:
context: "app"
target: production
networks:
- d3net
ports:
Expand Down

0 comments on commit d967a61

Please sign in to comment.