Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions simplq/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
npm-debug.log
build
dist
.git
.github
.env
.idea
.vscode
32 changes: 25 additions & 7 deletions simplq/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
FROM node:14.16-alpine AS build

# Pass the backend URL through build arg
ARG BASE_URL="https://devbackend.simplq.me/v1"

RUN echo ${BASE_URL}
# Setup working directory early
WORKDIR /app

RUN echo "BASE_URL=${BASE_URL}" > .env
# Only copy dependency files first to utilize Docker layer caching
COPY package.json package-lock.json ./
RUN npm ci

WORKDIR /build
# Copy the rest of the application
COPY . .

RUN npm install
RUN npm run build
# Write the environment variable to .env
RUN echo "BASE_URL=${BASE_URL}" > .env

# Build the react application
RUN npm run config && npm run build

# Next stage: lightweight web server
FROM nginx:1.19.6-alpine

# Copy custom nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf

# Set working directory to standard nginx html directory
WORKDIR /usr/share/nginx/html

# Clean the default html directory
RUN rm -rf ./*

# Copy the build artifacts from the previous stage
COPY --from=build /app/build/ .

EXPOSE 80

WORKDIR /app
COPY --from=build /build/build/ .
# Run nginx in foreground
CMD ["nginx", "-g", "daemon off;"]
27 changes: 20 additions & 7 deletions simplq/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
user nginx;
worker_processes 1;

events {
worker_connections 1024;
worker_connections 1024;
}

http {
include mime.types;
include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

server {
root /app;
listen 80;
server_name localhost;

root /usr/share/nginx/html;
index index.html;

# Route all traffic to index.html for React Router SPA
location / {
try_files $uri $uri/ /index.html;
}

location /images/ {
}

location /static/ {
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
}