Skip to content

Commit

Permalink
Merge pull request #64 from Hugo-C/feature/export-nginx-logs
Browse files Browse the repository at this point in the history
Feature/export nginx logs
  • Loading branch information
Hugo-C authored Aug 11, 2024
2 parents b902660 + 9d88a92 commit 63debbd
Show file tree
Hide file tree
Showing 13 changed files with 1,198 additions and 846 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.77-bullseye as build-stage
FROM rust:1.77-bullseye AS build-stage

ARG BUILD_TARGET="x86_64-unknown-linux-musl"
ARG BUILD_OPTIONS="--release --target $BUILD_TARGET"
Expand Down Expand Up @@ -26,7 +26,7 @@ COPY . /app/project/
# This is the actual build, touch the main.rs to have newer timestamp
RUN touch /app/project/src/main.rs && cargo build $BUILD_OPTIONS -Z unstable-options --out-dir /app/dist

FROM alpine:3 as production-stage
FROM alpine:3 AS production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist/jarm_online /app
COPY --from=build-stage /app/project/Rocket.toml /
Expand Down
13 changes: 12 additions & 1 deletion ansible_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
path: "{{ project_dir }}/nginx"
state: directory

- name: Create nginx logs directory
file:
path: "{{ project_dir }}/nginx_logs"
state: directory

- name: Copy nginx conf
ansible.builtin.copy:
src: /git/jarm-online/jarm_online_gui/nginx.conf.prod
Expand Down Expand Up @@ -113,4 +118,10 @@
- name: Start containers
community.docker.docker_compose:
project_src: "{{ project_dir }}"
pull: true
pull: true

- name: Add logrotate to nginx
ansible.builtin.copy:
src: /git/jarm-online/nginx_log_rotate
dest: "/etc/logrotate.d/nginx"
force: true
2 changes: 0 additions & 2 deletions docker-compose-LE.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:

letsencrypt:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
jarm_online_gui:
build:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml.prod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '3'
services:
jarm_online_gui:
image: hugocker/jarm_online_gui
container_name: jarm_online_gui_container
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx_logs:/var/log/nginx
- letsencrypt:/etc/letsencrypt:ro
restart: unless-stopped
ports:
Expand Down
4 changes: 2 additions & 2 deletions jarm_online_gui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Taken from https://cli.vuejs.org/guide/deployment.html#docker-nginx
FROM node:20 as build-stage
FROM node:20 AS build-stage
ARG VUE_APP_SENTRY_DSN
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run build

FROM nginx:stable-alpine as production-stage
FROM nginx:stable-alpine AS production-stage
ARG VUE_APP_SENTRY_DSN
ENV VUE_APP_SENTRY_DSN=${VUE_APP_SENTRY_DSN}
RUN echo "Sentry dsn set to $VUE_APP_SENTRY_DSN"
Expand Down
15 changes: 15 additions & 0 deletions jarm_online_gui/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import js from "@eslint/js";
import pluginVue from 'eslint-plugin-vue'

export default [
js.configs.recommended,
...pluginVue.configs['flat/recommended'],
{
files: ["**/*.js", "**/*.ts", "**/vue.js"],
ignores: [".gitignore"],
languageOptions: {
ecmaVersion: 2022,
},
rules: {}
}
]
48 changes: 45 additions & 3 deletions jarm_online_gui/nginx.conf.prod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,46 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
log_format json_analytics escape=json '{'
'"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution
'"connection": "$connection", ' # connection serial number
'"connection_requests": "$connection_requests", ' # number of requests made in connection
'"pid": "$pid", ' # process pid
'"request_id": "$request_id", ' # the unique request id
'"request_length": "$request_length", ' # request length (including headers and body)
'"remote_addr": "$remote_addr", ' # client IP
'"remote_user": "$remote_user", ' # client HTTP username
'"remote_port": "$remote_port", ' # client port
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format
'"request": "$request", ' # full path no arguments if the request
'"request_uri": "$request_uri", ' # full path and arguments if the request
'"args": "$args", ' # args
'"status": "$status", ' # response status code
'"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client
'"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client
'"http_referer": "$http_referer", ' # HTTP referer
'"http_user_agent": "$http_user_agent", ' # user agent
'"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for
'"http_host": "$http_host", ' # the request Host: header
'"server_name": "$server_name", ' # the name of the vhost serving the request
'"request_time": "$request_time", ' # request processing time in seconds with msec resolution
'"upstream": "$upstream_addr", ' # upstream backend server for proxied requests
'"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS
'"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers
'"upstream_response_time": "$upstream_response_time", ' # time spent receiving upstream body
'"upstream_response_length": "$upstream_response_length", ' # upstream response length
'"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable
'"ssl_protocol": "$ssl_protocol", ' # TLS protocol
'"ssl_cipher": "$ssl_cipher", ' # TLS cipher
'"scheme": "$scheme", ' # http or https
'"request_method": "$request_method", ' # request method
'"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0
'"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise
'"gzip_ratio": "$gzip_ratio"'
'}';

access_log /var/log/nginx/json_access.log json_analytics;
sendfile on;
keepalive_timeout 65;

Expand Down Expand Up @@ -51,7 +91,8 @@ http {
}
}
server {
listen 443 ssl http2;
listen 443 ssl;
http2 on;
server_name jarm.online www.jarm.online;
ssl_protocols TLSv1.3 TLSv1.2;
ssl_prefer_server_ciphers on;
Expand Down Expand Up @@ -90,7 +131,8 @@ http {
}

server {
listen 443 ssl http2;
listen 443 ssl;
http2 on;

# the virtual host name of this
server_name netdata.jarm.online;
Expand Down Expand Up @@ -121,4 +163,4 @@ http {
proxy_store off;
}
}
}
}
Loading

0 comments on commit 63debbd

Please sign in to comment.