generated from 2BAD/ts-lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[conf] add docker compose with solution stack
- Loading branch information
Showing
9 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MIRE_HOST = 0.0.0.0 | ||
MIRE_PORT = 4000 | ||
NGINX_HOST = 127.0.0.1 | ||
NGINX_PORT = 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Canvas builder stage | ||
FROM node:20-alpine AS canvas | ||
|
||
# Install build dependencies for node-canvas | ||
RUN apk add --no-cache build-base cairo-dev pango-dev jpeg-dev giflib-dev librsvg-dev | ||
|
||
# Set working directory | ||
WORKDIR /canvas | ||
|
||
# Copy package.json and package-lock.json | ||
COPY package*.json ./ | ||
|
||
# Install canvas and its dependencies | ||
RUN npm install canvas@next | ||
|
||
|
||
# Main build stage | ||
FROM node:20-alpine AS builder | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json | ||
COPY package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm un canvas | ||
RUN npm ci | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Build the application | ||
RUN npm run build | ||
|
||
# Production stage | ||
FROM node:20-alpine AS production | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Install runtime dependencies for node-canvas | ||
RUN apk add --no-cache cairo pango jpeg giflib librsvg | ||
|
||
# Copy package.json and package-lock.json | ||
COPY package*.json ./ | ||
|
||
# Install production dependencies | ||
RUN npm un canvas && rm -rf node_modules && npm cache clean --force | ||
RUN npm ci --only=production && npm cache clean --force | ||
|
||
# Copy the built canvas module from canvas | ||
COPY --from=canvas /canvas/node_modules/canvas ./node_modules/canvas | ||
|
||
# Copy built application from builder stage | ||
COPY --from=builder /app/build ./build | ||
|
||
# Set NODE_ENV | ||
ENV NODE_ENV=production | ||
ENV PORT=3000 | ||
|
||
# Expose the port your app runs on | ||
EXPOSE 3000 | ||
|
||
# Define the command to run your app | ||
CMD ["node", "build/server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM nginx:mainline AS builder | ||
|
||
# Install necessary build tools | ||
RUN apt-get update && apt-get install -y wget build-essential libpcre3-dev zlib1g-dev libssl-dev | ||
|
||
# Download and extract Nginx source | ||
RUN wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \ | ||
tar zxf nginx-$NGINX_VERSION.tar.gz | ||
|
||
# Download and extract NGINX VTS module | ||
RUN wget https://github.com/vozlt/nginx-module-vts/archive/v0.2.2.tar.gz && \ | ||
tar zxf v0.2.2.tar.gz | ||
|
||
# Compile Nginx with VTS module | ||
RUN cd nginx-$NGINX_VERSION && \ | ||
./configure --with-compat --add-dynamic-module=../nginx-module-vts-0.2.2 && \ | ||
make modules | ||
|
||
FROM nginx:mainline | ||
|
||
# Copy the compiled module | ||
COPY --from=builder /nginx-$NGINX_VERSION/objs/ngx_http_vhost_traffic_status_module.so /usr/lib/nginx/modules/ | ||
|
||
# Enable the module in nginx.conf | ||
RUN echo "load_module modules/ngx_http_vhost_traffic_status_module.so;" > /etc/nginx/modules/vts.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
x-base: &base | ||
restart: unless-stopped | ||
# network_mode: host | ||
# env_file: defaults.env | ||
|
||
services: | ||
mire: | ||
<<: *base | ||
container_name: mire | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile.mire | ||
ports: | ||
- ${MIRE_PORT}:${MIRE_PORT} | ||
environment: | ||
NODE_ENV: production | ||
HOST: ${MIRE_HOST} | ||
PORT: ${MIRE_PORT} | ||
|
||
nginx: | ||
<<: *base | ||
container_name: nginx | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile.nginx | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf:ro | ||
depends_on: | ||
- mire | ||
|
||
nginx-exporter: | ||
<<: *base | ||
container_name: nginx-exporter | ||
image: nginx/nginx-prometheus-exporter | ||
command: | ||
- -nginx.scrape-uri=http://nginx/metrics | ||
ports: | ||
- "9113:9113" | ||
depends_on: | ||
- nginx | ||
|
||
prometheus: | ||
<<: *base | ||
container_name: prometheus | ||
image: prom/prometheus | ||
ports: | ||
- "9090:9090" | ||
volumes: | ||
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro | ||
depends_on: | ||
- nginx | ||
|
||
grafana: | ||
<<: *base | ||
container_name: grafana | ||
image: grafana/grafana | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- ./grafana/dashboards:/var/lib/grafana/dashboards | ||
- ./grafana/provisioning:/etc/grafana/provisioning | ||
environment: | ||
- GF_SECURITY_ADMIN_PASSWORD=admin | ||
depends_on: | ||
- prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: 1 | ||
|
||
providers: | ||
- name: 'default' | ||
orgId: 1 | ||
folder: '' | ||
type: file | ||
disableDeletion: false | ||
updateIntervalSeconds: 10 | ||
options: | ||
path: /var/lib/grafana/dashboards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# config file version | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: Prometheus | ||
type: prometheus | ||
access: proxy | ||
orgId: 1 | ||
url: 'http://prometheus:9090' | ||
isDefault: true | ||
version: 1 | ||
editable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
include /etc/nginx/modules/*.conf; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
vhost_traffic_status_zone; | ||
|
||
# Define a cache zone | ||
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; | ||
|
||
upstream app { | ||
server mire:4000; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
# Cache configuration for the specific endpoint | ||
location /problems/slow-image { | ||
proxy_cache my_cache; | ||
proxy_cache_valid 200 1d; # Cache successful responses for 1 day | ||
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; | ||
proxy_cache_lock on; | ||
proxy_cache_key $request_uri; # Include query string in cache key | ||
|
||
proxy_pass http://app; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
|
||
# Default location block for other requests | ||
location / { | ||
proxy_pass http://app; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
|
||
location /metrics { | ||
stub_status; | ||
# allow 127.0.0.1; | ||
# deny all; | ||
} | ||
|
||
location /status { | ||
vhost_traffic_status_display; | ||
vhost_traffic_status_display_format html; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
global: | ||
scrape_interval: 5s | ||
|
||
scrape_configs: | ||
- job_name: 'mire' | ||
static_configs: | ||
- targets: ['mire:4000'] | ||
|
||
- job_name: 'nginx' | ||
static_configs: | ||
- targets: ['nginx-exporter:9113'] | ||
|
||
- job_name: 'nginx-vts' | ||
metrics_path: /status/format/prometheus | ||
static_configs: | ||
- targets: ['nginx:80'] | ||
|
||
- job_name: 'prometheus' | ||
static_configs: | ||
- targets: ['localhost:9090'] |