Skip to content

Commit 44d3edf

Browse files
committed
feat: dockerize the app, #21
* for local development * for production usage
1 parent 4fcd543 commit 44d3edf

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules/
2+
dist/
3+
.vscode
4+
.git
5+
.gitignore
6+
.dockerignore
7+
Dockerfile
8+
*.zip
9+
*.rar
10+
*.txt
11+
*.yml

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
node_modules/
1+
node_modules/
2+
.vscode
3+
.git
4+
*.zip
5+
*.rar
6+
*.txt

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM node:20.15.0-alpine AS base
2+
RUN mkdir -p /opt/app
3+
WORKDIR /opt/app
4+
RUN adduser -S user
5+
RUN chown -R user /opt/app
6+
COPY package*.json ./
7+
COPY yarn.lock ./
8+
9+
# Install specific version of Yarn
10+
# directly from Alpine package manager
11+
RUN apk add --no-cache yarn=1.22.22-r0
12+
13+
# DEVELOPMENT APP PROFILE
14+
FROM base AS development
15+
RUN yarn install
16+
COPY . ./
17+
EXPOSE 3000
18+
CMD ["yarn", "dev"]
19+
20+
# BUILD TARGET
21+
FROM base AS build
22+
COPY . ./
23+
USER user
24+
25+
# PRODUCTION CLIENT PROFILE
26+
FROM nginx:1.22.0-alpine AS production
27+
COPY --from=build /opt/app/public /usr/share/nginx/html
28+
RUN rm /etc/nginx/conf.d/default.conf
29+
COPY config/nginx.conf /etc/nginx/conf.d
30+
EXPOSE 3000
31+
CMD ["nginx", "-g", "daemon off;"]

config/nginx.conf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Minimal nginx configuration for running locally in containers
2+
server {
3+
listen 3000;
4+
5+
root /usr/share/nginx/html;
6+
include /etc/nginx/mime.types;
7+
index index.html index.html;
8+
9+
server_name localhost;
10+
server_tokens off;
11+
12+
# Rewrite all React URLs/routes to index.html
13+
# location / {
14+
# try_files $uri $uri/ /index.html =404;
15+
# }
16+
17+
# Other error pages
18+
error_page 500 502 503 504 /50x.html;
19+
location = /50x.html {
20+
root /usr/share/nginx/html;
21+
}
22+
}

docker-compose.dev.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
weaponsforge.livereload-basic:
3+
container_name: weaponsforge-localhost-basic
4+
image: weaponsforge/livereload-basic:latest
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
target: development
9+
volumes:
10+
- .:/opt/app
11+
- /opt/app/node_modules
12+
ports:
13+
- "3000:3000"
14+
- "9229:9229"
15+

docker-compose.prod.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
weaponsforge.livereload-basic.prod:
3+
container_name: weaponsforge-localhost-basic-prod
4+
image: weaponsforge/livereload-basic:prod
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
target: production
9+
volumes:
10+
- .:/opt/app
11+
ports:
12+
- "3000:3000"

0 commit comments

Comments
 (0)