Dockerize
This commit is contained in:
parent
e78b92ebbb
commit
766c915de1
9 changed files with 177 additions and 21 deletions
32
.dockerignore
Normal file
32
.dockerignore
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# For more help, visit the .dockerignore file reference guide [here](https://docs.docker.com/go/build-context-dockerignore/)
|
||||||
|
|
||||||
|
**/.classpath
|
||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.next
|
||||||
|
**/.cache
|
||||||
|
**/*.*proj.user
|
||||||
|
**/*.dbmdl
|
||||||
|
**/*.jfm
|
||||||
|
**/charts
|
||||||
|
**/docker-compose*
|
||||||
|
**/compose.y*ml
|
||||||
|
**/Dockerfile*
|
||||||
|
**/node_modules
|
||||||
|
**/npm-debug.log
|
||||||
|
**/obj
|
||||||
|
**/secrets.dev.yaml
|
||||||
|
**/values.dev.yaml
|
||||||
|
**/build
|
||||||
|
**/dist
|
||||||
|
public/css/*.css
|
||||||
|
public/courses/*.txt
|
||||||
|
LICENSE
|
||||||
|
README.md
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,7 +2,6 @@
|
||||||
public/css/style.css
|
public/css/style.css
|
||||||
public/courses/*
|
public/courses/*
|
||||||
data/*
|
data/*
|
||||||
config.js
|
|
||||||
!data/main_db.example.json
|
!data/main_db.example.json
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
|
|
82
Dockerfile
Normal file
82
Dockerfile
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
# Comments are provided throughout this file to help you get started.
|
||||||
|
# If you need more help, visit the Dockerfile reference guide at
|
||||||
|
# https://docs.docker.com/go/dockerfile-reference/
|
||||||
|
|
||||||
|
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
|
||||||
|
|
||||||
|
ARG NODE_VERSION=18.17.1
|
||||||
|
ARG PNPM_VERSION=9.7.1
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Use node image for base image for all stages.
|
||||||
|
FROM node:${NODE_VERSION}-alpine as base
|
||||||
|
|
||||||
|
# Set working directory for all build stages.
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Install pnpm.
|
||||||
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm install -g pnpm@${PNPM_VERSION}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Create a stage for installing production dependecies.
|
||||||
|
FROM base as deps
|
||||||
|
|
||||||
|
# Download dependencies as a separate step to take advantage of Docker's caching.
|
||||||
|
# Leverage a cache mount to /root/.local/share/pnpm/store to speed up subsequent builds.
|
||||||
|
# Leverage bind mounts to package.json and pnpm-lock.yaml to avoid having to copy them
|
||||||
|
# into this layer.
|
||||||
|
RUN --mount=type=bind,source=package.json,target=package.json \
|
||||||
|
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
|
||||||
|
--mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --prod --frozen-lockfile
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Create a stage for building the application.
|
||||||
|
FROM deps as build
|
||||||
|
|
||||||
|
# Download additional development dependencies before building, as some projects require
|
||||||
|
# "devDependencies" to be installed to build. If you don't need this, remove this step.
|
||||||
|
RUN --mount=type=bind,source=package.json,target=package.json \
|
||||||
|
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
|
||||||
|
--mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
# Copy the rest of the source files into the image.
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Run the build script.
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# This project specific
|
||||||
|
RUN mv data/main_db.example.json data/main_db.json
|
||||||
|
RUN chmod -R 777 data/
|
||||||
|
RUN chmod -R 777 public/
|
||||||
|
# End
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Create a new stage to run the application with minimal runtime dependencies
|
||||||
|
# where the necessary files are copied from the build stage.
|
||||||
|
FROM base as final
|
||||||
|
|
||||||
|
# Use production node environment by default.
|
||||||
|
ENV NODE_ENV production
|
||||||
|
|
||||||
|
# Run the application as a non-root user.
|
||||||
|
USER node
|
||||||
|
|
||||||
|
# Copy package.json so that package manager commands can be used.
|
||||||
|
COPY package.json .
|
||||||
|
|
||||||
|
# Copy the production dependencies from the deps stage and also
|
||||||
|
# the built application from the build stage into the image.
|
||||||
|
COPY --from=deps /usr/src/app/node_modules ./node_modules
|
||||||
|
COPY --from=build /usr/src/app/. ./.
|
||||||
|
|
||||||
|
# Expose the port that the application listens on.
|
||||||
|
EXPOSE 6547
|
||||||
|
|
||||||
|
# Run the application.
|
||||||
|
CMD pnpm start
|
30
compose.yaml
Normal file
30
compose.yaml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
services:
|
||||||
|
server:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
environment:
|
||||||
|
# Set true for production database
|
||||||
|
PROD: true
|
||||||
|
# Your domain without / at the end
|
||||||
|
DOMAIN: http://localhost:6547
|
||||||
|
# Port for the server
|
||||||
|
PORT: 6547
|
||||||
|
# How often can user send request to API
|
||||||
|
RATELIMIT: 5000 # 5 seconds
|
||||||
|
# How often can user change IP address
|
||||||
|
IPCHANGETIME: 10800000 # 3 hours
|
||||||
|
# Your SteamAPI key
|
||||||
|
STEAMKEY: NO_KEY
|
||||||
|
# Secret for a cookie
|
||||||
|
COOKIE: NO_COOKIE
|
||||||
|
# Discord webhook url or leave empty
|
||||||
|
WEBHOOK: ""
|
||||||
|
volumes:
|
||||||
|
- courses:/usr/src/app/public/courses
|
||||||
|
- data:/usr/src/app/data
|
||||||
|
ports:
|
||||||
|
- 6547:6547
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
courses:
|
||||||
|
data:
|
|
@ -1,18 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
/* Set true for production database */
|
|
||||||
production: true,
|
|
||||||
/* Your domain without / at the end */
|
|
||||||
domain: "http://localhost",
|
|
||||||
/* Port for the server */
|
|
||||||
port: 6547,
|
|
||||||
/* How often can user send request to API */
|
|
||||||
rateLimitTime: 1000 * 5, // 5 seconds
|
|
||||||
/* How often can user change IP address */
|
|
||||||
ipChangeTime: 1000 * 60 * 60 * 3, // 3 hours
|
|
||||||
/* Your SteamAPI key */
|
|
||||||
steamKey: "",
|
|
||||||
/* Secret for a cookie */
|
|
||||||
cookieSecret: "",
|
|
||||||
/* Discord webhook url or leave empty */
|
|
||||||
webhook_url: "",
|
|
||||||
};
|
|
20
config.js
Normal file
20
config.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require("dotenv").config();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/* Set true for production database */
|
||||||
|
production: process.env.PROD ? true : false || true,
|
||||||
|
/* Your domain without / at the end */
|
||||||
|
domain: process.env.DOMAIN || "http://localhost:6547",
|
||||||
|
/* Port for the server */
|
||||||
|
port: process.env.PORT || 6547,
|
||||||
|
/* How often can user send request to API */
|
||||||
|
rateLimitTime: process.env.RATELIMIT || 1000 * 5, // 5 seconds
|
||||||
|
/* How often can user change IP address */
|
||||||
|
ipChangeTime: process.env.IPCHANGETIME || 1000 * 60 * 60 * 3, // 3 hours
|
||||||
|
/* Your SteamAPI key */
|
||||||
|
steamKey: process.env.STEAMKEY || "",
|
||||||
|
/* Secret for a cookie */
|
||||||
|
cookieSecret: process.env.COOKIE || "",
|
||||||
|
/* Discord webhook url or leave empty */
|
||||||
|
webhook_url: process.env.WEBHOOK || "",
|
||||||
|
};
|
2
index.js
2
index.js
|
@ -12,7 +12,7 @@ const { JsonDB, Config } = require("node-json-db"),
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const db = new JsonDB(new Config(`data/${config.production ? "main" : "test"}_db`, true, true, "/"));
|
const db = new JsonDB(new Config(`data/${config.production ? "main" : "test"}_db`, true, true, "/"));
|
||||||
|
|
||||||
if (!config.cookieSecret || !config.steamKey) return console.log("Please check that you have filled steamKey and cookieSecret in config file");
|
if (!config.cookieSecret || !config.steamKey || config.steamKey === "NO_KEY" || config.cookieSecret === "NO_COOKIE") return console.log("Please check that you have filled steamKey and cookieSecret in config file");
|
||||||
if (!fs.existsSync("public/courses/")) fs.mkdirSync("public/courses/");
|
if (!fs.existsSync("public/courses/")) fs.mkdirSync("public/courses/");
|
||||||
|
|
||||||
// Express App
|
// Express App
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"daisyui": "^4.11.1",
|
"daisyui": "^4.11.1",
|
||||||
|
"dotenv": "^16.4.5",
|
||||||
"ejs": "^2.6.1",
|
"ejs": "^2.6.1",
|
||||||
"express": "^4.16.1",
|
"express": "^4.16.1",
|
||||||
"express-session": "^1.18.0",
|
"express-session": "^1.18.0",
|
||||||
|
|
|
@ -11,6 +11,9 @@ importers:
|
||||||
daisyui:
|
daisyui:
|
||||||
specifier: ^4.11.1
|
specifier: ^4.11.1
|
||||||
version: 4.11.1(postcss@8.4.36)
|
version: 4.11.1(postcss@8.4.36)
|
||||||
|
dotenv:
|
||||||
|
specifier: ^16.4.5
|
||||||
|
version: 16.4.5
|
||||||
ejs:
|
ejs:
|
||||||
specifier: ^2.6.1
|
specifier: ^2.6.1
|
||||||
version: 2.6.2
|
version: 2.6.2
|
||||||
|
@ -395,6 +398,10 @@ packages:
|
||||||
domutils@3.1.0:
|
domutils@3.1.0:
|
||||||
resolution: {integrity: sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==}
|
resolution: {integrity: sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==}
|
||||||
|
|
||||||
|
dotenv@16.4.5:
|
||||||
|
resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
eastasianwidth@0.2.0:
|
eastasianwidth@0.2.0:
|
||||||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||||
|
|
||||||
|
@ -1579,6 +1586,8 @@ snapshots:
|
||||||
domelementtype: 2.3.0
|
domelementtype: 2.3.0
|
||||||
domhandler: 5.0.3
|
domhandler: 5.0.3
|
||||||
|
|
||||||
|
dotenv@16.4.5: {}
|
||||||
|
|
||||||
eastasianwidth@0.2.0: {}
|
eastasianwidth@0.2.0: {}
|
||||||
|
|
||||||
ee-first@1.1.1: {}
|
ee-first@1.1.1: {}
|
||||||
|
@ -2158,8 +2167,9 @@ snapshots:
|
||||||
postcss-load-config@4.0.2(postcss@8.4.36):
|
postcss-load-config@4.0.2(postcss@8.4.36):
|
||||||
dependencies:
|
dependencies:
|
||||||
lilconfig: 3.1.1
|
lilconfig: 3.1.1
|
||||||
postcss: 8.4.36
|
|
||||||
yaml: 2.4.1
|
yaml: 2.4.1
|
||||||
|
optionalDependencies:
|
||||||
|
postcss: 8.4.36
|
||||||
|
|
||||||
postcss-nested@6.0.1(postcss@8.4.36):
|
postcss-nested@6.0.1(postcss@8.4.36):
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue