fix
This commit is contained in:
parent
ef78fd9c8a
commit
d520205885
8 changed files with 62 additions and 81955 deletions
8
dist/main/index.js
vendored
8
dist/main/index.js
vendored
|
|
@ -97046,20 +97046,22 @@ async function restoreCache(cacheConfig) {
|
|||
|
||||
async function startRemoteCacheServer() {
|
||||
core.startGroup("Remote cache server")
|
||||
|
||||
|
||||
core.debug(`Remote cache server log file path: ${config.remoteCacheServer.logPath}`)
|
||||
const log = fs.openSync(config.remoteCacheServer.logPath, 'a')
|
||||
const serverProcess = fork(path.join(__dirname, 'dist', 'remote-cache-server', 'index.js'), [], {
|
||||
const serverProcess = fork(__nccwpck_require__.ab + "remote-cache-server.js", [], {
|
||||
detached: true,
|
||||
stdio: ['ignore', log, log, 'ipc']
|
||||
})
|
||||
serverProcess.unref()
|
||||
|
||||
core.info(`Started remote cache server (${serverProcess.pid}`)
|
||||
core.info(`Started remote cache server (${serverProcess.pid}`)
|
||||
core.saveState('remote-cache-server-pid', serverProcess.pid.toString())
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
})();
|
||||
|
||||
module.exports = __webpack_exports__;
|
||||
|
|
|
|||
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
50
dist/main/remote-cache-server.js
vendored
Normal file
50
dist/main/remote-cache-server.js
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
const http = require('http')
|
||||
const cache = require('@actions/cache')
|
||||
const fs = require('fs')
|
||||
|
||||
// https://bazel.build/remote/caching#http-caching
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const { method, url } = req
|
||||
const [, , cacheType, sha] = url.split('/')
|
||||
const filePath = `/tmp/cache-${cacheType}-${sha}`
|
||||
|
||||
if (method === 'GET') {
|
||||
try {
|
||||
const cacheId = await cache.restoreCache([filePath], sha)
|
||||
if (!cacheId) {
|
||||
console.log(`Cache miss for ${sha}`)
|
||||
res.writeHead(404)
|
||||
return res.end('Cache miss')
|
||||
}
|
||||
const data = fs.readFileSync(filePath)
|
||||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' })
|
||||
res.end(data)
|
||||
} catch (error) {
|
||||
console.error(`Error retrieving cache for ${sha}: ${error}`)
|
||||
res.writeHead(500)
|
||||
res.end('Internal Server Error')
|
||||
}
|
||||
} else if (method === 'PUT') {
|
||||
const data = []
|
||||
req.on('data', chunk => data.push(chunk))
|
||||
req.on('end', async () => {
|
||||
try {
|
||||
fs.writeFileSync(filePath, Buffer.concat(data))
|
||||
await cache.saveCache([filePath], sha)
|
||||
console.log(`Cache saved for ${sha}`)
|
||||
res.writeHead(201)
|
||||
res.end('Cache saved')
|
||||
} catch (error) {
|
||||
console.error(`Error saving cache for ${sha}: ${error}`)
|
||||
res.writeHead(500)
|
||||
res.end('Internal Server Error')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
res.writeHead(405)
|
||||
res.end('Method Not Allowed')
|
||||
}
|
||||
})
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
server.listen(PORT, () => console.log(`Server listening on port ${PORT}`))
|
||||
81945
dist/remote-cache-server/index.js
vendored
81945
dist/remote-cache-server/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/remote-cache-server/index.js.map
vendored
1
dist/remote-cache-server/index.js.map
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
8
index.js
8
index.js
|
|
@ -180,16 +180,18 @@ async function restoreCache(cacheConfig) {
|
|||
|
||||
async function startRemoteCacheServer() {
|
||||
core.startGroup("Remote cache server")
|
||||
|
||||
|
||||
core.debug(`Remote cache server log file path: ${config.remoteCacheServer.logPath}`)
|
||||
const log = fs.openSync(config.remoteCacheServer.logPath, 'a')
|
||||
const serverProcess = fork(path.join(__dirname, 'dist', 'remote-cache-server', 'index.js'), [], {
|
||||
const serverProcess = fork(path.join(__dirname, 'remote-cache-server.js'), [], {
|
||||
detached: true,
|
||||
stdio: ['ignore', log, log, 'ipc']
|
||||
})
|
||||
serverProcess.unref()
|
||||
|
||||
core.info(`Started remote cache server (${serverProcess.pid}`)
|
||||
core.info(`Started remote cache server (${serverProcess.pid}`)
|
||||
core.saveState('remote-cache-server-pid', serverProcess.pid.toString())
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
run()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"node": "20.x"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post && ncc build remote-cache-server.js -s -o dist/remote-cache-server",
|
||||
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Alex Rodionov <p0deje@gmail.com>",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue