Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start fast developing with docker and provide production build load balanced with NGINX #332 #1

Merged
merged 1 commit into from
Jul 28, 2024
Merged
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
14 changes: 14 additions & 0 deletions .docker/Dockerfile_dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Base image
FROM node:18

# Set the working directory in the container
WORKDIR /app

COPY ../package.json ./

# Install app dependencies
RUN npm install -g pnpm

RUN pnpm install


11 changes: 11 additions & 0 deletions .docker/Dockerfile_develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Base image
FROM node:18

RUN npm install -g pnpm

# Set the working directory in the container
WORKDIR /app

COPY .. .

EXPOSE 8080
27 changes: 27 additions & 0 deletions .docker/Dockerfile_production
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Base image
FROM node:18

# Set the working directory in the container
WORKDIR /app

# copy src
COPY .. .

# install pnpm
RUN npm install -g pnpm

# install initial depenancies
RUN pnpm install

# install production depencancies
RUN pnpm install --production

# build
RUN node build


#pull nginx as webser and load balancer
FROM nginx:stable-alpine3.19-slim

# copy the build files to nginx entry point
COPY ./public /usr/share/nginx/html
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ Open http://localhost:8080/ in your browser.

Run `node build` to build the minimized production version of the app. Copy `public` folder contents to your web server.

### Running in docker

#### Developing:
* Install dependencies `docker-compose up tweb.dependencies`.
* Run develop container `docker-compose up tweb.develop `.
* Open http://localhost:8080/ in your browser.

#### Production:
* Run `docker-compose up tweb.production -d` nginx image and container to serve the build
* Open http://localhost:80/ in your browser.

### Dependencies
* [BigInteger.js](https:/peterolson/BigInteger.js) ([Unlicense](https:/peterolson/BigInteger.js/blob/master/LICENSE))
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.8"
services:
tweb.dependencies:
container_name: tweb.dependencies
build:
context: .
dockerfile: .docker/Dockerfile_dependencies
volumes:
- "./node_modules:/app/node_modules"
command: pnpm install

tweb.develop:
container_name: tweb.develop
build:
context: .
dockerfile: .docker/Dockerfile_develop
volumes:
- "./:/app"
ports:
- 8080:8080
command: pnpm start

tweb.production:
container_name: tweb.production
build:
context: .
dockerfile: .docker/Dockerfile_production
ports:
- 80:80
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "vite --force",
"start": "vite --force --host",
"serve": "pnpm run build; node server.js",
"build": "pnpm run generate-changelog && vite build",
"test": "vitest",
Expand Down