mirror of
https://github.com/caprover/caprover
synced 2025-10-30 10:07:01 +00:00
Update to using captain shared files instead of dedicated volume
This commit is contained in:
@@ -10,7 +10,6 @@ docker service rm $(docker service ls -q)
|
||||
sleep 1
|
||||
docker secret rm captain-salt
|
||||
docker build -t captain-debug -f dockerfile-captain.debug .
|
||||
docker build -t caprover-goaccess -f ./dockerfiles/goaccess .
|
||||
docker run \
|
||||
-e "CAPTAIN_IS_DEBUG=1" \
|
||||
-e "MAIN_NODE_IP_ADDRESS=127.0.0.1" \
|
||||
|
||||
@@ -17,6 +17,9 @@ for logFile in /var/log/nginx-shared/*.log; do
|
||||
appName=${filename%%--*}
|
||||
appPath="/var/log/nginx-shared/$appName"
|
||||
|
||||
# Make directory for all the reports to live in
|
||||
mkdir -p $appPath
|
||||
|
||||
report="$appPath/$filename--Current.html"
|
||||
|
||||
echo "Processing catchup $report"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import express = require('express')
|
||||
import request = require('request')
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import validator from 'validator'
|
||||
import ApiStatusCodes from '../../../api/ApiStatusCodes'
|
||||
import BaseApi from '../../../api/BaseApi'
|
||||
@@ -352,67 +353,63 @@ router.get('/goaccess/:appName/files', async function (req, res, next) {
|
||||
return
|
||||
}
|
||||
|
||||
const directoryPath = path.join(
|
||||
CaptainConstants.nginxSharedLogsPathOnHost,
|
||||
appName
|
||||
)
|
||||
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
// Ensure a valid appName parameter
|
||||
return dataStore.getAppsDataStore().getAppDefinition(appName)
|
||||
})
|
||||
.then(function () {
|
||||
// Request the autoindex json that has all the generated reports
|
||||
const url = `http://${CaptainConstants.nginxServiceName}/goaccess/${appName}`
|
||||
|
||||
return new Promise<any[]>(function (resolve, reject) {
|
||||
request(url, function (error, response, body) {
|
||||
if (error || !body) {
|
||||
Logger.e(`Error ${error}`)
|
||||
reject(
|
||||
ApiStatusCodes.createError(
|
||||
ApiStatusCodes.STATUS_ERROR_GENERIC,
|
||||
'Request to list goaccess files Failed.'
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
resolve(JSON.parse(body))
|
||||
} catch (e) {
|
||||
Logger.e(`Error parsing ${e}`)
|
||||
reject(
|
||||
ApiStatusCodes.createError(
|
||||
ApiStatusCodes.STATUS_ERROR_GENERIC,
|
||||
'Request to list goaccess files Failed.'
|
||||
)
|
||||
)
|
||||
}
|
||||
return fs.readdir(directoryPath)
|
||||
})
|
||||
.then(function (files) {
|
||||
return Promise.all(
|
||||
files.map((file) => {
|
||||
return fs
|
||||
.stat(path.join(directoryPath, file))
|
||||
.then(function (fileStats) {
|
||||
return {
|
||||
name: file,
|
||||
time: fileStats.mtime,
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
.then(function (linkData) {
|
||||
const baseUrl = `/user/system/goaccess/`
|
||||
|
||||
const baseApi = new BaseApi(
|
||||
ApiStatusCodes.STATUS_OK,
|
||||
'GoAccess info retrieved'
|
||||
)
|
||||
baseApi.data = linkData.map((d) => {
|
||||
const { domainName, fileName } = CaptainManager.get()
|
||||
.getLoadBalanceManager()
|
||||
.parseLogPath(d.name)
|
||||
return {
|
||||
domainName,
|
||||
name: fileName,
|
||||
lastModifiedTime: d.mtime,
|
||||
url: `http://${
|
||||
CaptainConstants.configs.captainSubDomain
|
||||
}.${dataStore.getRootDomain()}/goaccess/${appName}/${
|
||||
d.name
|
||||
}`,
|
||||
}
|
||||
})
|
||||
baseApi.data = linkData
|
||||
.sort((a, b) => b.time.getTime() - a.time.getTime())
|
||||
.map((d) => {
|
||||
const { domainName, fileName } = CaptainManager.get()
|
||||
.getLoadBalanceManager()
|
||||
.parseLogPath(d.name)
|
||||
return {
|
||||
domainName,
|
||||
name: fileName,
|
||||
lastModifiedTime: d.time,
|
||||
url: baseUrl + `${appName}/files/${d.name}`,
|
||||
}
|
||||
})
|
||||
res.send(baseApi)
|
||||
})
|
||||
.catch(ApiStatusCodes.createCatcher(res))
|
||||
})
|
||||
|
||||
router.get('/goaccess/:appName/files/:file', function (req, res, next) {
|
||||
const path = `${req.params.appName}/${req.params.file}`
|
||||
res.sendFile(path, { root: CaptainConstants.nginxSharedLogsPathOnHost })
|
||||
})
|
||||
|
||||
router.get('/nginxconfig/', function (req, res, next) {
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
|
||||
@@ -724,9 +724,8 @@ class CaptainManager {
|
||||
CaptainConstants.configs.goAccessImageName,
|
||||
[
|
||||
{
|
||||
hostPath: CaptainConstants.nginxLogsVolumeName,
|
||||
volumeName:
|
||||
CaptainConstants.nginxLogsVolumeName,
|
||||
hostPath:
|
||||
CaptainConstants.nginxSharedLogsPathOnHost,
|
||||
containerPath:
|
||||
CaptainConstants.nginxSharedLogsPath,
|
||||
mode: 'rw',
|
||||
|
||||
@@ -848,7 +848,8 @@ class LoadBalancerManager {
|
||||
hostPath: CaptainConstants.nginxSharedPathOnHost,
|
||||
},
|
||||
{
|
||||
volumeName: CaptainConstants.nginxLogsVolumeName,
|
||||
hostPath:
|
||||
CaptainConstants.nginxSharedLogsPathOnHost,
|
||||
containerPath: CaptainConstants.nginxSharedLogsPath,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -159,6 +159,8 @@ const data = {
|
||||
|
||||
nginxSharedPathOnHost: CAPTAIN_DATA_DIRECTORY + '/nginx-shared',
|
||||
|
||||
nginxSharedLogsPathOnHost: CAPTAIN_DATA_DIRECTORY + '/shared-logs',
|
||||
|
||||
debugSourceDirectory: '', // Only used in debug mode
|
||||
|
||||
// ********************* Local Docker Constants ************************
|
||||
@@ -167,8 +169,6 @@ const data = {
|
||||
|
||||
nginxServiceName: 'captain-nginx',
|
||||
|
||||
nginxLogsVolumeName: 'caprover-logs',
|
||||
|
||||
captainServiceName: 'captain-captain',
|
||||
|
||||
certbotServiceName: 'captain-certbot',
|
||||
|
||||
@@ -26,26 +26,6 @@
|
||||
deny all;
|
||||
}
|
||||
|
||||
<%
|
||||
if (captain.logAccessPath) {
|
||||
%>
|
||||
location /goaccess {
|
||||
alias <%-captain.logAccessPath%>;
|
||||
autoindex on;
|
||||
autoindex_format json;
|
||||
|
||||
# This can be improved by adding authentication as well.
|
||||
# CIDR Range IPs:
|
||||
allow 172.16.0.0/12;
|
||||
allow 10.0.0.0/8;
|
||||
allow 192.168.0.0/16;
|
||||
|
||||
deny all;
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
location / {
|
||||
root <%-captain.defaultHtmlDir%>;
|
||||
index index.html index.htm;
|
||||
@@ -138,16 +118,6 @@
|
||||
root <%-captain.staticWebRoot%>;
|
||||
}
|
||||
|
||||
|
||||
<%
|
||||
if (captain.logAccessPath) {
|
||||
%>
|
||||
location /goaccess {
|
||||
alias <%-captain.logAccessPath%>;
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user