Compare commits
134 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cbd683d89 | |||
| 3d97353750 | |||
| c242ac606a | |||
| 5f5300b124 | |||
| e65e87a8a8 | |||
| 377a931654 | |||
| 01ca16fd59 | |||
| 75f45401c1 | |||
| 34ae84a5fa | |||
| 009781c33b | |||
| a7370d5de5 | |||
| b864e37fe5 | |||
| e182368ef5 | |||
| c2ebfcc23e | |||
| 94ce0d37b9 | |||
| aaf73bd622 | |||
| 48f7b545d9 | |||
| 7ba417d3a8 | |||
| cfa18a0e0b | |||
| 9a5980e5bc | |||
| 14af0c68d0 | |||
| 94923ba2e8 | |||
| fc164cd0c2 | |||
| 19e6147266 | |||
| 811f168f66 | |||
| 14ee66fe94 | |||
| 9f9423c5ed | |||
| 4184d4374a | |||
| e3d3dd83ae | |||
| 8648407435 | |||
| 9b17961367 | |||
| 0a63d3befe | |||
| 78faedb6cc | |||
| b72e6fba3e | |||
| b0a759ff2a | |||
| d2ba7da012 | |||
| 6bb5bcb198 | |||
| a1ecd03f73 | |||
| f73b8e3937 | |||
| 64a673ec6d | |||
| 6af53b3697 | |||
| dcec6837b4 | |||
| 6e698b0c05 | |||
| f5f46af5a5 | |||
| 2a79a6066f | |||
| 5933dd60f5 | |||
| 55b9ac7d5a | |||
| aa5eda9f1b | |||
| be1bb918e4 | |||
| 5f0785c818 | |||
| 593f48419b | |||
| d9fdd93a2e | |||
| c4d84487cd | |||
| 6ab07443e3 | |||
| bbdc08249b | |||
| b846033c15 | |||
| c9cf01a9bb | |||
| f238f7726f | |||
| 36e31fda5d | |||
| a038b56d89 | |||
| f85178bf1d | |||
| b2057cb310 | |||
| 9f28ba29cb | |||
| ff04b104a5 | |||
| 7c8f11d102 | |||
| 7713de24dc | |||
| f204c5d440 | |||
| c403003030 | |||
| fbb33bda0f | |||
| 61bb54a2be | |||
| 94aae37025 | |||
| 0b3224c05f | |||
| 217e5f74ca | |||
| aca7b3f961 | |||
| c3ff6c7770 | |||
| 0fc386eebf | |||
| 119ed217ad | |||
| 072a45d853 | |||
| dec7347f08 | |||
| b1eaa97530 | |||
| 6280a5a002 | |||
| 20866189ab | |||
| 90fdbf5681 | |||
| 31b41e156d | |||
| bf528709d2 | |||
| 89bff17891 | |||
| 6279c63dfb | |||
| 0d531d2641 | |||
| 84dfc633bd | |||
| 5840e8f88d | |||
| b461178ff0 | |||
| 69f79386f4 | |||
| 179bc4df33 | |||
| a577a17116 | |||
| d0bfa69a23 | |||
| 5bc02b12fe | |||
| 019a4f26f3 | |||
| 3e9c3bfcce | |||
| 9b6377f4dc | |||
| 78408be110 | |||
| 1d8e019e33 | |||
| c2c092fb4d | |||
| 1b51f9a6af | |||
| 00af21cc5e | |||
| 7c86c6e243 | |||
| 9b53af0a26 | |||
| c3d6d6704c | |||
| 0a707f9b05 | |||
| bce30bcfeb | |||
| 62ffdc816a | |||
| 87376120c9 | |||
| ad6ed1cbff | |||
| 09ea2f68de | |||
| 56ecb546f4 | |||
| af2476d46c | |||
| 432f45ac59 | |||
| c71cb09fdd | |||
| 65f3d2365e | |||
| 62b187eb10 | |||
| 34796ac040 | |||
| a440b5435a | |||
| 6e150b1edc | |||
| 3492e118fd | |||
| d02c777e55 | |||
| 8ed522774c | |||
| d301e54b45 | |||
| 3576b096ea | |||
| 7082842d00 | |||
| 5911a7fb43 | |||
| 81024f869d | |||
| 7ead61dbf2 | |||
| 098be1495e | |||
| 536f7b5b85 | |||
| 6a1a965ffd |
@@ -1,41 +0,0 @@
|
||||
FROM ubuntu:20.04
|
||||
|
||||
# Makes sure LuaTex cache is writable
|
||||
# -----------------------------------
|
||||
ENV TEXMFVAR=/var/lib/sharelatex/tmp/texmf-var
|
||||
|
||||
|
||||
# Install dependencies
|
||||
# --------------------
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
build-essential wget net-tools unzip time imagemagick optipng strace nginx git python zlib1g-dev libpcre3-dev \
|
||||
qpdf \
|
||||
aspell aspell-en aspell-af aspell-am aspell-ar aspell-ar-large aspell-bg aspell-bn aspell-br aspell-ca aspell-cs aspell-cy aspell-da aspell-de aspell-el aspell-eo aspell-es aspell-et aspell-eu-es aspell-fa aspell-fo aspell-fr aspell-ga aspell-gl-minimos aspell-gu aspell-he aspell-hi aspell-hr aspell-hsb aspell-hu aspell-hy aspell-id aspell-is aspell-it aspell-kk aspell-kn aspell-ku aspell-lt aspell-lv aspell-ml aspell-mr aspell-nl aspell-nr aspell-ns aspell-pa aspell-pl aspell-pt aspell-pt-br aspell-ro aspell-ru aspell-sk aspell-sl aspell-ss aspell-st aspell-sv aspell-tl aspell-tn aspell-ts aspell-uk aspell-uz aspell-xh aspell-zu \
|
||||
\
|
||||
# install Node.JS 12
|
||||
&& curl -sSL https://deb.nodesource.com/setup_12.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
\
|
||||
&& rm -rf \
|
||||
# We are adding a custom nginx config in the main Dockerfile.
|
||||
/etc/nginx/nginx.conf \
|
||||
/etc/nginx/sites-enabled/default \
|
||||
/var/lib/apt/lists/*
|
||||
|
||||
# Add envsubst
|
||||
# ------------
|
||||
ADD server-ce/vendor/envsubst /usr/bin/envsubst
|
||||
RUN chmod +x /usr/bin/envsubst
|
||||
|
||||
# Install TexLive
|
||||
# ---------------
|
||||
# Skipped!
|
||||
|
||||
|
||||
# Set up sharelatex user and home directory
|
||||
# -----------------------------------------
|
||||
RUN mkdir -p /var/lib/sharelatex && \
|
||||
mkdir -p /var/log/sharelatex && \
|
||||
mkdir -p /var/lib/sharelatex/data/template_files
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "Overleaf Community Edition Codespace",
|
||||
"dockerComposeFile": "docker-compose.dev.yml",
|
||||
"service": "sharelatex",
|
||||
"workspaceFolder": "/var/www/sharelatex",
|
||||
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/bash"
|
||||
},
|
||||
|
||||
"extensions": [
|
||||
"ms-azuretools.vscode-docker",
|
||||
|
||||
],
|
||||
|
||||
"forwardPorts": [80]
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
version: '2.2'
|
||||
services:
|
||||
sharelatex:
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: .devcontainer/Dockerfile
|
||||
entrypoint: "echo hola!"
|
||||
depends_on:
|
||||
mongo:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_started
|
||||
ports:
|
||||
- 80:80
|
||||
links:
|
||||
- mongo
|
||||
- redis
|
||||
environment:
|
||||
SHARELATEX_APP_NAME: Overleaf CE Codebase Dev Environment
|
||||
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
|
||||
SHARELATEX_REDIS_HOST: redis
|
||||
REDIS_HOST: redis
|
||||
ENABLED_LINKED_FILE_TYPES: 'project_file,project_output_file'
|
||||
ENABLE_CONVERSIONS: 'true'
|
||||
EMAIL_CONFIRMATION_DISABLED: 'true'
|
||||
|
||||
mongo:
|
||||
restart: always
|
||||
image: mongo:4.2
|
||||
healthcheck:
|
||||
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
||||
interval: 10s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:5
|
||||
@@ -1,44 +0,0 @@
|
||||
<!--
|
||||
|
||||
Note: If you are using www.overleaf.com and have a problem,
|
||||
or if you would like to request a new feature please contact
|
||||
the support team at support@overleaf.com
|
||||
|
||||
This form should only be used to report bugs in the
|
||||
Community Edition release of Overleaf.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
|
||||
<!-- BUG REPORT TEMPLATE -->
|
||||
|
||||
## Steps to Reproduce
|
||||
<!-- Describe the steps leading up to when / where you found the bug. -->
|
||||
<!-- Screenshots may be helpful here. -->
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
## Expected Behaviour
|
||||
<!-- What should have happened when you completed the steps above? -->
|
||||
|
||||
## Observed Behaviour
|
||||
<!-- What actually happened when you completed the steps above? -->
|
||||
<!-- Screenshots may be helpful here. -->
|
||||
|
||||
## Context
|
||||
<!-- How has this issue affected you? What were you trying to accomplish? -->
|
||||
|
||||
## Technical Info
|
||||
<!-- Provide any technical details that may be applicable (or N/A if not applicable). -->
|
||||
|
||||
* URL:
|
||||
* Browser Name and version:
|
||||
* Operating System and version (desktop or mobile):
|
||||
* Signed in as:
|
||||
* Project and/or file:
|
||||
|
||||
## Analysis
|
||||
<!--- Optionally, document investigation of / suggest a fix for the bug, e.g. 'comes from this line / commit' -->
|
||||
@@ -1,11 +0,0 @@
|
||||
## Description
|
||||
<!-- Goal of the pull request -->
|
||||
|
||||
|
||||
## Related issues / Pull Requests
|
||||
<!-- Fixes #xyz, Contributes to #xyz, Related to #xyz-->
|
||||
|
||||
|
||||
## Contributor Agreement
|
||||
|
||||
- [ ] I confirm I have signed the [Contributor License Agreement](https://github.com/overleaf/overleaf/blob/master/CONTRIBUTING.md#contributor-license-agreement)
|
||||
+20
-5
@@ -1,6 +1,21 @@
|
||||
# docker image build
|
||||
.dockerignore
|
||||
/config
|
||||
config-local
|
||||
node_modules
|
||||
|
||||
# user defined files
|
||||
.env
|
||||
docker-compose.override.yml
|
||||
web
|
||||
document-updater
|
||||
clsi
|
||||
filestore
|
||||
track-changes
|
||||
docstore
|
||||
tags
|
||||
chat
|
||||
spelling
|
||||
|
||||
data
|
||||
tmp
|
||||
|
||||
db.sqlite
|
||||
|
||||
.DS_Store
|
||||
.vagrant
|
||||
|
||||
+22
-10
@@ -4,17 +4,17 @@ Contributing to ShareLaTeX
|
||||
Thank you for reading this! If you'd like to report a bug or join in the development
|
||||
of ShareLaTeX, then here are some notes on how to do that.
|
||||
|
||||
*Note that ShareLaTeX is actually made up of many separate repositories (a list is available
|
||||
*Note that ShareLaTeX is actually made up of many seperate repositories (a list is available
|
||||
[here](https://github.com/sharelatex/sharelatex/blob/master/README.md#other-repositories)).*
|
||||
|
||||
Reporting bugs and opening issues
|
||||
---------------------------------
|
||||
|
||||
If you'd like to report a bug or open an issue then please:
|
||||
If you'd like a report a bug or open an issue then please:
|
||||
|
||||
1. **Find the correct repository.** ShareLaTeX is split across multiple different repositories, each containing a different service (you can find a list of [all repositories here](https://github.com/sharelatex/sharelatex/blob/master/README.md#other-repositories)). If you know the bug only applies to one service, then please open an issue in that repository. For general bugs and issues that span more than one service, please open an issue in the [sharelatex/sharelatex](https://github.com/sharelatex/sharelatex) repository.
|
||||
2. **Check if there is an existing issue.** If there is then please add
|
||||
any more information that you have, or give it a 👍.
|
||||
any more information that you have, or give it a "+1" in the comments.
|
||||
|
||||
When submitting an issue please describe the issue as clearly as possible, including how to
|
||||
reproduce the bug, which situations it appears in, what you expected to happen, and what actually happens.
|
||||
@@ -23,29 +23,41 @@ If you can include a screenshot for front end issues that is very helpful.
|
||||
Pull Requests
|
||||
-------------
|
||||
|
||||
See [our wiki](https://github.com/sharelatex/sharelatex/wiki)
|
||||
See [our wiki](https://github.com/sharelatex/sharelatex/wiki/Developer-Guidelines)
|
||||
for how to manage the ShareLaTeX development environment and for our developer guidelines.
|
||||
|
||||
We love pull requests, so be bold with them! Don't be afraid of going ahead
|
||||
and changing something, or adding a new feature. We're very happy to work with you
|
||||
to get your changes merged into ShareLaTeX.
|
||||
|
||||
If you're looking for something to work on, have a look at the open issues in any of the repositories listed [here](https://github.com/sharelatex/sharelatex/blob/master/README.md#other-repositories).
|
||||
If you've got an idea for a change then please discuss it in the open first,
|
||||
either by opening an issue, or by joining us in our
|
||||
[development chat room](http://www.hipchat.com/g1nJMcj7b).
|
||||
|
||||
If you're looking for something to work on, then take a look at our [development roadmap](https://github.com/sharelatex/sharelatex/wiki/Development-Roadmap), or have a look at the open issues in any of the repositories listed [here](https://github.com/sharelatex/sharelatex/blob/master/README.md#other-repositories).
|
||||
|
||||
Developer Chat Room
|
||||
-------------------
|
||||
|
||||
If you want to ask any questions in real-time, or get a feel for what's going on
|
||||
then please drop into our [development chat room](http://www.hipchat.com/g1nJMcj7b).
|
||||
If no one is online then you can still leave a message that will hopefully get a reply
|
||||
when we return.
|
||||
|
||||
Security
|
||||
--------
|
||||
|
||||
Please do not publish security vulnerabilities publicly until we've had a chance
|
||||
to address them. All security related issues/patches should be sent directly to
|
||||
security@overleaf.com where we will attempt to address them quickly. If you're
|
||||
team@sharelatex.com where we will attempt to address them quickly. If you're
|
||||
unsure whether something is a security issue or not, then please be cautious and
|
||||
contact us at security@overleaf.com first.
|
||||
contact us at team@sharelatex.com first.
|
||||
|
||||
Contributor License Agreement
|
||||
-----------------------------
|
||||
|
||||
Before we can accept any contributions of code, we need you to agree to our
|
||||
[Contributor License Agreement](https://docs.google.com/forms/d/e/1FAIpQLSef79XH3mb7yIiMzZw-yALEegS-wyFetvjTiNBfZvf_IHD2KA/viewform?usp=sf_link).
|
||||
Before we can accept and contributions of code, we need you to agree to our
|
||||
[Contributor License Agreement](https://sharelatex.wufoo.com/forms/sharelatex-contributor-license-agreement/).
|
||||
This is to ensure that you own the copyright of your contribution, and that you
|
||||
agree to give us a license to use it in both the open source version, and the version
|
||||
of Overleaf running at www.overleaf.com, which may have additional changes.
|
||||
of ShareLaTeX running at www.sharelatex.com, which may have additional changes.
|
||||
|
||||
@@ -0,0 +1,510 @@
|
||||
fs = require "fs"
|
||||
spawn = require("child_process").spawn
|
||||
exec = require("child_process").exec
|
||||
rimraf = require "rimraf"
|
||||
Path = require "path"
|
||||
semver = require "semver"
|
||||
knox = require "knox"
|
||||
crypto = require "crypto"
|
||||
async = require "async"
|
||||
|
||||
SERVICES = [{
|
||||
name: "web"
|
||||
repo: "https://github.com/sharelatex/web-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "document-updater"
|
||||
repo: "https://github.com/sharelatex/document-updater-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "clsi"
|
||||
repo: "https://github.com/sharelatex/clsi-sharelatex.git"
|
||||
version: "v0.1.1"
|
||||
}, {
|
||||
name: "filestore"
|
||||
repo: "https://github.com/sharelatex/filestore-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "track-changes"
|
||||
repo: "https://github.com/sharelatex/track-changes-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "docstore"
|
||||
repo: "https://github.com/sharelatex/docstore-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "chat"
|
||||
repo: "https://github.com/sharelatex/chat-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "tags"
|
||||
repo: "https://github.com/sharelatex/tags-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}, {
|
||||
name: "spelling"
|
||||
repo: "https://github.com/sharelatex/spelling-sharelatex.git"
|
||||
version: "v0.1.0"
|
||||
}]
|
||||
|
||||
module.exports = (grunt) ->
|
||||
grunt.loadNpmTasks 'grunt-bunyan'
|
||||
grunt.loadNpmTasks 'grunt-execute'
|
||||
grunt.loadNpmTasks 'grunt-available-tasks'
|
||||
grunt.loadNpmTasks 'grunt-concurrent'
|
||||
|
||||
execute = {}
|
||||
for service in SERVICES
|
||||
execute[service.name] =
|
||||
src: "#{service.name}/app.js"
|
||||
|
||||
grunt.initConfig
|
||||
execute: execute
|
||||
|
||||
concurrent:
|
||||
all:
|
||||
tasks: ("run:#{service.name}" for service in SERVICES)
|
||||
options:
|
||||
limit: SERVICES.length
|
||||
logConcurrentOutput: true
|
||||
|
||||
availabletasks:
|
||||
tasks:
|
||||
options:
|
||||
filter: 'exclude',
|
||||
tasks: [
|
||||
'concurrent'
|
||||
'execute'
|
||||
'bunyan'
|
||||
'availabletasks'
|
||||
]
|
||||
groups:
|
||||
"Run tasks": [
|
||||
"run"
|
||||
"run:all"
|
||||
"default"
|
||||
].concat ("run:#{service.name}" for service in SERVICES)
|
||||
"Misc": [
|
||||
"help"
|
||||
]
|
||||
"Install tasks": ("install:#{service.name}" for service in SERVICES).concat(["install:all", "install", "install:dirs", "install:config"])
|
||||
"Update tasks": ("update:#{service.name}" for service in SERVICES).concat(["update:all", "update"])
|
||||
"Config tasks": ["install:config"]
|
||||
"Checks": ["check", "check:redis", "check:latexmk", "check:s3", "check:make"]
|
||||
|
||||
for service in SERVICES
|
||||
do (service) ->
|
||||
grunt.registerTask "install:#{service.name}", "Download and set up the #{service.name} service", () ->
|
||||
done = @async()
|
||||
Helpers.installService(service, done)
|
||||
grunt.registerTask "update:#{service.name}", "Checkout and update the #{service.name} service", () ->
|
||||
done = @async()
|
||||
Helpers.updateService(service, done)
|
||||
grunt.registerTask "run:#{service.name}", "Run the ShareLaTeX #{service.name} service", ["bunyan", "execute:#{service.name}"]
|
||||
grunt.registerTask "release:#{service.name}", "Create a new release version of #{service.name} (specify with --release option)", () ->
|
||||
done = @async()
|
||||
Helpers.createNewRelease(service, grunt.option("release"), done)
|
||||
|
||||
grunt.registerTask 'install:config', "Copy the example config into the real config", () ->
|
||||
Helpers.installConfig @async()
|
||||
grunt.registerTask 'install:dirs', "Copy the example config into the real config", () ->
|
||||
Helpers.createDataDirs @async()
|
||||
grunt.registerTask 'install:all', "Download and set up all ShareLaTeX services",
|
||||
["check:make"].concat(
|
||||
("install:#{service.name}" for service in SERVICES)
|
||||
).concat(["install:config", "install:dirs"])
|
||||
grunt.registerTask 'install', 'install:all'
|
||||
grunt.registerTask 'update:all', "Checkout and update all ShareLaTeX services",
|
||||
["check:make"].concat(
|
||||
("update:#{service.name}" for service in SERVICES)
|
||||
)
|
||||
grunt.registerTask 'update', 'update:all'
|
||||
grunt.registerTask 'run', "Run all of the sharelatex processes", ['concurrent:all']
|
||||
grunt.registerTask 'run:all', 'run'
|
||||
|
||||
grunt.registerTask 'help', 'Display this help list', 'availabletasks'
|
||||
grunt.registerTask 'default', 'run'
|
||||
|
||||
grunt.registerTask "check:redis", "Check that redis is installed and running", () ->
|
||||
Helpers.checkRedis @async()
|
||||
grunt.registerTask "check:latexmk", "Check that latexmk is installed", () ->
|
||||
Helpers.checkLatexmk @async()
|
||||
grunt.registerTask "check:s3", "Check that Amazon S3 credentials are configured", () ->
|
||||
Helpers.checkS3 @async()
|
||||
grunt.registerTask "check:fs", "Check that local filesystem options are configured", () ->
|
||||
Helpers.checkFS @async()
|
||||
grunt.registerTask "check:aspell", "Check that aspell is installed", () ->
|
||||
Helpers.checkAspell @async()
|
||||
grunt.registerTask "check:make", "Check that make is installed", () ->
|
||||
Helpers.checkMake @async()
|
||||
grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk", "check:s3", "check:fs", "check:aspell"]
|
||||
|
||||
grunt.registerTask "build:deb", "Build an installable .deb file from the current directory", () ->
|
||||
Helpers.buildDeb @async()
|
||||
grunt.registerTask "build:upstart_scripts", "Create upstart scripts for each service", () ->
|
||||
Helpers.buildUpstartScripts()
|
||||
|
||||
Helpers =
|
||||
installService: (service, callback = (error) ->) ->
|
||||
Helpers.cloneGitRepo service, (error) ->
|
||||
return callback(error) if error?
|
||||
Helpers.installNpmModules service, (error) ->
|
||||
return callback(error) if error?
|
||||
Helpers.runGruntInstall service, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
||||
updateService: (service, callback = (error) ->) ->
|
||||
Helpers.updateGitRepo service, (error) ->
|
||||
return callback(error) if error?
|
||||
Helpers.installNpmModules service, (error) ->
|
||||
return callback(error) if error?
|
||||
Helpers.runGruntInstall service, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
||||
cloneGitRepo: (service, callback = (error) ->) ->
|
||||
repo_src = service.repo
|
||||
dir = service.name
|
||||
if !fs.existsSync(dir)
|
||||
proc = spawn "git", [
|
||||
"clone",
|
||||
"-b", service.version,
|
||||
repo_src,
|
||||
dir
|
||||
], stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
else
|
||||
console.log "#{dir} already installed, skipping."
|
||||
callback()
|
||||
|
||||
updateGitRepo: (service, callback = (error) ->) ->
|
||||
dir = service.name
|
||||
proc = spawn "git", ["checkout", service.version], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
proc = spawn "git", ["pull"], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
|
||||
createNewRelease: (service, version, callback = (error) ->) ->
|
||||
dir = service.name
|
||||
proc = spawn "sed", [
|
||||
"-i", "",
|
||||
"s/\"version\".*$/\"version\": \"#{version}\",/g",
|
||||
"package.json"
|
||||
], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
proc = spawn "git", ["commit", "-a", "-m", "Release version #{version}"], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
proc = spawn "git", ["tag", "v#{version}"], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
proc = spawn "git", ["push"], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
proc = spawn "git", ["push", "--tags"], cwd: dir, stdio: "inherit"
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
|
||||
installNpmModules: (service, callback = (error) ->) ->
|
||||
dir = service.name
|
||||
proc = spawn "npm", ["install"], stdio: "inherit", cwd: dir
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
|
||||
createDataDirs: (callback = (error) ->) ->
|
||||
DIRS = [
|
||||
"tmp/dumpFolder"
|
||||
"tmp/uploads"
|
||||
"data/user_files"
|
||||
"data/compiles"
|
||||
"data/cache"
|
||||
]
|
||||
jobs = []
|
||||
for dir in DIRS
|
||||
do (dir) ->
|
||||
jobs.push (callback) ->
|
||||
path = Path.join(__dirname, dir)
|
||||
grunt.log.writeln "Ensuring '#{path}' exists"
|
||||
exec "mkdir -p #{path}", callback
|
||||
async.series jobs, callback
|
||||
|
||||
installConfig: (callback = (error) ->) ->
|
||||
src = "config/settings.development.coffee.example"
|
||||
dest = "config/settings.development.coffee"
|
||||
if !fs.existsSync(dest)
|
||||
grunt.log.writeln "Creating config at #{dest}"
|
||||
config = fs.readFileSync(src).toString()
|
||||
config = config.replace /CRYPTO_RANDOM/g, () ->
|
||||
crypto.randomBytes(64).toString("hex")
|
||||
fs.writeFileSync dest, config
|
||||
callback()
|
||||
else
|
||||
grunt.log.writeln "Config file already exists. Skipping."
|
||||
callback()
|
||||
|
||||
runGruntInstall: (service, callback = (error) ->) ->
|
||||
dir = service.name
|
||||
proc = spawn "grunt", ["install"], stdio: "inherit", cwd: dir
|
||||
proc.on "close", () ->
|
||||
callback()
|
||||
|
||||
checkRedis: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking Redis is running... "
|
||||
exec "redis-cli info", (error, stdout, stderr) ->
|
||||
if error? and error.message.match("Could not connect")
|
||||
grunt.log.error "FAIL. Redis is not running"
|
||||
return callback(error)
|
||||
else if error?
|
||||
return callback(error)
|
||||
else
|
||||
m = stdout.match(/redis_version:(.*)/)
|
||||
if !m?
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.error "Unknown redis version"
|
||||
error = new Error("Unknown redis version")
|
||||
else
|
||||
version = m[1]
|
||||
if semver.gte(version, "2.6.12")
|
||||
grunt.log.writeln "OK."
|
||||
grunt.log.writeln "Running Redis version #{version}"
|
||||
else
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.error "Redis version is too old (#{version}). Must be 2.6.12 or greater."
|
||||
error = new Error("Redis version is too old (#{version}). Must be 2.6.12 or greater.")
|
||||
callback(error)
|
||||
|
||||
checkLatexmk: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking latexmk is installed... "
|
||||
exec "latexmk --version", (error, stdout, stderr) ->
|
||||
if error? and error.message.match("not found")
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Either latexmk is not installed or is not in your PATH.
|
||||
|
||||
latexmk comes with TexLive 2013, and must be a version from 2013 or later.
|
||||
If you have already have TeXLive installed, then make sure it is
|
||||
included in your PATH (example for 64-bit linux):
|
||||
|
||||
export PATH=$PATH:/usr/local/texlive/2014/bin/x86_64-linux/
|
||||
|
||||
This is a not a fatal error, but compiling will not work without latexmk.
|
||||
"""
|
||||
return callback(error)
|
||||
else if error?
|
||||
return callback(error)
|
||||
else
|
||||
m = stdout.match(/Version (.*)/)
|
||||
if !m?
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.error "Unknown latexmk version"
|
||||
error = new Error("Unknown latexmk version")
|
||||
else
|
||||
version = m[1]
|
||||
if semver.gte(version + ".0", "4.39.0")
|
||||
grunt.log.writeln "OK."
|
||||
grunt.log.writeln "Running latexmk version #{version}"
|
||||
else
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
latexmk version is too old (#{version}). Must be 4.39 or greater.
|
||||
This is a not a fatal error, but compiling will not work without latexmk
|
||||
"""
|
||||
error = new Error("latexmk is too old")
|
||||
callback(error)
|
||||
|
||||
checkAspell: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking aspell is installed... "
|
||||
exec "aspell dump dicts", (error, stdout, stderr) ->
|
||||
if error? and error.message.match("not found")
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Either aspell is not installed or is not in your PATH.
|
||||
|
||||
On Ubuntu you can install aspell with:
|
||||
|
||||
sudo apt-get install aspell
|
||||
|
||||
Or on a mac:
|
||||
|
||||
brew install aspell
|
||||
|
||||
This is not a fatal error, but the spell-checker will not work without aspell
|
||||
"""
|
||||
return callback(error)
|
||||
else if error?
|
||||
return callback(error)
|
||||
else
|
||||
grunt.log.writeln "OK."
|
||||
grunt.log.writeln "The following spell check dictionaries are available:"
|
||||
grunt.log.write stdout
|
||||
callback()
|
||||
callback(error)
|
||||
|
||||
checkS3: (callback = (error) ->) ->
|
||||
Settings = require "settings-sharelatex"
|
||||
if Settings.filestore.backend==""
|
||||
grunt.log.writeln "No backend specified. Assuming Amazon S3"
|
||||
Settings.filestore.backend = "s3"
|
||||
if Settings.filestore.backend=="s3"
|
||||
grunt.log.write "Checking S3 credentials... "
|
||||
try
|
||||
client = knox.createClient({
|
||||
key: Settings.filestore.s3.key
|
||||
secret: Settings.filestore.s3.secret
|
||||
bucket: Settings.filestore.stores.user_files
|
||||
})
|
||||
catch e
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Please configure your Amazon S3 credentials in config/settings.development.coffee
|
||||
|
||||
Amazon S3 (Simple Storage Service) is a cloud storage service provided by
|
||||
Amazon. ShareLaTeX uses S3 for storing binary files like images. You can
|
||||
sign up for an account and find out more at:
|
||||
|
||||
http://aws.amazon.com/s3/
|
||||
|
||||
"""
|
||||
return callback()
|
||||
client.getFile "does-not-exist", (error, response) ->
|
||||
unless response? and response.statusCode == 404
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Could not connect to Amazon S3. Please check your credentials.
|
||||
"""
|
||||
else
|
||||
grunt.log.writeln "OK."
|
||||
callback()
|
||||
else
|
||||
grunt.log.writeln "Filestore other than S3 configured. Not checking S3."
|
||||
callback()
|
||||
|
||||
checkFS: (callback = (error) ->) ->
|
||||
Settings = require "settings-sharelatex"
|
||||
if Settings.filestore.backend=="fs"
|
||||
grunt.log.write "Checking FS configuration... "
|
||||
fs = require("fs")
|
||||
fs.exists Settings.filestore.stores.user_files, (exists) ->
|
||||
if exists
|
||||
grunt.log.writeln "OK."
|
||||
else
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Could not find directory "#{Settings.filestore.stores.user_files}".
|
||||
Please check your configuration.
|
||||
"""
|
||||
callback()
|
||||
else
|
||||
grunt.log.writeln "Filestore other than FS configured. Not checking FS."
|
||||
callback()
|
||||
|
||||
checkMake: (callback = (error) ->) ->
|
||||
grunt.log.write "Checking make is installed... "
|
||||
exec "make --version", (error, stdout, stderr) ->
|
||||
if error? and error.message.match("not found")
|
||||
grunt.log.error "FAIL."
|
||||
grunt.log.errorlns """
|
||||
Either make is not installed or is not in your path.
|
||||
|
||||
On Ubuntu you can install make with:
|
||||
|
||||
sudo apt-get install build-essential
|
||||
|
||||
"""
|
||||
return callback(error)
|
||||
else if error?
|
||||
return callback(error)
|
||||
else
|
||||
grunt.log.write "OK."
|
||||
return callback()
|
||||
|
||||
buildUpstartScripts: () ->
|
||||
template = fs.readFileSync("package/upstart/sharelatex-template").toString()
|
||||
for service in SERVICES
|
||||
fs.writeFileSync "package/upstart/sharelatex-#{service.name}", template.replace(/__SERVICE__/g, service.name)
|
||||
|
||||
buildPackageSettingsFile: () ->
|
||||
config = fs.readFileSync("config/settings.development.coffee.example").toString()
|
||||
config = config.replace /DATA_DIR.*/, "DATA_DIR = '/var/lib/sharelatex/data'"
|
||||
config = config.replace /TMP_DIR.*/, "TMP_DIR = '/var/lib/sharelatex/tmp'"
|
||||
fs.writeFileSync "package/config/settings.coffee", config
|
||||
|
||||
buildDeb: (callback = (error) ->) ->
|
||||
command = ["-s", "dir", "-t", "deb", "-n", "sharelatex", "-v", "0.0.1", "--verbose"]
|
||||
command.push(
|
||||
"--maintainer", "ShareLaTeX <team@sharelatex.com>"
|
||||
"--config-files", "/etc/sharelatex/settings.coffee"
|
||||
"--config-files", "/etc/nginx/conf.d/sharelatex.conf"
|
||||
"--directories", "/var/lib/sharelatex"
|
||||
"--directories", "/var/log/sharelatex"
|
||||
)
|
||||
|
||||
command.push(
|
||||
"--depends", "redis-server > 2.6.12"
|
||||
"--depends", "mongodb-org > 2.4.0"
|
||||
"--depends", "nodejs > 0.10.0"
|
||||
)
|
||||
|
||||
@buildPackageSettingsFile()
|
||||
|
||||
@buildUpstartScripts()
|
||||
for service in SERVICES
|
||||
command.push(
|
||||
"--deb-upstart", "package/upstart/sharelatex-#{service.name}"
|
||||
)
|
||||
|
||||
after_install_script = """
|
||||
#!/bin/sh
|
||||
# Create random secret keys (twice, once for http auth pass, once for cookie secret).
|
||||
sed -i "0,/CRYPTO_RANDOM/s/CRYPTO_RANDOM/$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 64 | head -n 1)/" /etc/sharelatex/settings.coffee
|
||||
sed -i "0,/CRYPTO_RANDOM/s/CRYPTO_RANDOM/$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 64 | head -n 1)/" /etc/sharelatex/settings.coffee
|
||||
|
||||
sudo adduser --system --group --home /var/www/sharelatex --no-create-home sharelatex
|
||||
|
||||
mkdir -p /var/log/sharelatex
|
||||
chown sharelatex:sharelatex /var/log/sharelatex
|
||||
|
||||
mkdir -p /var/lib/sharelatex
|
||||
|
||||
"""
|
||||
|
||||
for dir in ["data/user_files", "tmp/uploads", "data/compiles", "data/cache", "tmp/dumpFolder"]
|
||||
after_install_script += """
|
||||
mkdir -p /var/lib/sharelatex/#{dir}
|
||||
|
||||
"""
|
||||
|
||||
after_install_script += """
|
||||
chown -R sharelatex:sharelatex /var/lib/sharelatex
|
||||
|
||||
"""
|
||||
|
||||
for service in SERVICES
|
||||
after_install_script += "service sharelatex-#{service.name} restart\n"
|
||||
fs.writeFileSync "package/scripts/after_install.sh", after_install_script
|
||||
command.push("--after-install", "package/scripts/after_install.sh")
|
||||
|
||||
command.push("--exclude", "**/.git")
|
||||
command.push("--exclude", "**/node_modules/grunt-*")
|
||||
for path in ["filestore/user_files", "filestore/uploads", "clsi/cache", "clsi/compiles"]
|
||||
command.push "--exclude", path
|
||||
|
||||
for service in SERVICES
|
||||
command.push "#{service.name}=/var/www/sharelatex/"
|
||||
|
||||
command.push(
|
||||
"package/config/settings.coffee=/etc/sharelatex/settings.coffee"
|
||||
"package/nginx/sharelatex=/etc/nginx/conf.d/sharelatex.conf"
|
||||
)
|
||||
console.log "fpm " + command.join(" ")
|
||||
proc = spawn "fpm", command, stdio: "inherit"
|
||||
proc.on "close", (code) ->
|
||||
if code != 0
|
||||
callback(new Error("exit code: #{code}"))
|
||||
else
|
||||
callback()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,77 +1,97 @@
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<a href="https://www.overleaf.com"><img src="doc/logo.png" alt="Overleaf" width="300"></a>
|
||||
</h1>
|
||||
ShareLaTeX
|
||||
==========
|
||||
|
||||
<h4 align="center">An open-source online real-time collaborative LaTeX editor.</h4>
|
||||
[ShareLaTeX](https://www.sharelatex.com) is an open-source online real-time collaborative LaTeX editor. We run a hosted version at http://www.sharelatex.com, but you can also run your own local version, and contribute to the development of ShareLaTeX.
|
||||
|
||||
<p align="center">
|
||||
<a href="#key-features">Key Features</a> •
|
||||
<a href="https://github.com/overleaf/overleaf/wiki">Wiki</a> •
|
||||
<a href="https://www.overleaf.com/for/enterprises">Server Pro</a> •
|
||||
<a href="#contributing">Contributing</a> •
|
||||
<a href="https://mailchi.mp/overleaf.com/community-edition-and-server-pro">Mailing List</a> •
|
||||
<a href="#authors">Authors</a> •
|
||||
<a href="#license">License</a>
|
||||
</p>
|
||||
|
||||
<a href="https://www.overleaf.com"><img src="doc/screenshot.png" alt="Overleaf" ></a>
|
||||
<p align="center">
|
||||
Figure 1: A screenshot of Overleaf Server Pro's comments and tracked changes features.
|
||||
</p>
|
||||
|
||||
## Key Features
|
||||
|
||||
[Overleaf](https://www.overleaf.com) is an open-source online real-time collaborative LaTeX editor. We run a hosted version at [www.overleaf.com](https://www.overleaf.com), but you can also run your own local version, and contribute to the development of Overleaf.
|
||||
|
||||
*[If you want help installing and maintaining Overleaf in your lab or workplace, we offer an officially supported version called Overleaf Server Pro. It also comes with extra security and admin features. Click here to find out more!](https://www.overleaf.com/for/enterprises)*
|
||||
|
||||
## Keeping up to date
|
||||
|
||||
Sign up to the [mailing list](https://mailchi.mp/overleaf.com/community-edition-and-server-pro) to get updates on Overleaf Releases and development
|
||||
|
||||
## Installation
|
||||
Installation
|
||||
------------
|
||||
|
||||
We have detailed installation instructions in our wiki:
|
||||
|
||||
* [Overleaf Quick Start Guide](https://github.com/overleaf/overleaf/wiki/Quick-Start-Guide)
|
||||
* [Installing ShareLaTeX in Production](https://github.com/sharelatex/sharelatex/wiki/Production-Installation-Instructions)
|
||||
* [Setting up a ShareLaTeX Development Environment](https://github.com/sharelatex/sharelatex/wiki/Setting-up-a-Development-Environment)
|
||||
|
||||
## Upgrading
|
||||
**If you have any problems, have a look at our page of [Frequent Problems and Questions](https://github.com/sharelatex/sharelatex/wiki/FAQ).**
|
||||
|
||||
If you are upgrading from a previous version of Overleaf, please see the [Release Notes section on the Wiki](https://github.com/overleaf/overleaf/wiki/Home) for all of the versions between your current version and the version you are upgrading to.
|
||||
*[Please help us make ShareLaTeX as easy to install as possible by answering our quick survey about your system and needs](https://sharelatex.typeform.com/to/PLNits)*
|
||||
|
||||
## Overleaf Docker Image
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
This repo contains two dockerfiles, `Dockerfile-base`, which builds the
|
||||
`sharelatex/sharelatex-base` image, and `Dockerfile` which builds the
|
||||
`sharelatex/sharelatex` (or "community") image.
|
||||
ShareLaTeX should run on OS X and Linux. You need:
|
||||
|
||||
The Base image generally contains the basic dependencies like `wget` and
|
||||
`aspell`, plus `texlive`. We split this out because it's a pretty heavy set of
|
||||
dependencies, and it's nice to not have to rebuild all of that every time.
|
||||
* [Node.js](http://nodejs.org/) 0.10 or greater. We recommend that you use [nvm](https://github.com/creationix/nvm) to install it.
|
||||
* The [grunt](http://gruntjs.com/) command line tools (Run `npm install -g grunt-cli` to install them)
|
||||
* A local instance of [Redis](http://redis.io/topics/quickstart) (version 2.6.12 or later) and [MongoDB](http://docs.mongodb.org/manual/installation/) running on their standard ports.
|
||||
* [TeXLive](https://www.tug.org/texlive/) 2013 or later with the `latexmk` program installed.
|
||||
|
||||
The `sharelatex/sharelatex` image extends the base image and adds the actual Overleaf code
|
||||
and services.
|
||||
Other repositories
|
||||
------------------
|
||||
|
||||
Use `make build-base` and `make build-community` from `server-ce/` to build these images.
|
||||
This repository does not contain any code. It acts a wrapper and toolkit for managing the many different ShareLaTeX services. These each run as their own Node.js process and have their own Github repository. These are all downloaded and set up when you run `grunt install`
|
||||
|
||||
We use the [Phusion base-image](https://github.com/phusion/baseimage-docker)
|
||||
(which is extended by our `base` image) to provide us with a VM-like container
|
||||
in which to run the Overleaf services. Baseimage uses the `runit` service
|
||||
manager to manage services, and we add our init-scripts from the `server-ce/runit`
|
||||
folder.
|
||||
The different services are:
|
||||
|
||||
### [web](https://github.com/sharelatex/web-sharelatex) [](https://travis-ci.org/sharelatex/web-sharelatex)
|
||||
|
||||
The front facing web server that serves all the HTML pages, CSS and JavaScript
|
||||
to the client. Also contains a lot of logic around creating and editing
|
||||
projects, and account management.
|
||||
|
||||
### [document-updater](https://github.com/sharelatex/document-updater-sharelatex) [](https://travis-ci.org/sharelatex/document-updater-sharelatex)
|
||||
|
||||
Processes updates that come in from the editor when users modify documents. Ensures that
|
||||
the updates are applied in the right order, and that only one operation is modifying
|
||||
the document at a time. Also caches the documents in redis for very fast but persistent
|
||||
modifications.
|
||||
|
||||
### [CLSI](https://github.com/sharelatex/clsi-sharelatex) [](https://travis-ci.org/sharelatex/clsi-sharelatex)
|
||||
|
||||
The Common LaTeX Service Interface (CLSI) which provides an API for compiling LaTeX
|
||||
documents.
|
||||
|
||||
### [docstore](https://github.com/sharelatex/docstore-sharelatex) [](https://travis-ci.org/sharelatex/docstore-sharelatex)
|
||||
|
||||
An API for performing CRUD (Create, Read, Update and Delete) operations on text files
|
||||
stored in ShareLaTeX.
|
||||
|
||||
### [filestore](https://github.com/sharelatex/filestore-sharelatex) [](https://travis-ci.org/sharelatex/filestore-sharelatex)
|
||||
|
||||
An API for performing CRUD (Create, Read, Update and Delete) operations on binary files
|
||||
(like images) stored in ShareLaTeX.
|
||||
|
||||
### [track-changes](https://github.com/sharelatex/track-changes-sharelatex) [](https://travis-ci.org/sharelatex/track-changes-sharelatex)
|
||||
|
||||
An API for compressing and storing the updates applied to a document, and then rendering a diff of the changes
|
||||
between any two time points.
|
||||
|
||||
### [chat](https://github.com/sharelatex/chat-sharelatex) [](https://travis-ci.org/sharelatex/chat-sharelatex)
|
||||
|
||||
The backend API for storing and fetching chat messages.
|
||||
|
||||
### [tags](https://github.com/sharelatex/tags-sharelatex) [](https://travis-ci.org/sharelatex/tags-sharelatex)
|
||||
|
||||
The backend API for managing project tags (folders).
|
||||
|
||||
### [spelling](https://github.com/sharelatex/spelling-sharelatex)
|
||||
|
||||
An API for running server-side spelling checking on ShareLaTeX documents.
|
||||
|
||||
|
||||
## Contributing
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Please see the [CONTRIBUTING](https://github.com/overleaf/overleaf/blob/master/CONTRIBUTING.md) file for information on contributing to the development of Overleaf. See [our wiki](https://github.com/overleaf/overleaf/wiki/Developer-Guidelines) for information on setting up a development environment and how to recompile and run Overleaf after modifications.
|
||||
Please see the [CONTRIBUTING](https://github.com/sharelatex/sharelatex/blob/master/CONTRIBUTING.md) file for information on contributing to the development of ShareLaTeX. See [our wiki](https://github.com/sharelatex/sharelatex/wiki/Developer-Guidelines) for information on setting up a development environment and how to recompile and run ShareLaTeX after modifications.
|
||||
|
||||
## Authors
|
||||
Authors
|
||||
---
|
||||
|
||||
[The Overleaf Team](https://www.overleaf.com/about)
|
||||
- [Henry Oswald](http://twitter.com/henryoswald)
|
||||
- [James Allen](http://twitter.com/thejpallen)
|
||||
|
||||
## License
|
||||
License
|
||||
----
|
||||
|
||||
The code in this repository is released under the GNU AFFERO GENERAL PUBLIC LICENSE, version 3. A copy can be found in the `LICENSE` file.
|
||||
|
||||
Copyright (c) Overleaf, 2014-2021.
|
||||
Copyright (c) ShareLaTeX, 2014.
|
||||
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = "ubuntu-12.04"
|
||||
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
||||
|
||||
config.vm.network :forwarded_port, guest: 3000, host: 3000
|
||||
config.vm.network :forwarded_port, guest: 80, host: 8080
|
||||
|
||||
config.ssh.forward_agent = true
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 1024
|
||||
end
|
||||
|
||||
config.vm.provision :chef_solo do |chef|
|
||||
chef.cookbooks_path = "chef/cookbooks"
|
||||
chef.add_recipe 'apt'
|
||||
chef.add_recipe 'redis-server'
|
||||
chef.add_recipe 'mongodb'
|
||||
chef.add_recipe 'nodejs'
|
||||
chef.add_recipe 'texlive'
|
||||
chef.add_recipe 'packages'
|
||||
|
||||
# You may also specify custom JSON attributes:
|
||||
chef.json = {}
|
||||
end
|
||||
|
||||
# Enable provisioning with chef server, specifying the chef server URL,
|
||||
# and the path to the validation key (relative to this Vagrantfile).
|
||||
#
|
||||
# The Opscode Platform uses HTTPS. Substitute your organization for
|
||||
# ORGNAME in the URL and validation key.
|
||||
#
|
||||
# If you have your own Chef Server, use the appropriate URL, which may be
|
||||
# HTTP instead of HTTPS depending on your configuration. Also change the
|
||||
# validation key to validation.pem.
|
||||
#
|
||||
# config.vm.provision :chef_client do |chef|
|
||||
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
|
||||
# chef.validation_key_path = "ORGNAME-validator.pem"
|
||||
# end
|
||||
#
|
||||
# If you're using the Opscode platform, your validator client is
|
||||
# ORGNAME-validator, replacing ORGNAME with your organization name.
|
||||
#
|
||||
# If you have your own Chef Server, the default validation client name is
|
||||
# chef-validator, unless you changed the configuration.
|
||||
#
|
||||
# chef.validation_client_name = "ORGNAME-validator"
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
current_dir = File.dirname(__FILE__)
|
||||
cookbook_path ["#{current_dir}/../cookbooks"]
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
apt Cookbook CHANGELOG
|
||||
======================
|
||||
This file is used to list changes made in each version of the apt cookbook.
|
||||
|
||||
v2.3.8 (2014-02-14)
|
||||
-------------------
|
||||
### Bug
|
||||
- **[COOK-4287](https://tickets.opscode.com/browse/COOK-4287)** - Cleanup the Kitchen
|
||||
|
||||
|
||||
v2.3.6
|
||||
------
|
||||
* [COOK-4154] - Add chefspec matchers.rb file to apt cookbook
|
||||
* [COOK-4102] - Only index created repository
|
||||
|
||||
|
||||
v2.3.6
|
||||
------
|
||||
* [COOK-4154] - Add chefspec matchers.rb file to apt cookbook
|
||||
* [COOK-4102] - Only index created repository
|
||||
|
||||
|
||||
v2.3.4
|
||||
------
|
||||
No change. Version bump for toolchain sanity
|
||||
|
||||
|
||||
v2.3.2
|
||||
------
|
||||
- [COOK-3905] apt-get-update-periodic: configuration for the update period
|
||||
- Updating style for rubocops
|
||||
- Updating test-kitchen harness
|
||||
|
||||
|
||||
v2.3.0
|
||||
------
|
||||
### Bug
|
||||
- **[COOK-3812](https://tickets.opscode.com/browse/COOK-3812)** - Add a way to bypass the apt existence check
|
||||
|
||||
### Improvement
|
||||
- **[COOK-3567](https://tickets.opscode.com/browse/COOK-3567)** - Allow users to bypass apt-cache via attributes
|
||||
|
||||
|
||||
v2.2.1
|
||||
------
|
||||
### Improvement
|
||||
- **[COOK-664](https://tickets.opscode.com/browse/COOK-664)** - Check platform before running apt-specific commands
|
||||
|
||||
|
||||
v2.2.0
|
||||
------
|
||||
### Bug
|
||||
- **[COOK-3707](https://tickets.opscode.com/browse/COOK-3707)** - multiple nics confuse apt::cacher-client
|
||||
|
||||
v2.1.2
|
||||
------
|
||||
### Improvement
|
||||
- **[COOK-3551](https://tickets.opscode.com/browse/COOK-3551)** - Allow user to set up a trusted APT repository
|
||||
|
||||
v2.1.1
|
||||
------
|
||||
### Bug
|
||||
- **[COOK-1856](https://tickets.opscode.com/browse/COOK-1856)** - Match GPG keys without case sensitivity
|
||||
|
||||
v2.1.0
|
||||
------
|
||||
- [COOK-3426]: cacher-ng fails with restrict_environment set to true
|
||||
- [COOK-2859]: cacher-client executes out of order
|
||||
- [COOK-3052]: Long GPG keys are downloaded on every run
|
||||
- [COOK-1856]: apt cookbook should match keys without case sensitivity
|
||||
- [COOK-3255]: Attribute name incorrect in README
|
||||
- [COOK-3225]: Call use_inline_resources only if defined
|
||||
- [COOK-3386]: Cache dir for apt-cacher-ng
|
||||
- [COOK-3291]: apt_repository: enable usage of a keyserver on port 80
|
||||
- Greatly expanded test coverage with ChefSpec and Test-Kitchen
|
||||
|
||||
v2.0.0
|
||||
------
|
||||
### Bug
|
||||
|
||||
- [COOK-2258]: apt: LWRP results in error under why-run mode in apt 1.9.0 cookbook
|
||||
|
||||
v1.10.0
|
||||
-------
|
||||
### Improvement
|
||||
|
||||
- [COOK-2885]: Improvements for apt cache server search
|
||||
|
||||
### Bug
|
||||
|
||||
- [COOK-2441]: Apt recipe broken in new chef version
|
||||
- [COOK-2660]: Create Debian 6.0 "squeeze" specific template for
|
||||
apt-cacher-ng
|
||||
|
||||
v1.9.2
|
||||
------
|
||||
- [COOK-2631] - Create Ubuntu 10.04 specific template for apt-cacher-ng
|
||||
|
||||
v1.9.0
|
||||
------
|
||||
- [COOK-2185] - Proxy for apt-key
|
||||
- [COOK-2338] - Support pinning by glob() or regexp
|
||||
|
||||
v1.8.4
|
||||
------
|
||||
- [COOK-2171] - Update README to clarify required Chef version: 10.18.0
|
||||
or higher.
|
||||
|
||||
v1.8.2
|
||||
------
|
||||
- [COOK-2112] - need [] around "arch" in sources.list entries
|
||||
- [COOK-2171] - fixes a regression in the notification
|
||||
|
||||
v1.8.0
|
||||
------
|
||||
- [COOK-2143] - Allow for a custom cacher-ng port
|
||||
- [COOK-2171] - On `apt_repository.run_action(:add)` the source file
|
||||
is not created.
|
||||
- [COOK-2184] - apt::cacher-ng, use `cacher_port` attribute in
|
||||
acng.conf
|
||||
|
||||
v1.7.0
|
||||
------
|
||||
- [COOK-2082] - add "arch" parameter to apt_repository LWRP
|
||||
|
||||
v1.6.0
|
||||
------
|
||||
- [COOK-1893] - `apt_preference` use "`package_name`" resource instead of "name"
|
||||
- [COOK-1894] - change filename for sources.list.d files
|
||||
- [COOK-1914] - Wrong dir permissions for /etc/apt/preferences.d/
|
||||
- [COOK-1942] - README.md has wrong name for the keyserver attribute
|
||||
- [COOK-2019] - create 01proxy before any other apt-get updates get executed
|
||||
|
||||
v1.5.2
|
||||
------
|
||||
- [COOK-1682] - use template instead of file resource in apt::cacher-client
|
||||
- [COOK-1875] - cacher-client should be Environment-aware
|
||||
|
||||
V1.5.0
|
||||
------
|
||||
- [COOK-1500] - Avoid triggering apt-get update
|
||||
- [COOK-1548] - Add execute commands for autoclean and autoremove
|
||||
- [COOK-1591] - Setting up the apt proxy should leave https
|
||||
connections direct
|
||||
- [COOK-1596] - execute[apt-get-update-periodic] never runs
|
||||
- [COOK-1762] - create /etc/apt/preferences.d directory
|
||||
- [COOK-1776] - apt key check isn't idempotent
|
||||
|
||||
v1.4.8
|
||||
------
|
||||
* Adds test-kitchen support
|
||||
- [COOK-1435] - repository lwrp is not idempotent with http key
|
||||
|
||||
v1.4.6
|
||||
------
|
||||
- [COOK-1530] - apt_repository isn't aware of update-success-stamp
|
||||
file (also reverts COOK-1382 patch).
|
||||
|
||||
v1.4.4
|
||||
------
|
||||
- [COOK-1229] - Allow cacher IP to be set manually in non-Chef Solo
|
||||
environments
|
||||
- [COOK-1530] - Immediately update apt-cache when sources.list file is dropped off
|
||||
|
||||
v1.4.2
|
||||
------
|
||||
- [COOK-1155] - LWRP for apt pinning
|
||||
|
||||
v1.4.0
|
||||
------
|
||||
- [COOK-889] - overwrite existing repo source files
|
||||
- [COOK-921] - optionally use cookbook\_file or remote\_file for key
|
||||
- [COOK-1032] - fixes problem with apt repository key installation
|
||||
@@ -0,0 +1,248 @@
|
||||
apt Cookbook
|
||||
============
|
||||
This cookbook includes recipes to execute apt-get update to ensure the local APT package cache is up to date. There are recipes for managing the apt-cacher-ng caching proxy and proxy clients. It also includes a LWRP for managing APT repositories in /etc/apt/sources.list.d as well as an LWRP for pinning packages via /etc/apt/preferences.d.
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
**Version 2.0.0+ of this cookbook requires Chef 11.0.0 or later**. If your Chef version is earlier than 11.0.0, use version 1.10.0 of this cookbook.
|
||||
|
||||
Version 1.8.2 to 1.10.0 of this cookbook requires **Chef 10.16.4** or later.
|
||||
|
||||
If your Chef version is earlier than 10.16.4, use version 1.7.0 of this cookbook.
|
||||
|
||||
### Platform
|
||||
Please refer to the [TESTING file](TESTING.md) to see the currently (and passing) tested platforms. The release was tested on:
|
||||
|
||||
* Ubuntu 10.04
|
||||
* Ubuntu 12.04
|
||||
* Ubuntu 13.04
|
||||
* Debian 7.1
|
||||
* Debian 6.0 (have with manual testing)
|
||||
|
||||
May work with or without modification on other Debian derivatives.
|
||||
|
||||
|
||||
-------
|
||||
### default
|
||||
This recipe installs the `update-notifier-common` package to provide the timestamp file used to only run `apt-get update` if the cache is more than one day old.
|
||||
|
||||
This recipe should appear first in the run list of Debian or Ubuntu nodes to ensure that the package cache is up to date before managing any `package` resources with Chef.
|
||||
|
||||
This recipe also sets up a local cache directory for preseeding packages.
|
||||
|
||||
**Including the default recipe on a node that does not support apt (such as Windows) results in a noop.**
|
||||
|
||||
### cacher-client
|
||||
Configures the node to use the `apt-cacher-ng` server as a client.
|
||||
|
||||
#### Bypassing the cache
|
||||
Occasionally you may come across repositories that do not play nicely when the node is using an `apt-cacher-ng` server. You can configure `cacher-client` to bypass the server and connect directly to the repository with the `cache_bypass` attribute.
|
||||
|
||||
To do this, you need to override the `cache_bypass` attribute with an array of repositories, with each array key as the repository URL and value as the protocol to use:
|
||||
|
||||
```json
|
||||
{
|
||||
...,
|
||||
'apt': {
|
||||
...,
|
||||
'cache_bypass': {
|
||||
URL: PROTOCOL
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For example, to prevent caching and directly connect to the repository at `download.oracle.com` via http:
|
||||
|
||||
```json
|
||||
{
|
||||
'apt': {
|
||||
'cache_bypass': {
|
||||
'download.oracle.com': 'http'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### cacher-ng
|
||||
Installs the `apt-cacher-ng` package and service so the system can provide APT caching. You can check the usage report at http://{hostname}:3142/acng-report.html.
|
||||
|
||||
If you wish to help the `cacher-ng` recipe seed itself, you must now explicitly include the `cacher-client` recipe in your run list **after** `cacher-ng` or you will block your ability to install any packages (ie. `apt-cacher-ng`).
|
||||
|
||||
|
||||
Attributes
|
||||
----------
|
||||
* `['apt']['cacher_ipaddress']` - use a cacher server (or standard proxy server) not available via search
|
||||
* `['apt']['cacher_interface]` - interface to connect to the cacher-ng service, no default.
|
||||
* `['apt']['cacher_port']` - port for the cacher-ng service (either client or server), default is '3142'
|
||||
* `['apt']['cacher_dir']` - directory used by cacher-ng service, default is '/var/cache/apt-cacher-ng'
|
||||
* `['apt']['cacher-client']['restrict_environment']` - restrict your node to using the `apt-cacher-ng` server in your Environment, default is 'false'
|
||||
* `['apt']['compiletime']` - force the `cacher-client` recipe to run before other recipes. It forces apt to use the proxy before other recipes run. Useful if your nodes have limited access to public apt repositories. This is overridden if the `cacher-ng` recipe is in your run list. Default is 'false'
|
||||
* `['apt']['cache_bypass']` - array of URLs to bypass the cache. Accepts the URL and protocol to fetch directly from the remote repository and not attempt to cache
|
||||
* `['apt']['periodic_update_min_delay']` - minimum delay (in seconds) beetween two actual executions of `apt-get update` by the `execute[apt-get-update-periodic]` resource, default is '86400' (24 hours)
|
||||
|
||||
Libraries
|
||||
---------
|
||||
There is an `interface_ipaddress` method that returns the IP address for a particular host and interface, used by the `cacher-client` recipe. To enable it on the server use the `['apt']['cacher_interface']` attribute.
|
||||
|
||||
Resources/Providers
|
||||
-------------------
|
||||
### `apt_repository`
|
||||
This LWRP provides an easy way to manage additional APT repositories. Adding a new repository will notify running the `execute[apt-get-update]` resource immediately.
|
||||
|
||||
#### Actions
|
||||
- :add: creates a repository file and builds the repository listing
|
||||
- :remove: removes the repository file
|
||||
|
||||
#### Attribute Parameters
|
||||
- repo_name: name attribute. The name of the channel to discover
|
||||
- uri: the base of the Debian distribution
|
||||
- distribution: this is usually your release's codename...ie something like `karmic`, `lucid` or `maverick`
|
||||
- components: package groupings..when it doubt use `main`
|
||||
- arch: constrain package to a particular arch like `i386`, `amd64` or even `armhf` or `powerpc`. Defaults to nil.
|
||||
- trusted: treat all packages from this repository as authenticated regardless of signature
|
||||
- deb_src: whether or not to add the repository as a source repo as well - value can be `true` or `false`, default `false`.
|
||||
- keyserver: the GPG keyserver where the key for the repo should be retrieved
|
||||
- key: if a `keyserver` is provided, this is assumed to be the fingerprint, otherwise it can be either the URI to the GPG key for the repo, or a cookbook_file.
|
||||
- key_proxy: if set, pass the specified proxy via `http-proxy=` to GPG.
|
||||
- cookbook: if key should be a cookbook_file, specify a cookbook where the key is located for files/default. Defaults to nil, so it will use the cookbook where the resource is used.
|
||||
|
||||
#### Examples
|
||||
|
||||
Add the Zenoss repo:
|
||||
|
||||
```ruby
|
||||
apt_repository 'zenoss' do
|
||||
uri 'http://dev.zenoss.org/deb'
|
||||
components ['main', 'stable']
|
||||
end
|
||||
```
|
||||
|
||||
Add the Nginx PPA, grabbing the key from keyserver:
|
||||
|
||||
```ruby
|
||||
apt_repository 'nginx-php' do
|
||||
uri 'http://ppa.launchpad.net/nginx/php5/ubuntu'
|
||||
distribution node['lsb']['codename']
|
||||
components ['main']
|
||||
keyserver 'keyserver.ubuntu.com'
|
||||
key 'C300EE8C'
|
||||
end
|
||||
```
|
||||
|
||||
Add the Nginx PPA, grab the key from the keyserver, and add source repo:
|
||||
|
||||
```ruby
|
||||
apt_repository 'nginx-php' do
|
||||
uri 'http://ppa.launchpad.net/nginx/php5/ubuntu'
|
||||
distribution node['lsb']['codename']
|
||||
components ['main']
|
||||
keyserver 'keyserver.ubuntu.com'
|
||||
key 'C300EE8C'
|
||||
deb_src true
|
||||
end
|
||||
```
|
||||
|
||||
Add the Cloudera Repo of CDH4 packages for Ubuntu 12.04 on AMD64:
|
||||
|
||||
```ruby
|
||||
apt_repository 'cloudera' do
|
||||
uri 'http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh'
|
||||
arch 'amd64'
|
||||
distribution 'precise-cdh4'
|
||||
components ['contrib']
|
||||
key 'http://archive.cloudera.com/debian/archive.key'
|
||||
end
|
||||
```
|
||||
|
||||
Remove Zenoss repo:
|
||||
|
||||
```ruby
|
||||
apt_repository 'zenoss' do
|
||||
action :remove
|
||||
end
|
||||
```
|
||||
|
||||
### `apt_preference`
|
||||
This LWRP provides an easy way to pin packages in /etc/apt/preferences.d. Although apt-pinning is quite helpful from time to time please note that Debian does not encourage its use without thorough consideration.
|
||||
|
||||
Further information regarding apt-pinning is available via http://wiki.debian.org/AptPreferences.
|
||||
|
||||
#### Actions
|
||||
- :add: creates a preferences file under /etc/apt/preferences.d
|
||||
- :remove: Removes the file, therefore unpin the package
|
||||
|
||||
#### Attribute Parameters
|
||||
- package_name: name attribute. The name of the package
|
||||
- glob: Pin by glob() expression or regexp surrounded by /.
|
||||
- pin: The package version/repository to pin
|
||||
- pin_priority: The pinning priority aka "the highest package version wins"
|
||||
|
||||
#### Examples
|
||||
Pin libmysqlclient16 to version 5.1.49-3:
|
||||
|
||||
```ruby
|
||||
apt_preference 'libmysqlclient16' do
|
||||
pin 'version 5.1.49-3'
|
||||
pin_priority '700'
|
||||
end
|
||||
```
|
||||
|
||||
Unpin libmysqlclient16:
|
||||
|
||||
```ruby
|
||||
apt_preference 'libmysqlclient16' do
|
||||
action :remove
|
||||
end
|
||||
```
|
||||
|
||||
Pin all packages from dotdeb.org:
|
||||
|
||||
```ruby
|
||||
apt_preference 'dotdeb' do
|
||||
glob '*'
|
||||
pin 'origin packages.dotdeb.org'
|
||||
pin_priority '700'
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
Put `recipe[apt]` first in the run list. If you have other recipes that you want to use to configure how apt behaves, like new sources, notify the execute resource to run, e.g.:
|
||||
|
||||
```ruby
|
||||
template '/etc/apt/sources.list.d/my_apt_sources.list' do
|
||||
notifies :run, 'execute[apt-get update]', :immediately
|
||||
end
|
||||
```
|
||||
|
||||
The above will run during execution phase since it is a normal template resource, and should appear before other package resources that need the sources in the template.
|
||||
|
||||
Put `recipe[apt::cacher-ng]` in the run_list for a server to provide APT caching and add `recipe[apt::cacher-client]` on the rest of the Debian-based nodes to take advantage of the caching server.
|
||||
|
||||
If you want to cleanup unused packages, there is also the `apt-get autoclean` and `apt-get autoremove` resources provided for automated cleanup.
|
||||
|
||||
|
||||
License & Authors
|
||||
-----------------
|
||||
- Author:: Joshua Timberman (joshua@opscode.com)
|
||||
- Author:: Matt Ray (matt@opscode.com)
|
||||
- Author:: Seth Chisamore (schisamo@opscode.com)
|
||||
|
||||
```text
|
||||
Copyright 2009-2013, Opscode, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Attributes:: default
|
||||
#
|
||||
# Copyright 2009-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
default['apt']['cacher-client']['restrict_environment'] = false
|
||||
default['apt']['cacher_dir'] = '/var/cache/apt-cacher-ng'
|
||||
default['apt']['cacher_interface'] = nil
|
||||
default['apt']['cacher_port'] = 3142
|
||||
default['apt']['caching_server'] = false
|
||||
default['apt']['compiletime'] = false
|
||||
default['apt']['key_proxy'] = ''
|
||||
default['apt']['cache_bypass'] = {}
|
||||
default['apt']['periodic_update_min_delay'] = 86_400
|
||||
@@ -0,0 +1,50 @@
|
||||
[DEFAULT]
|
||||
;; All times are in seconds, but you can add a suffix
|
||||
;; for minutes(m), hours(h) or days(d)
|
||||
|
||||
;; commented out address so apt-proxy will listen on all IPs
|
||||
;; address = 127.0.0.1
|
||||
port = 9999
|
||||
cache_dir = /var/cache/apt-proxy
|
||||
|
||||
;; Control files (Packages/Sources/Contents) refresh rate
|
||||
min_refresh_delay = 1s
|
||||
complete_clientless_downloads = 1
|
||||
|
||||
;; Debugging settings.
|
||||
debug = all:4 db:0
|
||||
|
||||
time = 30
|
||||
passive_ftp = on
|
||||
|
||||
;;--------------------------------------------------------------
|
||||
;; Cache housekeeping
|
||||
|
||||
cleanup_freq = 1d
|
||||
max_age = 120d
|
||||
max_versions = 3
|
||||
|
||||
;;---------------------------------------------------------------
|
||||
;; Backend servers
|
||||
;;
|
||||
;; Place each server in its own [section]
|
||||
|
||||
[ubuntu]
|
||||
; Ubuntu archive
|
||||
backends =
|
||||
http://us.archive.ubuntu.com/ubuntu
|
||||
|
||||
[ubuntu-security]
|
||||
; Ubuntu security updates
|
||||
backends = http://security.ubuntu.com/ubuntu
|
||||
|
||||
[debian]
|
||||
;; Backend servers, in order of preference
|
||||
backends =
|
||||
http://debian.osuosl.org/debian/
|
||||
|
||||
[security]
|
||||
;; Debian security archive
|
||||
backends =
|
||||
http://security.debian.org/debian-security
|
||||
http://ftp2.de.debian.org/debian-security
|
||||
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Library:: helpers
|
||||
#
|
||||
# Copyright 2013 Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module Apt
|
||||
# Helpers for apt
|
||||
module Helpers
|
||||
# Determines if apt is installed on a system.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def apt_installed?
|
||||
!which('apt-get').nil?
|
||||
end
|
||||
|
||||
# Finds a command in $PATH
|
||||
#
|
||||
# @return [String, nil]
|
||||
def which(cmd)
|
||||
paths = (ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin))
|
||||
|
||||
paths.each do |path|
|
||||
possible = File.join(path, cmd)
|
||||
return possible if File.executable?(possible)
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Chef::Recipe.send(:include, ::Apt::Helpers)
|
||||
Chef::Resource.send(:include, ::Apt::Helpers)
|
||||
Chef::Provider.send(:include, ::Apt::Helpers)
|
||||
@@ -0,0 +1,17 @@
|
||||
if defined?(ChefSpec)
|
||||
def add_apt_preference(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:apt_preference, :add, resource_name)
|
||||
end
|
||||
|
||||
def remove_apt_preference(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:apt_preference, :remove, resource_name)
|
||||
end
|
||||
|
||||
def add_apt_repository(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :add, resource_name)
|
||||
end
|
||||
|
||||
def remove_apt_repository(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :remove, resource_name)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# library:: network
|
||||
#
|
||||
# Copyright 2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module ::Apt
|
||||
def interface_ipaddress(host, interface)
|
||||
if interface
|
||||
addresses = host['network']['interfaces'][interface]['addresses']
|
||||
addresses.select do |ip, data|
|
||||
return ip if data['family'].eql?('inet')
|
||||
end
|
||||
else
|
||||
return host.ipaddress
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,34 @@
|
||||
name 'apt'
|
||||
maintainer 'Opscode, Inc.'
|
||||
maintainer_email 'cookbooks@opscode.com'
|
||||
license 'Apache 2.0'
|
||||
description 'Configures apt and apt services and LWRPs for managing apt repositories and preferences'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '2.3.8'
|
||||
recipe 'apt', 'Runs apt-get update during compile phase and sets up preseed directories'
|
||||
recipe 'apt::cacher-ng', 'Set up an apt-cacher-ng caching proxy'
|
||||
recipe 'apt::cacher-client', 'Client for the apt::cacher-ng caching proxy'
|
||||
|
||||
%w{ ubuntu debian }.each do |os|
|
||||
supports os
|
||||
end
|
||||
|
||||
attribute 'apt/cacher-client/restrict_environment',
|
||||
:description => 'Whether to restrict the search for the caching server to the same environment as this node',
|
||||
:default => 'false'
|
||||
|
||||
attribute 'apt/cacher_port',
|
||||
:description => 'Default listen port for the caching server',
|
||||
:default => '3142'
|
||||
|
||||
attribute 'apt/cacher_interface',
|
||||
:description => 'Default listen interface for the caching server',
|
||||
:default => nil
|
||||
|
||||
attribute 'apt/key_proxy',
|
||||
:description => 'Passed as the proxy passed to GPG for the apt_repository resource',
|
||||
:default => ''
|
||||
|
||||
attribute 'apt/caching_server',
|
||||
:description => 'Set this to true if the node is a caching server',
|
||||
:default => 'false'
|
||||
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Provider:: preference
|
||||
#
|
||||
# Copyright 2010-2011, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# Build preferences.d file contents
|
||||
def build_pref(package_name, pin, pin_priority)
|
||||
"Package: #{package_name}\nPin: #{pin}\nPin-Priority: #{pin_priority}\n"
|
||||
end
|
||||
|
||||
action :add do
|
||||
new_resource.updated_by_last_action(false)
|
||||
|
||||
preference = build_pref(
|
||||
new_resource.glob || new_resource.package_name,
|
||||
new_resource.pin,
|
||||
new_resource.pin_priority
|
||||
)
|
||||
|
||||
preference_dir = directory '/etc/apt/preferences.d' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00755
|
||||
recursive true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
preference_file = file "/etc/apt/preferences.d/#{new_resource.name}" do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00644
|
||||
content preference
|
||||
action :nothing
|
||||
end
|
||||
|
||||
preference_dir.run_action(:create)
|
||||
# write out the preference file, replace it if it already exists
|
||||
preference_file.run_action(:create)
|
||||
end
|
||||
|
||||
action :remove do
|
||||
if ::File.exists?("/etc/apt/preferences.d/#{new_resource.name}")
|
||||
Chef::Log.info "Un-pinning #{new_resource.name} from /etc/apt/preferences.d/"
|
||||
file "/etc/apt/preferences.d/#{new_resource.name}" do
|
||||
action :delete
|
||||
end
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,150 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Provider:: repository
|
||||
#
|
||||
# Copyright 2010-2011, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
use_inline_resources if defined?(use_inline_resources)
|
||||
|
||||
def whyrun_supported?
|
||||
true
|
||||
end
|
||||
|
||||
# install apt key from keyserver
|
||||
def install_key_from_keyserver(key, keyserver)
|
||||
execute "install-key #{key}" do
|
||||
if !node['apt']['key_proxy'].empty?
|
||||
command "apt-key adv --keyserver-options http-proxy=#{node['apt']['key_proxy']} --keyserver hkp://#{keyserver}:80 --recv #{key}"
|
||||
else
|
||||
command "apt-key adv --keyserver #{keyserver} --recv #{key}"
|
||||
end
|
||||
action :run
|
||||
not_if do
|
||||
extract_fingerprints_from_cmd('apt-key finger').any? do |fingerprint|
|
||||
fingerprint.end_with?(key.upcase)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# run command and extract gpg ids
|
||||
def extract_fingerprints_from_cmd(cmd)
|
||||
so = Mixlib::ShellOut.new(cmd)
|
||||
so.run_command
|
||||
so.stdout.split(/\n/).map do |t|
|
||||
if z = t.match(/^ +Key fingerprint = ([0-9A-F ]+)/)
|
||||
z[1].split.join
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
# install apt key from URI
|
||||
def install_key_from_uri(uri)
|
||||
key_name = uri.split(/\//).last
|
||||
cached_keyfile = "#{Chef::Config[:file_cache_path]}/#{key_name}"
|
||||
if new_resource.key =~ /http/
|
||||
remote_file cached_keyfile do
|
||||
source new_resource.key
|
||||
mode 00644
|
||||
action :create
|
||||
end
|
||||
else
|
||||
cookbook_file cached_keyfile do
|
||||
source new_resource.key
|
||||
cookbook new_resource.cookbook
|
||||
mode 00644
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
execute "install-key #{key_name}" do
|
||||
command "apt-key add #{cached_keyfile}"
|
||||
action :run
|
||||
not_if do
|
||||
installed_keys = extract_fingerprints_from_cmd('apt-key finger')
|
||||
proposed_keys = extract_fingerprints_from_cmd("gpg --with-fingerprint #{cached_keyfile}")
|
||||
(installed_keys & proposed_keys).sort == proposed_keys.sort
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# build repo file contents
|
||||
def build_repo(uri, distribution, components, trusted, arch, add_deb_src)
|
||||
components = components.join(' ') if components.respond_to?(:join)
|
||||
repo_options = []
|
||||
repo_options << "arch=#{arch}" if arch
|
||||
repo_options << 'trusted=yes' if trusted
|
||||
repo_options = '[' + repo_options.join(' ') + ']' unless repo_options.empty?
|
||||
repo_info = "#{uri} #{distribution} #{components}\n"
|
||||
repo_info = "#{repo_options} #{repo_info}" unless repo_options.empty?
|
||||
repo = "deb #{repo_info}"
|
||||
repo << "deb-src #{repo_info}" if add_deb_src
|
||||
repo
|
||||
end
|
||||
|
||||
action :add do
|
||||
# add key
|
||||
if new_resource.keyserver && new_resource.key
|
||||
install_key_from_keyserver(new_resource.key, new_resource.keyserver)
|
||||
elsif new_resource.key
|
||||
install_key_from_uri(new_resource.key)
|
||||
end
|
||||
|
||||
file '/var/lib/apt/periodic/update-success-stamp' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'apt-cache gencaches' do
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'apt-get update' do
|
||||
command "apt-get update -o Dir::Etc::sourcelist='sources.list.d/#{new_resource.name}.list' -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0'"
|
||||
ignore_failure true
|
||||
action :nothing
|
||||
notifies :run, 'execute[apt-cache gencaches]', :immediately
|
||||
end
|
||||
|
||||
# build repo file
|
||||
repository = build_repo(
|
||||
new_resource.uri,
|
||||
new_resource.distribution,
|
||||
new_resource.components,
|
||||
new_resource.trusted,
|
||||
new_resource.arch,
|
||||
new_resource.deb_src
|
||||
)
|
||||
|
||||
file "/etc/apt/sources.list.d/#{new_resource.name}.list" do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00644
|
||||
content repository
|
||||
action :create
|
||||
notifies :delete, 'file[/var/lib/apt/periodic/update-success-stamp]', :immediately
|
||||
notifies :run, 'execute[apt-get update]', :immediately if new_resource.cache_rebuild
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
if ::File.exists?("/etc/apt/sources.list.d/#{new_resource.name}.list")
|
||||
Chef::Log.info "Removing #{new_resource.name} repository from /etc/apt/sources.list.d/"
|
||||
file "/etc/apt/sources.list.d/#{new_resource.name}.list" do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,81 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Recipe:: cacher-client
|
||||
#
|
||||
# Copyright 2011-2013 Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
class ::Chef::Recipe
|
||||
include ::Apt
|
||||
end
|
||||
|
||||
# remove Acquire::http::Proxy lines from /etc/apt/apt.conf since we use 01proxy
|
||||
# these are leftover from preseed installs
|
||||
execute 'Remove proxy from /etc/apt/apt.conf' do
|
||||
command "sed --in-place '/^Acquire::http::Proxy/d' /etc/apt/apt.conf"
|
||||
only_if 'grep Acquire::http::Proxy /etc/apt/apt.conf'
|
||||
end
|
||||
|
||||
servers = []
|
||||
if node['apt']
|
||||
if node['apt']['cacher_ipaddress']
|
||||
cacher = Chef::Node.new
|
||||
cacher.default.name = node['apt']['cacher_ipaddress']
|
||||
cacher.default.ipaddress = node['apt']['cacher_ipaddress']
|
||||
cacher.default.apt.cacher_port = node['apt']['cacher_port']
|
||||
cacher.default.apt_cacher_interface = node['apt']['cacher_interface']
|
||||
servers << cacher
|
||||
elsif node['apt']['caching_server']
|
||||
node.override['apt']['compiletime'] = false
|
||||
servers << node
|
||||
end
|
||||
end
|
||||
|
||||
unless Chef::Config[:solo] || servers.length > 0
|
||||
query = 'apt_caching_server:true'
|
||||
query += " AND chef_environment:#{node.chef_environment}" if node['apt']['cacher-client']['restrict_environment']
|
||||
Chef::Log.debug("apt::cacher-client searching for '#{query}'")
|
||||
servers += search(:node, query)
|
||||
end
|
||||
|
||||
if servers.length > 0
|
||||
Chef::Log.info("apt-cacher-ng server found on #{servers[0]}.")
|
||||
if servers[0]['apt']['cacher_interface']
|
||||
cacher_ipaddress = interface_ipaddress(servers[0], servers[0]['apt']['cacher_interface'])
|
||||
else
|
||||
cacher_ipaddress = servers[0].ipaddress
|
||||
end
|
||||
t = template '/etc/apt/apt.conf.d/01proxy' do
|
||||
source '01proxy.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00644
|
||||
variables(
|
||||
:proxy => cacher_ipaddress,
|
||||
:port => servers[0]['apt']['cacher_port'],
|
||||
:bypass => node['apt']['cache_bypass']
|
||||
)
|
||||
action(node['apt']['compiletime'] ? :nothing : :create)
|
||||
notifies :run, 'execute[apt-get update]', :immediately
|
||||
end
|
||||
t.run_action(:create) if node['apt']['compiletime']
|
||||
else
|
||||
Chef::Log.info('No apt-cacher-ng server found.')
|
||||
file '/etc/apt/apt.conf.d/01proxy' do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
include_recipe 'apt::default'
|
||||
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Recipe:: cacher-ng
|
||||
#
|
||||
# Copyright 2008-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
node.set['apt']['caching_server'] = true
|
||||
|
||||
package 'apt-cacher-ng' do
|
||||
action :install
|
||||
end
|
||||
|
||||
directory node['apt']['cacher_dir'] do
|
||||
owner 'apt-cacher-ng'
|
||||
group 'apt-cacher-ng'
|
||||
mode 0755
|
||||
end
|
||||
|
||||
template '/etc/apt-cacher-ng/acng.conf' do
|
||||
source 'acng.conf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00644
|
||||
notifies :restart, 'service[apt-cacher-ng]', :immediately
|
||||
end
|
||||
|
||||
service 'apt-cacher-ng' do
|
||||
supports :restart => true, :status => false
|
||||
action [:enable, :start]
|
||||
end
|
||||
@@ -0,0 +1,82 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2008-2013, Opscode, Inc.
|
||||
# Copyright 2009, Bryan McLellan <btm@loftninjas.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# On systems where apt is not installed, the resources in this recipe are not
|
||||
# executed. However, they _must_ still be present in the resource collection
|
||||
# or other cookbooks which notify these resources will fail on non-apt-enabled
|
||||
# systems.
|
||||
|
||||
Chef::Log.debug 'apt is not installed. Apt-specific resources will not be executed.' unless apt_installed?
|
||||
|
||||
# Run apt-get update to create the stamp file
|
||||
execute 'apt-get-update' do
|
||||
command 'apt-get update'
|
||||
ignore_failure true
|
||||
only_if { apt_installed? }
|
||||
not_if { ::File.exists?('/var/lib/apt/periodic/update-success-stamp') }
|
||||
end
|
||||
|
||||
# For other recipes to call to force an update
|
||||
execute 'apt-get update' do
|
||||
command 'apt-get update'
|
||||
ignore_failure true
|
||||
only_if { apt_installed? }
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# Automatically remove packages that are no longer needed for dependencies
|
||||
execute 'apt-get autoremove' do
|
||||
command 'apt-get -y autoremove'
|
||||
only_if { apt_installed? }
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# Automatically remove .deb files for packages no longer on your system
|
||||
execute 'apt-get autoclean' do
|
||||
command 'apt-get -y autoclean'
|
||||
only_if { apt_installed? }
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# provides /var/lib/apt/periodic/update-success-stamp on apt-get update
|
||||
package 'update-notifier-common' do
|
||||
notifies :run, 'execute[apt-get-update]', :immediately
|
||||
only_if { apt_installed? }
|
||||
end
|
||||
|
||||
execute 'apt-get-update-periodic' do
|
||||
command 'apt-get update'
|
||||
ignore_failure true
|
||||
only_if do
|
||||
apt_installed? &&
|
||||
::File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
|
||||
::File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - node['apt']['periodic_update_min_delay']
|
||||
end
|
||||
end
|
||||
|
||||
%w{/var/cache/local /var/cache/local/preseeding}.each do |dirname|
|
||||
directory dirname do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 00755
|
||||
action :create
|
||||
only_if { apt_installed? }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Resource:: preference
|
||||
#
|
||||
# Copyright 2010-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :remove
|
||||
default_action :add if defined?(default_action) # Chef > 10.8
|
||||
|
||||
# Needed for Chef versions < 0.10.10
|
||||
def initialize(*args)
|
||||
super
|
||||
@action = :add
|
||||
end
|
||||
|
||||
attribute :package_name, :kind_of => String, :name_attribute => true
|
||||
attribute :glob, :kind_of => String
|
||||
attribute :pin, :kind_of => String
|
||||
attribute :pin_priority, :kind_of => String
|
||||
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# Cookbook Name:: apt
|
||||
# Resource:: repository
|
||||
#
|
||||
# Copyright 2010-2013, Opscode, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
actions :add, :remove
|
||||
default_action :add if defined?(default_action) # Chef > 10.8
|
||||
|
||||
# Needed for Chef versions < 0.10.10
|
||||
def initialize(*args)
|
||||
super
|
||||
@action = :add
|
||||
end
|
||||
|
||||
# name of the repo, used for source.list filename
|
||||
attribute :repo_name, :kind_of => String, :name_attribute => true
|
||||
attribute :uri, :kind_of => String
|
||||
attribute :distribution, :kind_of => String
|
||||
attribute :components, :kind_of => Array, :default => []
|
||||
attribute :arch, :kind_of => String, :default => nil
|
||||
attribute :trusted, :kind_of => [TrueClass, FalseClass], :default => false
|
||||
# whether or not to add the repository as a source repo as well
|
||||
attribute :deb_src, :default => false
|
||||
attribute :keyserver, :kind_of => String, :default => nil
|
||||
attribute :key, :kind_of => String, :default => nil
|
||||
attribute :cookbook, :kind_of => String, :default => nil
|
||||
# trigger cache rebuild
|
||||
# If not you can trigger in the recipe itself after checking the status of resource.updated{_by_last_action}?
|
||||
attribute :cache_rebuild, :kind_of => [TrueClass, FalseClass], :default => true
|
||||
@@ -0,0 +1,173 @@
|
||||
# Letter case in directive names does not matter. Must be separated with colons.
|
||||
# Valid boolean values are a zero number for false, non-zero numbers for true.
|
||||
|
||||
CacheDir: <%= node['apt']['cacher_dir'] %>
|
||||
|
||||
# set empty to disable logging
|
||||
LogDir: /var/log/apt-cacher-ng
|
||||
|
||||
# TCP (http) port
|
||||
# Set to 9999 to emulate apt-proxy
|
||||
Port:<%= node['apt']['cacher_port'] %>
|
||||
|
||||
# Addresses or hostnames to listen on. Multiple addresses must be separated by
|
||||
# spaces. Each entry must be associated with a local interface. DNS resolution
|
||||
# is performed using getaddrinfo(3) for all available protocols (i.e. IPv4 and
|
||||
# IPv6 if available).
|
||||
#
|
||||
# Default: not set, will listen on all interfaces.
|
||||
#
|
||||
# BindAddress: localhost 192.168.7.254 publicNameOnMainInterface
|
||||
|
||||
#Proxy: http://www-proxy.example.net:80
|
||||
#proxy: http://username:proxypassword@proxy.example.net:3128
|
||||
|
||||
# Repository remapping. See manual for details.
|
||||
# In this example, backends file is generated during package installation.
|
||||
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian
|
||||
Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu
|
||||
Remap-debvol: file:debvol_mirror*.gz /debian-volatile ; file:backends_debvol
|
||||
Remap-cygwin: file:cygwin_mirrors /cygwin # ; file:backends_cygwin # incomplete, please create this file
|
||||
|
||||
# Virtual page accessible in a web browser to see statistics and status
|
||||
# information, i.e. under http://localhost:3142/acng-report.html
|
||||
ReportPage: acng-report.html
|
||||
|
||||
# Socket file for accessing through local UNIX socket instead of TCP/IP. Can be
|
||||
# used with inetd bridge or cron client.
|
||||
# SocketPath:/var/run/apt-cacher-ng/socket
|
||||
|
||||
# Forces log file to be written to disk after every line when set to 1. Default
|
||||
# is 0, buffer flush happens after client disconnects.
|
||||
#
|
||||
# (technically, this is an alias to the Debug option provided for convenience)
|
||||
#
|
||||
# UnbufferLogs: 0
|
||||
|
||||
# Set to 0 to store only type, time and transfer sizes.
|
||||
# 1 -> client IP and relative local path are logged too
|
||||
# VerboseLog: 1
|
||||
|
||||
# Don't detach from the console
|
||||
# ForeGround: 0
|
||||
|
||||
# Store the pid of the daemon process therein
|
||||
# PidFile: /var/run/apt-cacher-ng/pid
|
||||
|
||||
# Forbid outgoing connections, work around them or respond with 503 error
|
||||
# offlinemode:0
|
||||
|
||||
# Forbid all downloads that don't run through preconfigured backends (.where)
|
||||
#ForceManaged: 0
|
||||
|
||||
# Days before considering an unreferenced file expired (to be deleted).
|
||||
# Warning: if the value is set too low and particular index files are not
|
||||
# available for some days (mirror downtime) there is a risk of deletion of
|
||||
# still usefull package files.
|
||||
ExTreshold: 4
|
||||
|
||||
# Stop expiration when a critical problem appeared. Currently only failed
|
||||
# refresh of an index file is considered as critical.
|
||||
#
|
||||
# WARNING: don't touch this option or set to a non-zero number.
|
||||
# Anything else is DANGEROUS and may cause data loss.
|
||||
#
|
||||
# ExAbortOnProblems: 1
|
||||
|
||||
# Replace some Windows/DOS-FS incompatible chars when storing
|
||||
# StupidFs: 0
|
||||
|
||||
# Experimental feature for apt-listbugs: pass-through SOAP requests and
|
||||
# responses to/from bugs.debian.org. If not set, default is true if
|
||||
# ForceManaged is enabled and false otherwise.
|
||||
# ForwardBtsSoap: 1
|
||||
|
||||
# The daemon has a small cache for DNS data, to speed up resolution. The
|
||||
# expiration time of the DNS entries can be configured in seconds.
|
||||
# DnsCacheSeconds: 3600
|
||||
|
||||
# Don't touch the following values without good consideration!
|
||||
#
|
||||
# Max. count of connection threads kept ready (for faster response in the
|
||||
# future). Should be a sane value between 0 and average number of connections,
|
||||
# and depend on the amount of spare RAM.
|
||||
# MaxStandbyConThreads: 8
|
||||
#
|
||||
# Hard limit of active thread count for incomming connections, i.e. operation
|
||||
# is refused when this value is reached (below zero = unlimited).
|
||||
# MaxConThreads: -1
|
||||
#
|
||||
#VfilePattern = (^|.*?/)(Index|Packages\.bz2|Packages\.gz|Packages|Release|Release\.gpg|Sources\.bz2|Sources\.gz|Sources|release|index\.db-.*\.gz|Contents-[^/]*\.gz|pkglist[^/]*\.bz2|rclist[^/]*\.bz2|/meta-release[^/]*|Translation[^/]*\.bz2)$
|
||||
#PfilePattern = .*(\.deb|\.rpm|\.dsc|\.tar\.gz\.gpg|\.tar\.gz|\.diff\.gz|\.diff\.bz2|\.jigdo|\.template|changelog|copyright|\.udeb|\.diff/.*\.gz|vmlinuz|initrd\.gz|(Devel)?ReleaseAnnouncement(\\?.*)?)$
|
||||
# Whitelist for expiration, file types not to be removed even when being
|
||||
# unreferenced. Default: same as VfilePattern which is a safe bed. When and
|
||||
# only when the only used mirrors are official repositories (with working
|
||||
# Release files) then it might be set to something more restrictive, like
|
||||
# (^|.*?/)(Release|Release\.gpg|release|meta-release|Translation[^/]*\.bz2)$
|
||||
#WfilePattern = (^|.*?/)(Index|Packages\.bz2|Packages\.gz|Packages|Release|Release\.gpg|Sources\.bz2|Sources\.gz|Sources|release|index\.db-.*\.gz|Contents-[^/]*\.gz|pkglist[^/]*\.bz2|rclist[^/]*\.bz2|/meta-release[^/]*|Translation[^/]*\.bz2)$
|
||||
|
||||
# Higher modes only working with the debug version
|
||||
# Warning, writes a lot into apt-cacher.err logfile
|
||||
# Value overwrites UnbufferLogs setting (aliased)
|
||||
# Debug:3
|
||||
|
||||
# Usually, general purpose proxies like Squid expose the IP adress of the
|
||||
# client user to the remote server using the X-Forwarded-For HTTP header. This
|
||||
# behaviour can be optionally turned on with the Expose-Origin option.
|
||||
# ExposeOrigin: 0
|
||||
|
||||
# When logging the originating IP address, trust the information supplied by
|
||||
# the client in the X-Forwarded-For header.
|
||||
# LogSubmittedOrigin: 0
|
||||
|
||||
# The version string reported to the peer, to be displayed as HTTP client (and
|
||||
# version) in the logs of the mirror.
|
||||
# WARNING: some archives use this header to detect/guess capabilities of the
|
||||
# client (i.e. redirection support) and change the behaviour accordingly, while
|
||||
# ACNG might not support the expected features. Expect side effects.
|
||||
#
|
||||
# UserAgent: Yet Another HTTP Client/1.2.3p4
|
||||
|
||||
# In some cases the Import and Expiration tasks might create fresh volatile
|
||||
# data for internal use by reconstructing them using patch files. This
|
||||
# by-product might be recompressed with bzip2 and with some luck the resulting
|
||||
# file becomes identical to the *.bz2 file on the server, usable for APT
|
||||
# clients trying to fetch the full .bz2 compressed version. Injection of the
|
||||
# generated files into the cache has however a disadvantage on underpowered
|
||||
# servers: bzip2 compession can create high load on the server system and the
|
||||
# visible download of the busy .bz2 files also becomes slower.
|
||||
#
|
||||
# RecompBz2: 0
|
||||
|
||||
# Network timeout for outgoing connections.
|
||||
# NetworkTimeout: 60
|
||||
|
||||
# Sometimes it makes sense to not store the data in cache and just return the
|
||||
# package data to client as it comes in. DontCache parameters can enable this
|
||||
# behaviour for certain URL types. The tokens are extended regular expressions
|
||||
# that URLs are matched against.
|
||||
#
|
||||
# DontCacheRequested is applied to the URL as it comes in from the client.
|
||||
# Example: exclude packages built with kernel-package for x86
|
||||
# DontCacheRequested: linux-.*_10\...\.Custo._i386
|
||||
# Example usecase: exclude popular private IP ranges from caching
|
||||
# DontCacheRequested: 192.168.0 ^10\..* 172.30
|
||||
#
|
||||
# DontCacheResolved is applied to URLs after mapping to the target server. If
|
||||
# multiple backend servers are specified then it's only matched against the
|
||||
# download link for the FIRST possible source (due to implementation limits).
|
||||
# Example usecase: all Ubuntu stuff comes from a local mirror (specified as
|
||||
# backend), don't cache it again:
|
||||
# DontCacheResolved: ubuntumirror.local.net
|
||||
#
|
||||
# DontCache directive sets (overrides) both, DontCacheResolved and
|
||||
# DontCacheRequested. Provided for convenience, see those directives for
|
||||
# details.
|
||||
#
|
||||
# Default permission set of freshly created files and directories, as octal
|
||||
# numbers (see chmod(1) for details).
|
||||
# Can by limited by the umask value (see umask(2) for details) if it's set in
|
||||
# the environment of the starting shell, e.g. in apt-cacher-ng init script or
|
||||
# in its configuration file.
|
||||
# DirPerms: 00755
|
||||
# FilePerms: 00664
|
||||
@@ -0,0 +1,5 @@
|
||||
Acquire::http::Proxy "http://<%= @proxy %>:<%= @port %>";
|
||||
Acquire::https::Proxy "DIRECT";
|
||||
<% @bypass.each do |bypass, type| %>
|
||||
Acquire::<%= type %>::Proxy::<%= bypass %> "DIRECT";
|
||||
<% end %>
|
||||
@@ -0,0 +1,275 @@
|
||||
# Letter case in directive names does not matter. Must be separated with colons.
|
||||
# Valid boolean values are a zero number for false, non-zero numbers for true.
|
||||
|
||||
CacheDir: <%= node['apt']['cacher_dir'] %>
|
||||
|
||||
# set empty to disable logging
|
||||
LogDir: /var/log/apt-cacher-ng
|
||||
|
||||
# place to look for additional configuration and resource files if they are not
|
||||
# found in the configuration directory
|
||||
# SupportDir: /usr/lib/apt-cacher-ng
|
||||
|
||||
# TCP (http) port
|
||||
# Set to 9999 to emulate apt-proxy
|
||||
Port:<%= node['apt']['cacher_port'] %>
|
||||
|
||||
# Addresses or hostnames to listen on. Multiple addresses must be separated by
|
||||
# spaces. Each entry must be an exact local address which is associated with a
|
||||
# local interface. DNS resolution is performed using getaddrinfo(3) for all
|
||||
# available protocols (IPv4, IPv6, ...). Using a protocol specific format will
|
||||
# create binding(s) only on protocol specific socket(s) (e.g. 0.0.0.0 will listen
|
||||
# only to IPv4).
|
||||
#
|
||||
# Default: not set, will listen on all interfaces and protocols
|
||||
#
|
||||
# BindAddress: localhost 192.168.7.254 publicNameOnMainInterface
|
||||
|
||||
# The specification of another proxy which shall be used for downloads.
|
||||
# Username and password are, and see manual for limitations.
|
||||
#
|
||||
#Proxy: http://www-proxy.example.net:80
|
||||
#proxy: username:proxypassword@proxy.example.net:3128
|
||||
|
||||
# Repository remapping. See manual for details.
|
||||
# In this example, some backends files might be generated during package
|
||||
# installation using information collected on the system.
|
||||
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian # Debian Archives
|
||||
Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu # Ubuntu Archives
|
||||
Remap-debvol: file:debvol_mirror*.gz /debian-volatile ; file:backends_debvol # Debian Volatile Archives
|
||||
Remap-cygwin: file:cygwin_mirrors /cygwin # ; file:backends_cygwin # incomplete, please create this file or specify preferred mirrors here
|
||||
Remap-sfnet: file:sfnet_mirrors # ; file:backends_sfnet # incomplete, please create this file or specify preferred mirrors here
|
||||
Remap-alxrep: file:archlx_mirrors /archlinux # ; file:backend_archlx # Arch Linux
|
||||
Remap-fedora: file:fedora_mirrors # Fedora Linux
|
||||
Remap-epel: file:epel_mirrors # Fedora EPEL
|
||||
Remap-slrep: file:sl_mirrors # Scientific Linux
|
||||
|
||||
# This is usually not needed for security.debian.org because it's always the
|
||||
# same DNS hostname. However, it might be enabled in order to use hooks,
|
||||
# ForceManaged mode or special flags in this context.
|
||||
# Remap-secdeb: security.debian.org
|
||||
|
||||
# Virtual page accessible in a web browser to see statistics and status
|
||||
# information, i.e. under http://localhost:3142/acng-report.html
|
||||
ReportPage: acng-report.html
|
||||
|
||||
# Socket file for accessing through local UNIX socket instead of TCP/IP. Can be
|
||||
# used with inetd bridge or cron client.
|
||||
# SocketPath:/var/run/apt-cacher-ng/socket
|
||||
|
||||
# Forces log file to be written to disk after every line when set to 1. Default
|
||||
# is 0, buffers are flushed when the client disconnects.
|
||||
#
|
||||
# (technically, alias to the Debug option, see its documentation for details)
|
||||
#
|
||||
# UnbufferLogs: 0
|
||||
|
||||
# Set to 0 to store only type, time and transfer sizes.
|
||||
# 1 -> client IP and relative local path are logged too
|
||||
# VerboseLog: 1
|
||||
|
||||
# Don't detach from the console
|
||||
# ForeGround: 0
|
||||
|
||||
# Store the pid of the daemon process therein
|
||||
# PidFile: /var/run/apt-cacher-ng/pid
|
||||
|
||||
# Forbid outgoing connections, work around them or respond with 503 error
|
||||
# offlinemode:0
|
||||
|
||||
# Forbid all downloads that don't run through preconfigured backends (.where)
|
||||
#ForceManaged: 0
|
||||
|
||||
# Days before considering an unreferenced file expired (to be deleted).
|
||||
# Warning: if the value is set too low and particular index files are not
|
||||
# available for some days (mirror downtime) there is a risk of deletion of
|
||||
# still useful package files.
|
||||
ExTreshold: 4
|
||||
|
||||
# Stop expiration when a critical problem appeared. Currently only failed
|
||||
# refresh of an index file is considered as critical.
|
||||
#
|
||||
# WARNING: don't touch this option or set to zero.
|
||||
# Anything else is DANGEROUS and may cause data loss.
|
||||
#
|
||||
# ExAbortOnProblems: 1
|
||||
|
||||
# Replace some Windows/DOS-FS incompatible chars when storing
|
||||
# StupidFs: 0
|
||||
|
||||
# Experimental feature for apt-listbugs: pass-through SOAP requests and
|
||||
# responses to/from bugs.debian.org. If not set, default is true if
|
||||
# ForceManaged is enabled and false otherwise.
|
||||
# ForwardBtsSoap: 1
|
||||
|
||||
# The daemon has a small cache for DNS data, to speed up resolution. The
|
||||
# expiration time of the DNS entries can be configured in seconds.
|
||||
# DnsCacheSeconds: 3600
|
||||
|
||||
# Don't touch the following values without good consideration!
|
||||
#
|
||||
# Max. count of connection threads kept ready (for faster response in the
|
||||
# future). Should be a sane value between 0 and average number of connections,
|
||||
# and depend on the amount of spare RAM.
|
||||
# MaxStandbyConThreads: 8
|
||||
#
|
||||
# Hard limit of active thread count for incoming connections, i.e. operation
|
||||
# is refused when this value is reached (below zero = unlimited).
|
||||
# MaxConThreads: -1
|
||||
#
|
||||
# Pigeonholing files with regular expressions (static/volatile). Can be
|
||||
# overriden here but not should not be done permanently because future update
|
||||
# of default settings would not be applied later.
|
||||
# VfilePattern = (^|.*?/)(Index|Packages(\.gz|\.bz2|\.lzma|\.xz)?|InRelease|Release|Release\.gpg|Sources(\.gz|\.bz2|\.lzma|\.xz)?|release|index\.db-.*\.gz|Contents-[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|pkglist[^/]*\.bz2|rclist[^/]*\.bz2|/meta-release[^/]*|Translation[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|MD5SUMS|SHA1SUMS|((setup|setup-legacy)(\.ini|\.bz2|\.hint)(\.sig)?)|mirrors\.lst|repo(index|md)\.xml(\.asc|\.key)?|directory\.yast|products|content(\.asc|\.key)?|media|filelists\.xml\.gz|filelists\.sqlite\.bz2|repomd\.xml|packages\.[a-zA-Z][a-zA-Z]\.gz|info\.txt|license\.tar\.gz|license\.zip|.*\.db(\.tar\.gz)?|.*\.files\.tar\.gz|.*\.abs\.tar\.gz|metalink\?repo|.*prestodelta\.xml\.gz)$|/dists/.*/installer-[^/]+/[^0-9][^/]+/images/.*
|
||||
# PfilePattern = .*(\.d?deb|\.rpm|\.dsc|\.tar(\.gz|\.bz2|\.lzma|\.xz)(\.gpg)?|\.diff(\.gz|\.bz2|\.lzma|\.xz)|\.jigdo|\.template|changelog|copyright|\.udeb|\.debdelta|\.diff/.*\.gz|(Devel)?ReleaseAnnouncement(\?.*)?|[a-f0-9]+-(susedata|updateinfo|primary|deltainfo).xml.gz|fonts/(final/)?[a-z]+32.exe(\?download.*)?|/dists/.*/installer-[^/]+/[0-9][^/]+/images/.*)$
|
||||
# Whitelist for expiration, file types not to be removed even when being
|
||||
# unreferenced. Default: many parts from VfilePattern where no parent index
|
||||
# exists or might be unknown.
|
||||
# WfilePattern = (^|.*?/)(Release|InRelease|Release\.gpg|(Packages|Sources)(\.gz|\.bz2|\.lzma|\.xz)?|Translation[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|MD5SUMS|SHA1SUMS|.*\.xml|.*\.db\.tar\.gz|.*\.files\.tar\.gz|.*\.abs\.tar\.gz|[a-z]+32.exe)$|/dists/.*/installer-.*/images/.*
|
||||
|
||||
# Higher modes only working with the debug version
|
||||
# Warning, writes a lot into apt-cacher.err logfile
|
||||
# Value overwrites UnbufferLogs setting (aliased)
|
||||
# Debug:3
|
||||
|
||||
# Usually, general purpose proxies like Squid expose the IP address of the
|
||||
# client user to the remote server using the X-Forwarded-For HTTP header. This
|
||||
# behaviour can be optionally turned on with the Expose-Origin option.
|
||||
# ExposeOrigin: 0
|
||||
|
||||
# When logging the originating IP address, trust the information supplied by
|
||||
# the client in the X-Forwarded-For header.
|
||||
# LogSubmittedOrigin: 0
|
||||
|
||||
# The version string reported to the peer, to be displayed as HTTP client (and
|
||||
# version) in the logs of the mirror.
|
||||
# WARNING: some archives use this header to detect/guess capabilities of the
|
||||
# client (i.e. redirection support) and change the behaviour accordingly, while
|
||||
# ACNG might not support the expected features. Expect side effects.
|
||||
#
|
||||
# UserAgent: Yet Another HTTP Client/1.2.3p4
|
||||
|
||||
# In some cases the Import and Expiration tasks might create fresh volatile
|
||||
# data for internal use by reconstructing them using patch files. This
|
||||
# by-product might be recompressed with bzip2 and with some luck the resulting
|
||||
# file becomes identical to the *.bz2 file on the server, usable for APT
|
||||
# clients trying to fetch the full .bz2 compressed version. Injection of the
|
||||
# generated files into the cache has however a disadvantage on underpowered
|
||||
# servers: bzip2 compression can create high load on the server system and the
|
||||
# visible download of the busy .bz2 files also becomes slower.
|
||||
#
|
||||
# RecompBz2: 0
|
||||
|
||||
# Network timeout for outgoing connections.
|
||||
# NetworkTimeout: 60
|
||||
|
||||
# Sometimes it makes sense to not store the data in cache and just return the
|
||||
# package data to client as it comes in. DontCache parameters can enable this
|
||||
# behaviour for certain URL types. The tokens are extended regular expressions
|
||||
# that URLs are matched against.
|
||||
#
|
||||
# DontCacheRequested is applied to the URL as it comes in from the client.
|
||||
# Example: exclude packages built with kernel-package for x86
|
||||
# DontCacheRequested: linux-.*_10\...\.Custo._i386
|
||||
# Example usecase: exclude popular private IP ranges from caching
|
||||
# DontCacheRequested: 192.168.0 ^10\..* 172.30
|
||||
#
|
||||
# DontCacheResolved is applied to URLs after mapping to the target server. If
|
||||
# multiple backend servers are specified then it's only matched against the
|
||||
# download link for the FIRST possible source (due to implementation limits).
|
||||
# Example usecase: all Ubuntu stuff comes from a local mirror (specified as
|
||||
# backend), don't cache it again:
|
||||
# DontCacheResolved: ubuntumirror.local.net
|
||||
#
|
||||
# DontCache directive sets (overrides) both, DontCacheResolved and
|
||||
# DontCacheRequested. Provided for convenience, see those directives for
|
||||
# details.
|
||||
#
|
||||
# Default permission set of freshly created files and directories, as octal
|
||||
# numbers (see chmod(1) for details).
|
||||
# Can by limited by the umask value (see umask(2) for details) if it's set in
|
||||
# the environment of the starting shell, e.g. in apt-cacher-ng init script or
|
||||
# in its configuration file.
|
||||
# DirPerms: 00755
|
||||
# FilePerms: 00664
|
||||
#
|
||||
#
|
||||
# It's possible to use use apt-cacher-ng as a regular web server with limited
|
||||
# feature set, i.e.
|
||||
# including directory browsing and download of any file;
|
||||
# excluding sorting, mime types/encodings, CGI execution, index page
|
||||
# redirection and other funny things.
|
||||
# To get this behavior, mappings between virtual directories and real
|
||||
# directories on the server must be defined with the LocalDirs directive.
|
||||
# Virtual and real dirs are separated by spaces, multiple pairs are separated
|
||||
# by semi-colons. Real directories must be absolute paths.
|
||||
# NOTE: Since the names of that key directories share the same namespace as
|
||||
# repository names (see Remap-...) it's administrators job to avoid such
|
||||
# collisions on them (unless created deliberately).
|
||||
#
|
||||
# LocalDirs: woo /data/debarchive/woody ; hamm /data/debarchive/hamm
|
||||
|
||||
# Precache a set of files referenced by specified index files. This can be used
|
||||
# to create a partial mirror usable for offline work. There are certain limits
|
||||
# and restrictions on the path specification, see manual for details. A list of
|
||||
# (maybe) relevant index files could be retrieved via
|
||||
# "apt-get --print-uris update" on a client machine.
|
||||
#
|
||||
# PrecacheFor: debrep/dists/unstable/*/source/Sources* debrep/dists/unstable/*/binary-amd64/Packages*
|
||||
|
||||
# Arbitrary set of data to append to request headers sent over the wire. Should
|
||||
# be a well formated HTTP headers part including newlines (DOS style) which
|
||||
# can be entered as escape sequences (\r\n).
|
||||
# RequestAppendix: X-Tracking-Choice: do-not-track\r\n
|
||||
|
||||
# Specifies the IP protocol families to use for remote connections. Order does
|
||||
# matter, first specified are considered first. Possible combinations:
|
||||
# v6 v4
|
||||
# v4 v6
|
||||
# v6
|
||||
# v4
|
||||
# (empty or not set: use system default)
|
||||
#
|
||||
# ConnectProto: v6 v4
|
||||
|
||||
# Regular expiration algorithm finds package files which are no longer listed
|
||||
# in any index file and removes them of them after a safety period.
|
||||
# This option allows to keep more versions of a package in the cache after
|
||||
# safety period is over.
|
||||
# KeepExtraVersions: 1
|
||||
|
||||
# Optionally uses TCP access control provided by libwrap, see hosts_access(5)
|
||||
# for details. Daemon name is apt-cacher-ng. Default if not set: decided on
|
||||
# startup by looking for explicit mentioning of apt-cacher-ng in
|
||||
# /etc/hosts.allow or /etc/hosts.deny files.
|
||||
# UseWrap: 0
|
||||
|
||||
# If many machines from the same local network attempt to update index files
|
||||
# (apt-get update) at nearly the same time, the known state of these index file
|
||||
# is temporarily frozen and multiple requests receive the cached response
|
||||
# without contacting the server. This parameter (in seconds) specifies the
|
||||
# length of this period before the files are considered outdated.
|
||||
# Setting it too low transfers more data and increases remote server load,
|
||||
# setting it too high (more than a couple of minutes) increases the risk of
|
||||
# delivering inconsistent responses to the clients.
|
||||
# FreshIndexMaxAge: 27
|
||||
|
||||
# Usually the users are not allowed to specify custom TCP ports of remote
|
||||
# mirrors in the requests, only the default HTTP port can be used (instead,
|
||||
# proxy administrator can create Remap- rules with custom ports). This
|
||||
# restriction can be disabled by specifying a list of allowed ports or 0 for
|
||||
# any port.
|
||||
#
|
||||
# AllowUserPorts: 80
|
||||
|
||||
# Normally the HTTP redirection responses are forwarded to the original caller
|
||||
# (i.e. APT) which starts a new download attempt from the new URL. This
|
||||
# solution is ok for client configurations with proxy mode but doesn't work
|
||||
# well with configurations using URL prefixes. To work around this the server
|
||||
# can restart its own download with another URL. However, this might be used to
|
||||
# circumvent download source policies by malicious users.
|
||||
# The RedirMax option specifies how many such redirects the server should
|
||||
# follow per request, 0 disables the internal redirection. If not set,
|
||||
# default value is 0 if ForceManaged is used and 5 otherwise.
|
||||
#
|
||||
# RedirMax: 5
|
||||
@@ -0,0 +1,269 @@
|
||||
# Letter case in directive names does not matter. Must be separated with colons.
|
||||
# Valid boolean values are a zero number for false, non-zero numbers for true.
|
||||
|
||||
CacheDir: <%= node['apt']['cacher_dir'] %>
|
||||
|
||||
# set empty to disable logging
|
||||
LogDir: /var/log/apt-cacher-ng
|
||||
|
||||
# place to look for additional configuration and resource files if they are not
|
||||
# found in the configuration directory
|
||||
# SupportDir: /usr/lib/apt-cacher-ng
|
||||
|
||||
# TCP (http) port
|
||||
# Set to 9999 to emulate apt-proxy
|
||||
Port:<%= node['apt']['cacher_port'] %>
|
||||
|
||||
# Addresses or hostnames to listen on. Multiple addresses must be separated by
|
||||
# spaces. Each entry must be an exact local address which is associated with a
|
||||
# local interface. DNS resolution is performed using getaddrinfo(3) for all
|
||||
# available protocols (IPv4, IPv6, ...). Using a protocol specific format will
|
||||
# create binding(s) only on protocol specific socket(s) (e.g. 0.0.0.0 will listen
|
||||
# only to IPv4).
|
||||
#
|
||||
# Default: not set, will listen on all interfaces and protocols
|
||||
#
|
||||
# BindAddress: localhost 192.168.7.254 publicNameOnMainInterface
|
||||
|
||||
# The specification of another proxy which shall be used for downloads.
|
||||
# Username and password are, and see manual for limitations.
|
||||
#
|
||||
#Proxy: http://www-proxy.example.net:80
|
||||
#proxy: username:proxypassword@proxy.example.net:3128
|
||||
|
||||
# Repository remapping. See manual for details.
|
||||
# In this example, some backends files might be generated during package
|
||||
# installation using information collected on the system.
|
||||
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian # Debian Archives
|
||||
Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu # Ubuntu Archives
|
||||
Remap-debvol: file:debvol_mirror*.gz /debian-volatile ; file:backends_debvol # Debian Volatile Archives
|
||||
|
||||
# This is usually not needed for security.debian.org because it's always the
|
||||
# same DNS hostname. However, it might be enabled in order to use hooks,
|
||||
# ForceManaged mode or special flags in this context.
|
||||
# Remap-secdeb: security.debian.org
|
||||
|
||||
# Virtual page accessible in a web browser to see statistics and status
|
||||
# information, i.e. under http://localhost:3142/acng-report.html
|
||||
ReportPage: acng-report.html
|
||||
|
||||
# Socket file for accessing through local UNIX socket instead of TCP/IP. Can be
|
||||
# used with inetd bridge or cron client.
|
||||
# SocketPath:/var/run/apt-cacher-ng/socket
|
||||
|
||||
# Forces log file to be written to disk after every line when set to 1. Default
|
||||
# is 0, buffers are flushed when the client disconnects.
|
||||
#
|
||||
# (technically, alias to the Debug option, see its documentation for details)
|
||||
#
|
||||
# UnbufferLogs: 0
|
||||
|
||||
# Set to 0 to store only type, time and transfer sizes.
|
||||
# 1 -> client IP and relative local path are logged too
|
||||
# VerboseLog: 1
|
||||
|
||||
# Don't detach from the console
|
||||
# ForeGround: 0
|
||||
|
||||
# Store the pid of the daemon process therein
|
||||
# PidFile: /var/run/apt-cacher-ng/pid
|
||||
|
||||
# Forbid outgoing connections, work around them or respond with 503 error
|
||||
# offlinemode:0
|
||||
|
||||
# Forbid all downloads that don't run through preconfigured backends (.where)
|
||||
#ForceManaged: 0
|
||||
|
||||
# Days before considering an unreferenced file expired (to be deleted).
|
||||
# Warning: if the value is set too low and particular index files are not
|
||||
# available for some days (mirror downtime) there is a risk of deletion of
|
||||
# still useful package files.
|
||||
ExTreshold: 4
|
||||
|
||||
# Stop expiration when a critical problem appeared. Currently only failed
|
||||
# refresh of an index file is considered as critical.
|
||||
#
|
||||
# WARNING: don't touch this option or set to zero.
|
||||
# Anything else is DANGEROUS and may cause data loss.
|
||||
#
|
||||
# ExAbortOnProblems: 1
|
||||
|
||||
# Replace some Windows/DOS-FS incompatible chars when storing
|
||||
# StupidFs: 0
|
||||
|
||||
# Experimental feature for apt-listbugs: pass-through SOAP requests and
|
||||
# responses to/from bugs.debian.org. If not set, default is true if
|
||||
# ForceManaged is enabled and false otherwise.
|
||||
# ForwardBtsSoap: 1
|
||||
|
||||
# The daemon has a small cache for DNS data, to speed up resolution. The
|
||||
# expiration time of the DNS entries can be configured in seconds.
|
||||
# DnsCacheSeconds: 3600
|
||||
|
||||
# Don't touch the following values without good consideration!
|
||||
#
|
||||
# Max. count of connection threads kept ready (for faster response in the
|
||||
# future). Should be a sane value between 0 and average number of connections,
|
||||
# and depend on the amount of spare RAM.
|
||||
# MaxStandbyConThreads: 8
|
||||
#
|
||||
# Hard limit of active thread count for incoming connections, i.e. operation
|
||||
# is refused when this value is reached (below zero = unlimited).
|
||||
# MaxConThreads: -1
|
||||
#
|
||||
# Pigeonholing files with regular expressions (static/volatile). Can be
|
||||
# overriden here but not should not be done permanently because future update
|
||||
# of default settings would not be applied later.
|
||||
# VfilePattern = (^|.*?/)(Index|Packages(\.gz|\.bz2|\.lzma|\.xz)?|InRelease|Release|Release\.gpg|Sources(\.gz|\.bz2|\.lzma|\.xz)?|release|index\.db-.*\.gz|Contents-[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|pkglist[^/]*\.bz2|rclist[^/]*\.bz2|/meta-release[^/]*|Translation[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|MD5SUMS|SHA1SUMS|((setup|setup-legacy)(\.ini|\.bz2|\.hint)(\.sig)?)|mirrors\.lst|repo(index|md)\.xml(\.asc|\.key)?|directory\.yast|products|content(\.asc|\.key)?|media|filelists\.xml\.gz|filelists\.sqlite\.bz2|repomd\.xml|packages\.[a-zA-Z][a-zA-Z]\.gz|info\.txt|license\.tar\.gz|license\.zip|.*\.db(\.tar\.gz)?|.*\.files\.tar\.gz|.*\.abs\.tar\.gz|metalink\?repo|.*prestodelta\.xml\.gz)$|/dists/.*/installer-[^/]+/[^0-9][^/]+/images/.*
|
||||
# PfilePattern = .*(\.d?deb|\.rpm|\.dsc|\.tar(\.gz|\.bz2|\.lzma|\.xz)(\.gpg)?|\.diff(\.gz|\.bz2|\.lzma|\.xz)|\.jigdo|\.template|changelog|copyright|\.udeb|\.debdelta|\.diff/.*\.gz|(Devel)?ReleaseAnnouncement(\?.*)?|[a-f0-9]+-(susedata|updateinfo|primary|deltainfo).xml.gz|fonts/(final/)?[a-z]+32.exe(\?download.*)?|/dists/.*/installer-[^/]+/[0-9][^/]+/images/.*)$
|
||||
# Whitelist for expiration, file types not to be removed even when being
|
||||
# unreferenced. Default: many parts from VfilePattern where no parent index
|
||||
# exists or might be unknown.
|
||||
# WfilePattern = (^|.*?/)(Release|InRelease|Release\.gpg|(Packages|Sources)(\.gz|\.bz2|\.lzma|\.xz)?|Translation[^/]*(\.gz|\.bz2|\.lzma|\.xz)?|MD5SUMS|SHA1SUMS|.*\.xml|.*\.db\.tar\.gz|.*\.files\.tar\.gz|.*\.abs\.tar\.gz|[a-z]+32.exe)$|/dists/.*/installer-.*/images/.*
|
||||
|
||||
# Higher modes only working with the debug version
|
||||
# Warning, writes a lot into apt-cacher.err logfile
|
||||
# Value overwrites UnbufferLogs setting (aliased)
|
||||
# Debug:3
|
||||
|
||||
# Usually, general purpose proxies like Squid expose the IP address of the
|
||||
# client user to the remote server using the X-Forwarded-For HTTP header. This
|
||||
# behaviour can be optionally turned on with the Expose-Origin option.
|
||||
# ExposeOrigin: 0
|
||||
|
||||
# When logging the originating IP address, trust the information supplied by
|
||||
# the client in the X-Forwarded-For header.
|
||||
# LogSubmittedOrigin: 0
|
||||
|
||||
# The version string reported to the peer, to be displayed as HTTP client (and
|
||||
# version) in the logs of the mirror.
|
||||
# WARNING: some archives use this header to detect/guess capabilities of the
|
||||
# client (i.e. redirection support) and change the behaviour accordingly, while
|
||||
# ACNG might not support the expected features. Expect side effects.
|
||||
#
|
||||
# UserAgent: Yet Another HTTP Client/1.2.3p4
|
||||
|
||||
# In some cases the Import and Expiration tasks might create fresh volatile
|
||||
# data for internal use by reconstructing them using patch files. This
|
||||
# by-product might be recompressed with bzip2 and with some luck the resulting
|
||||
# file becomes identical to the *.bz2 file on the server, usable for APT
|
||||
# clients trying to fetch the full .bz2 compressed version. Injection of the
|
||||
# generated files into the cache has however a disadvantage on underpowered
|
||||
# servers: bzip2 compression can create high load on the server system and the
|
||||
# visible download of the busy .bz2 files also becomes slower.
|
||||
#
|
||||
# RecompBz2: 0
|
||||
|
||||
# Network timeout for outgoing connections.
|
||||
# NetworkTimeout: 60
|
||||
|
||||
# Sometimes it makes sense to not store the data in cache and just return the
|
||||
# package data to client as it comes in. DontCache parameters can enable this
|
||||
# behaviour for certain URL types. The tokens are extended regular expressions
|
||||
# that URLs are matched against.
|
||||
#
|
||||
# DontCacheRequested is applied to the URL as it comes in from the client.
|
||||
# Example: exclude packages built with kernel-package for x86
|
||||
# DontCacheRequested: linux-.*_10\...\.Custo._i386
|
||||
# Example usecase: exclude popular private IP ranges from caching
|
||||
# DontCacheRequested: 192.168.0 ^10\..* 172.30
|
||||
#
|
||||
# DontCacheResolved is applied to URLs after mapping to the target server. If
|
||||
# multiple backend servers are specified then it's only matched against the
|
||||
# download link for the FIRST possible source (due to implementation limits).
|
||||
# Example usecase: all Ubuntu stuff comes from a local mirror (specified as
|
||||
# backend), don't cache it again:
|
||||
# DontCacheResolved: ubuntumirror.local.net
|
||||
#
|
||||
# DontCache directive sets (overrides) both, DontCacheResolved and
|
||||
# DontCacheRequested. Provided for convenience, see those directives for
|
||||
# details.
|
||||
#
|
||||
# Default permission set of freshly created files and directories, as octal
|
||||
# numbers (see chmod(1) for details).
|
||||
# Can by limited by the umask value (see umask(2) for details) if it's set in
|
||||
# the environment of the starting shell, e.g. in apt-cacher-ng init script or
|
||||
# in its configuration file.
|
||||
# DirPerms: 00755
|
||||
# FilePerms: 00664
|
||||
#
|
||||
#
|
||||
# It's possible to use use apt-cacher-ng as a regular web server with limited
|
||||
# feature set, i.e.
|
||||
# including directory browsing and download of any file;
|
||||
# excluding sorting, mime types/encodings, CGI execution, index page
|
||||
# redirection and other funny things.
|
||||
# To get this behavior, mappings between virtual directories and real
|
||||
# directories on the server must be defined with the LocalDirs directive.
|
||||
# Virtual and real dirs are separated by spaces, multiple pairs are separated
|
||||
# by semi-colons. Real directories must be absolute paths.
|
||||
# NOTE: Since the names of that key directories share the same namespace as
|
||||
# repository names (see Remap-...) it's administrators job to avoid such
|
||||
# collisions on them (unless created deliberately).
|
||||
#
|
||||
# LocalDirs: woo /data/debarchive/woody ; hamm /data/debarchive/hamm
|
||||
|
||||
# Precache a set of files referenced by specified index files. This can be used
|
||||
# to create a partial mirror usable for offline work. There are certain limits
|
||||
# and restrictions on the path specification, see manual for details. A list of
|
||||
# (maybe) relevant index files could be retrieved via
|
||||
# "apt-get --print-uris update" on a client machine.
|
||||
#
|
||||
# PrecacheFor: debrep/dists/unstable/*/source/Sources* debrep/dists/unstable/*/binary-amd64/Packages*
|
||||
|
||||
# Arbitrary set of data to append to request headers sent over the wire. Should
|
||||
# be a well formated HTTP headers part including newlines (DOS style) which
|
||||
# can be entered as escape sequences (\r\n).
|
||||
# RequestAppendix: X-Tracking-Choice: do-not-track\r\n
|
||||
|
||||
# Specifies the IP protocol families to use for remote connections. Order does
|
||||
# matter, first specified are considered first. Possible combinations:
|
||||
# v6 v4
|
||||
# v4 v6
|
||||
# v6
|
||||
# v4
|
||||
# (empty or not set: use system default)
|
||||
#
|
||||
# ConnectProto: v6 v4
|
||||
|
||||
# Regular expiration algorithm finds package files which are no longer listed
|
||||
# in any index file and removes them of them after a safety period.
|
||||
# This option allows to keep more versions of a package in the cache after
|
||||
# safety period is over.
|
||||
# KeepExtraVersions: 1
|
||||
|
||||
# Optionally uses TCP access control provided by libwrap, see hosts_access(5)
|
||||
# for details. Daemon name is apt-cacher-ng. Default if not set: decided on
|
||||
# startup by looking for explicit mentioning of apt-cacher-ng in
|
||||
# /etc/hosts.allow or /etc/hosts.deny files.
|
||||
# UseWrap: 0
|
||||
|
||||
# If many machines from the same local network attempt to update index files
|
||||
# (apt-get update) at nearly the same time, the known state of these index file
|
||||
# is temporarily frozen and multiple requests receive the cached response
|
||||
# without contacting the server. This parameter (in seconds) specifies the
|
||||
# length of this period before the files are considered outdated.
|
||||
# Setting it too low transfers more data and increases remote server load,
|
||||
# setting it too high (more than a couple of minutes) increases the risk of
|
||||
# delivering inconsistent responses to the clients.
|
||||
# FreshIndexMaxAge: 27
|
||||
|
||||
# Usually the users are not allowed to specify custom TCP ports of remote
|
||||
# mirrors in the requests, only the default HTTP port can be used (instead,
|
||||
# proxy administrator can create Remap- rules with custom ports). This
|
||||
# restriction can be disabled by specifying a list of allowed ports or 0 for
|
||||
# any port.
|
||||
#
|
||||
# AllowUserPorts: 80
|
||||
|
||||
# Normally the HTTP redirection responses are forwarded to the original caller
|
||||
# (i.e. APT) which starts a new download attempt from the new URL. This
|
||||
# solution is ok for client configurations with proxy mode but doesn't work
|
||||
# well with configurations using URL prefixes. To work around this the server
|
||||
# can restart its own download with another URL. However, this might be used to
|
||||
# circumvent download source policies by malicious users.
|
||||
# The RedirMax option specifies how many such redirects the server should
|
||||
# follow per request, 0 disables the internal redirection. If not set,
|
||||
# default value is 0 if ForceManaged is used and 5 otherwise.
|
||||
#
|
||||
# RedirMax: 5
|
||||
@@ -0,0 +1,12 @@
|
||||
# CHANGELOG for mongodb
|
||||
|
||||
This file is used to list changes made in each version of mongodb.
|
||||
|
||||
## 0.1.0:
|
||||
|
||||
* Initial release of mongodb
|
||||
|
||||
- - -
|
||||
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
|
||||
|
||||
The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
|
||||
@@ -0,0 +1,68 @@
|
||||
mongodb Cookbook
|
||||
================
|
||||
TODO: Enter the cookbook description here.
|
||||
|
||||
e.g.
|
||||
This cookbook makes your favorite breakfast sandwhich.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
||||
|
||||
e.g.
|
||||
#### packages
|
||||
- `toaster` - mongodb needs toaster to brown your bagel.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
TODO: List you cookbook attributes here.
|
||||
|
||||
e.g.
|
||||
#### mongodb::default
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>['mongodb']['bacon']</tt></td>
|
||||
<td>Boolean</td>
|
||||
<td>whether to include bacon</td>
|
||||
<td><tt>true</tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Usage
|
||||
-----
|
||||
#### mongodb::default
|
||||
TODO: Write usage instructions for each cookbook.
|
||||
|
||||
e.g.
|
||||
Just include `mongodb` in your node's `run_list`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"my_node",
|
||||
"run_list": [
|
||||
"recipe[mongodb]"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Contributing
|
||||
------------
|
||||
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
||||
|
||||
e.g.
|
||||
1. Fork the repository on Github
|
||||
2. Create a named feature branch (like `add_component_x`)
|
||||
3. Write you change
|
||||
4. Write tests for your change (if applicable)
|
||||
5. Run the tests, ensuring they all pass
|
||||
6. Submit a Pull Request using Github
|
||||
|
||||
License and Authors
|
||||
-------------------
|
||||
Authors: TODO: List authors
|
||||
@@ -0,0 +1,8 @@
|
||||
name 'mongodb'
|
||||
maintainer 'ShareLaTeX'
|
||||
maintainer_email 'team@sharelatex.com'
|
||||
license 'AGPLv3'
|
||||
description 'Installs/Configures mongodb'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
depends 'apt'
|
||||
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Cookbook Name:: mongodb
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, ShareLaTeX
|
||||
#
|
||||
|
||||
# See http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
|
||||
apt_repository 'mongodb-org' do
|
||||
uri 'http://downloads-distro.mongodb.org/repo/ubuntu-upstart'
|
||||
distribution 'dist'
|
||||
components ['10gen']
|
||||
keyserver 'keyserver.ubuntu.com'
|
||||
key '7F0CEB10'
|
||||
end
|
||||
|
||||
package 'mongodb-org' do
|
||||
action :install
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
# CHANGELOG for nodejs
|
||||
|
||||
This file is used to list changes made in each version of nodejs.
|
||||
|
||||
## 0.1.0:
|
||||
|
||||
* Initial release of nodejs
|
||||
|
||||
- - -
|
||||
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
|
||||
|
||||
The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
|
||||
@@ -0,0 +1,68 @@
|
||||
nodejs Cookbook
|
||||
===============
|
||||
TODO: Enter the cookbook description here.
|
||||
|
||||
e.g.
|
||||
This cookbook makes your favorite breakfast sandwhich.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
||||
|
||||
e.g.
|
||||
#### packages
|
||||
- `toaster` - nodejs needs toaster to brown your bagel.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
TODO: List you cookbook attributes here.
|
||||
|
||||
e.g.
|
||||
#### nodejs::default
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>['nodejs']['bacon']</tt></td>
|
||||
<td>Boolean</td>
|
||||
<td>whether to include bacon</td>
|
||||
<td><tt>true</tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Usage
|
||||
-----
|
||||
#### nodejs::default
|
||||
TODO: Write usage instructions for each cookbook.
|
||||
|
||||
e.g.
|
||||
Just include `nodejs` in your node's `run_list`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"my_node",
|
||||
"run_list": [
|
||||
"recipe[nodejs]"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Contributing
|
||||
------------
|
||||
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
||||
|
||||
e.g.
|
||||
1. Fork the repository on Github
|
||||
2. Create a named feature branch (like `add_component_x`)
|
||||
3. Write you change
|
||||
4. Write tests for your change (if applicable)
|
||||
5. Run the tests, ensuring they all pass
|
||||
6. Submit a Pull Request using Github
|
||||
|
||||
License and Authors
|
||||
-------------------
|
||||
Authors: TODO: List authors
|
||||
@@ -0,0 +1,8 @@
|
||||
name 'nodejs'
|
||||
maintainer 'YOUR_COMPANY_NAME'
|
||||
maintainer_email 'YOUR_EMAIL'
|
||||
license 'AGPLv3'
|
||||
description 'Installs/Configures nodejs'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
depends 'apt'
|
||||
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Cookbook Name:: nodejs
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, ShareLaTeX
|
||||
#
|
||||
|
||||
# See https://launchpad.net/~chris-lea/+archive/nodejs
|
||||
apt_repository 'node.js' do
|
||||
uri 'http://ppa.launchpad.net/chris-lea/node.js/ubuntu'
|
||||
distribution node['lsb']['codename']
|
||||
components ['main']
|
||||
keyserver 'keyserver.ubuntu.com'
|
||||
key 'C7917B12'
|
||||
end
|
||||
|
||||
package 'nodejs' do
|
||||
action :install
|
||||
end
|
||||
|
||||
execute 'install grunt' do
|
||||
command "npm install -g grunt-cli"
|
||||
not_if "npm --no-color -g ls 'grunt-cli' 2> /dev/null | grep 'grunt-cli'"
|
||||
end
|
||||
@@ -0,0 +1,68 @@
|
||||
redis Cookbook
|
||||
==============
|
||||
TODO: Enter the cookbook description here.
|
||||
|
||||
e.g.
|
||||
This cookbook makes your favorite breakfast sandwhich.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
||||
|
||||
e.g.
|
||||
#### packages
|
||||
- `toaster` - redis needs toaster to brown your bagel.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
TODO: List you cookbook attributes here.
|
||||
|
||||
e.g.
|
||||
#### redis::default
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>['redis']['bacon']</tt></td>
|
||||
<td>Boolean</td>
|
||||
<td>whether to include bacon</td>
|
||||
<td><tt>true</tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Usage
|
||||
-----
|
||||
#### redis::default
|
||||
TODO: Write usage instructions for each cookbook.
|
||||
|
||||
e.g.
|
||||
Just include `redis` in your node's `run_list`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"my_node",
|
||||
"run_list": [
|
||||
"recipe[redis]"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Contributing
|
||||
------------
|
||||
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
||||
|
||||
e.g.
|
||||
1. Fork the repository on Github
|
||||
2. Create a named feature branch (like `add_component_x`)
|
||||
3. Write you change
|
||||
4. Write tests for your change (if applicable)
|
||||
5. Run the tests, ensuring they all pass
|
||||
6. Submit a Pull Request using Github
|
||||
|
||||
License and Authors
|
||||
-------------------
|
||||
Authors: TODO: List authors
|
||||
@@ -0,0 +1,7 @@
|
||||
name 'packages'
|
||||
maintainer 'ShareLaTeX'
|
||||
maintainer_email 'team@sharelatex.com'
|
||||
license 'AGPLv3'
|
||||
description 'Installs/Configures packages'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Cookbook Name:: packages
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, ShareLaTeX
|
||||
#
|
||||
|
||||
package 'git'
|
||||
package 'vim'
|
||||
package 'build-essential'
|
||||
@@ -0,0 +1,12 @@
|
||||
# CHANGELOG for redis
|
||||
|
||||
This file is used to list changes made in each version of redis.
|
||||
|
||||
## 0.1.0:
|
||||
|
||||
* Initial release of redis
|
||||
|
||||
- - -
|
||||
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
|
||||
|
||||
The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
|
||||
@@ -0,0 +1,68 @@
|
||||
redis Cookbook
|
||||
==============
|
||||
TODO: Enter the cookbook description here.
|
||||
|
||||
e.g.
|
||||
This cookbook makes your favorite breakfast sandwhich.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
||||
|
||||
e.g.
|
||||
#### packages
|
||||
- `toaster` - redis needs toaster to brown your bagel.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
TODO: List you cookbook attributes here.
|
||||
|
||||
e.g.
|
||||
#### redis::default
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>['redis']['bacon']</tt></td>
|
||||
<td>Boolean</td>
|
||||
<td>whether to include bacon</td>
|
||||
<td><tt>true</tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Usage
|
||||
-----
|
||||
#### redis::default
|
||||
TODO: Write usage instructions for each cookbook.
|
||||
|
||||
e.g.
|
||||
Just include `redis` in your node's `run_list`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"my_node",
|
||||
"run_list": [
|
||||
"recipe[redis]"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Contributing
|
||||
------------
|
||||
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
||||
|
||||
e.g.
|
||||
1. Fork the repository on Github
|
||||
2. Create a named feature branch (like `add_component_x`)
|
||||
3. Write you change
|
||||
4. Write tests for your change (if applicable)
|
||||
5. Run the tests, ensuring they all pass
|
||||
6. Submit a Pull Request using Github
|
||||
|
||||
License and Authors
|
||||
-------------------
|
||||
Authors: TODO: List authors
|
||||
@@ -0,0 +1,8 @@
|
||||
name 'redis-server'
|
||||
maintainer 'ShareLaTeX'
|
||||
maintainer_email 'team@sharelatex.com'
|
||||
license 'AGPLv3'
|
||||
description 'Installs/Configures redis-server'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
depends 'apt'
|
||||
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Cookbook Name:: redis
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, ShareLaTeX
|
||||
#
|
||||
|
||||
# See https://launchpad.net/~chris-lea/+archive/redis-server
|
||||
apt_repository 'redis-server' do
|
||||
uri 'http://ppa.launchpad.net/chris-lea/redis-server/ubuntu'
|
||||
distribution node['lsb']['codename']
|
||||
components ['main']
|
||||
keyserver 'keyserver.ubuntu.com'
|
||||
key 'C7917B12'
|
||||
end
|
||||
|
||||
package 'redis-server' do
|
||||
action :upgrade
|
||||
options "--force-yes"
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
# CHANGELOG for latex
|
||||
|
||||
This file is used to list changes made in each version of latex.
|
||||
|
||||
## 0.1.0:
|
||||
|
||||
* Initial release of latex
|
||||
|
||||
- - -
|
||||
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
|
||||
|
||||
The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
|
||||
@@ -0,0 +1,68 @@
|
||||
latex Cookbook
|
||||
==============
|
||||
TODO: Enter the cookbook description here.
|
||||
|
||||
e.g.
|
||||
This cookbook makes your favorite breakfast sandwhich.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
||||
|
||||
e.g.
|
||||
#### packages
|
||||
- `toaster` - latex needs toaster to brown your bagel.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
TODO: List you cookbook attributes here.
|
||||
|
||||
e.g.
|
||||
#### latex::default
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>['latex']['bacon']</tt></td>
|
||||
<td>Boolean</td>
|
||||
<td>whether to include bacon</td>
|
||||
<td><tt>true</tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Usage
|
||||
-----
|
||||
#### latex::default
|
||||
TODO: Write usage instructions for each cookbook.
|
||||
|
||||
e.g.
|
||||
Just include `latex` in your node's `run_list`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"my_node",
|
||||
"run_list": [
|
||||
"recipe[latex]"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Contributing
|
||||
------------
|
||||
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
||||
|
||||
e.g.
|
||||
1. Fork the repository on Github
|
||||
2. Create a named feature branch (like `add_component_x`)
|
||||
3. Write you change
|
||||
4. Write tests for your change (if applicable)
|
||||
5. Run the tests, ensuring they all pass
|
||||
6. Submit a Pull Request using Github
|
||||
|
||||
License and Authors
|
||||
-------------------
|
||||
Authors: TODO: List authors
|
||||
@@ -0,0 +1,2 @@
|
||||
default[:texlive][:schema] = "small"
|
||||
default[:texlive][:bin_dir] = "/usr/local/texlive/2014/bin/x86_64-linux"
|
||||
@@ -0,0 +1,7 @@
|
||||
name 'texlive'
|
||||
maintainer 'ShareLaTeX'
|
||||
maintainer_email 'team@sharelatex.com'
|
||||
license 'All rights reserved'
|
||||
description 'Installs/Configures texlive'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# Cookbook Name:: texlive
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, YOUR_COMPANY_NAME
|
||||
#
|
||||
# All rights reserved - Do Not Redistribute
|
||||
#
|
||||
|
||||
remote_file "#{Chef::Config[:file_cache_path]}/install-tl-unx.tar.gz" do
|
||||
source "http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz"
|
||||
action :create_if_missing
|
||||
end
|
||||
|
||||
directory "/install-tl-unx"
|
||||
bash "extract install-tl" do
|
||||
cwd Chef::Config[:file_cache_path]
|
||||
code <<-EOH
|
||||
tar -xvf install-tl-unx.tar.gz -C /install-tl-unx --strip-components=1
|
||||
EOH
|
||||
creates "/install-tl-unx/install-tl"
|
||||
end
|
||||
|
||||
file "/install-tl-unx/texlive.profile" do
|
||||
content "selected_scheme scheme-#{node[:texlive][:schema]}"
|
||||
end
|
||||
|
||||
bash "install texlive" do
|
||||
cwd "/install-tl-unx"
|
||||
code <<-EOH
|
||||
/install-tl-unx/install-tl -profile /install-tl-unx/texlive.profile
|
||||
EOH
|
||||
creates "#{node[:texlive][:bin_dir]}/pdflatex"
|
||||
end
|
||||
|
||||
bash "install latexmk" do
|
||||
environment({
|
||||
"PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:#{node[:texlive][:bin_dir]}"
|
||||
})
|
||||
code "tlmgr install latexmk"
|
||||
creates "#{node[:texlive][:bin_dir]}/latexmk"
|
||||
end
|
||||
@@ -0,0 +1,219 @@
|
||||
Path = require('path')
|
||||
|
||||
# These credentials are used for authenticating api requests
|
||||
# between services that may need to go over public channels
|
||||
httpAuthUser = "sharelatex"
|
||||
httpAuthPass = "CRYPTO_RANDOM" # Randomly generated for you
|
||||
httpAuthUsers = {}
|
||||
httpAuthUsers[httpAuthUser] = httpAuthPass
|
||||
|
||||
DATA_DIR = Path.resolve(Path.join(__dirname, "..", "data"))
|
||||
TMP_DIR = Path.resolve(Path.join(__dirname, "..", "tmp"))
|
||||
|
||||
module.exports =
|
||||
# Databases
|
||||
# ---------
|
||||
|
||||
# ShareLaTeX's main persistant data store is MongoDB (http://www.mongodb.org/)
|
||||
# Documentation about the URL connection string format can be found at:
|
||||
#
|
||||
# http://docs.mongodb.org/manual/reference/connection-string/
|
||||
#
|
||||
# The following works out of the box with Mongo's default settings:
|
||||
mongo:
|
||||
url : 'mongodb://127.0.0.1/sharelatex'
|
||||
|
||||
# Redis is used in ShareLaTeX for high volume queries, like real-time
|
||||
# editing, and session management.
|
||||
#
|
||||
# The following config will work with Redis's default settings:
|
||||
redis:
|
||||
web:
|
||||
host: "localhost"
|
||||
port: "6379"
|
||||
password: ""
|
||||
|
||||
# The compile server (the clsi) uses a SQL database to cache files and
|
||||
# meta-data. sqllite is the default, and the load is low enough that this will
|
||||
# be fine in production (we use sqllite at sharelatex.com).
|
||||
#
|
||||
# If you want to configure a different database, see the Sequelize documentation
|
||||
# for available options:
|
||||
#
|
||||
# https://github.com/sequelize/sequelize/wiki/API-Reference-Sequelize#example-usage
|
||||
#
|
||||
mysql:
|
||||
clsi:
|
||||
database: "clsi"
|
||||
username: "clsi"
|
||||
password: ""
|
||||
dialect: "sqlite"
|
||||
storage: Path.join(DATA_DIR, "db.sqlite")
|
||||
|
||||
# File storage
|
||||
# ------------
|
||||
|
||||
# ShareLaTeX can store binary files like images either locally or in Amazon
|
||||
# S3. The default is locally:
|
||||
filestore:
|
||||
backend: "fs"
|
||||
stores:
|
||||
user_files: Path.join(DATA_DIR, "user_files")
|
||||
|
||||
# To use Amazon S3 as a storage backend, comment out the above config, and
|
||||
# uncomment the following, filling in your key, secret, and bucket name:
|
||||
#
|
||||
# filestore:
|
||||
# backend: "s3"
|
||||
# stores:
|
||||
# user_files: "BUCKET_NAME"
|
||||
# s3:
|
||||
# key: "AWS_KEY"
|
||||
# secret: "AWS_SECRET"
|
||||
#
|
||||
|
||||
# Local disk caching
|
||||
# ------------------
|
||||
path:
|
||||
# If we ever need to write something to disk (e.g. incoming requests
|
||||
# that need processing but may be too big for memory), then write
|
||||
# them to disk here:
|
||||
dumpFolder: Path.join(TMP_DIR, "dumpFolder")
|
||||
# Where to write uploads before they are processed
|
||||
uploadFolder: Path.join(TMP_DIR, "uploads")
|
||||
# Where to write the project to disk before running LaTeX on it
|
||||
compilesDir: Path.join(DATA_DIR, "compiles")
|
||||
# Where to cache downloaded URLs for the CLSI
|
||||
clsiCacheDir: Path.join(DATA_DIR, "cache")
|
||||
|
||||
# Server Config
|
||||
# -------------
|
||||
|
||||
# Where your instance of ShareLaTeX can be found publicly. This is used
|
||||
# when emails are sent out and in generated links:
|
||||
siteUrl : 'http://localhost:3000'
|
||||
|
||||
# If provided, a sessionSecret is used to sign cookies so that they cannot be
|
||||
# spoofed. This is recommended.
|
||||
security:
|
||||
sessionSecret: "CRYPTO_RANDOM" # This was randomly generated for you
|
||||
|
||||
# These credentials are used for authenticating api requests
|
||||
# between services that may need to go over public channels
|
||||
httpAuthUsers: httpAuthUsers
|
||||
|
||||
# Should javascript assets be served minified or not. Note that you will
|
||||
# need to run `grunt compile:minify` within the web-sharelatex directory
|
||||
# to generate these.
|
||||
useMinifiedJs: false
|
||||
|
||||
# Should static assets be sent with a header to tell the browser to cache
|
||||
# them. This should be false in development where changes are being made,
|
||||
# but should be set to true in production.
|
||||
cacheStaticAssets: false
|
||||
|
||||
# If you are running ShareLaTeX over https, set this to true to send the
|
||||
# cookie with a secure flag (recommended).
|
||||
secureCookie: false
|
||||
|
||||
# If you are running ShareLaTeX behind a proxy (like Apache, Nginx, etc)
|
||||
# then set this to true to allow it to correctly detect the forwarded IP
|
||||
# address and http/https protocol information.
|
||||
behindProxy: false
|
||||
|
||||
# Sending Email
|
||||
# -------------
|
||||
#
|
||||
# You must configure a mail server to be able to send invite emails from
|
||||
# ShareLaTeX. The config settings are passed to nodemailer. See the nodemailer
|
||||
# documentation for available options:
|
||||
#
|
||||
# http://www.nodemailer.com/docs/transports
|
||||
#
|
||||
# email:
|
||||
# fromAddress: ""
|
||||
# replyTo: ""
|
||||
# transport: "SES"
|
||||
# parameters:
|
||||
# AWSAccessKeyID: ""
|
||||
# AWSSecretKey: ""
|
||||
|
||||
# Spell Check Languages
|
||||
# ---------------------
|
||||
#
|
||||
# You must have the corresponding aspell dictionary installed to
|
||||
# be able to use a language. Run `grunt check:aspell` to check which
|
||||
# dictionaries you have installed. These should be set for the `code` for
|
||||
# each language.
|
||||
languages: [
|
||||
{name: "English", code: "en"}
|
||||
]
|
||||
|
||||
# Service locations
|
||||
# -----------------
|
||||
|
||||
# ShareLaTeX is comprised of many small services, which each expose
|
||||
# an HTTP API running on a different port. Generally you
|
||||
# can leave these as they are unless you have some other services
|
||||
# running which conflict, or want to run the web process on port 80.
|
||||
# internal:
|
||||
# web:
|
||||
# port: webPort = 3000
|
||||
# host: "localhost"
|
||||
# documentupdater:
|
||||
# port: docUpdaterPort = 3003
|
||||
# host: "localhost"
|
||||
# filestore:
|
||||
# port: filestorePort = 3009
|
||||
# host: "localhost"
|
||||
# chat:
|
||||
# port: chatPort = 3010
|
||||
# host: "localhost"
|
||||
# tags:
|
||||
# port: tagsPort = 3012
|
||||
# host: "localhost"
|
||||
# clsi:
|
||||
# port: clsiPort = 3013
|
||||
# host: "localhost"
|
||||
# trackchanges:
|
||||
# port: trackchangesPort = 3015
|
||||
# host: "localhost"
|
||||
# docstore:
|
||||
# port: docstorePort = 3016
|
||||
# host: "localhost"
|
||||
# spelling:
|
||||
# port: spellingPort = 3005
|
||||
# host: "localhost"
|
||||
|
||||
# If you change the above config, or run some services on remote servers,
|
||||
# you need to tell the other services where to find them:
|
||||
apis:
|
||||
web:
|
||||
url: "http://localhost:3000"
|
||||
user: httpAuthUser
|
||||
pass: httpAuthPass
|
||||
# documentupdater:
|
||||
# url : "http://localhost:#{docUpdaterPort}"
|
||||
# clsi:
|
||||
# url: "http://localhost:#{clsiPort}"
|
||||
# filestore:
|
||||
# url: "http://localhost:#{filestorePort}"
|
||||
# trackchanges:
|
||||
# url: "http://localhost:#{trackchangesPort}"
|
||||
# docstore:
|
||||
# url: "http://localhost:#{docstorePort}"
|
||||
# tags:
|
||||
# url: "http://localhost:#{tagsPort}"
|
||||
# spelling:
|
||||
# url: "http://localhost:#{spellingPort}"
|
||||
# chat:
|
||||
# url: "http://localhost:#{chatPort}"
|
||||
|
||||
|
||||
# With lots of incoming and outgoing HTTP connections to different services,
|
||||
# sometimes long running, it is a good idea to increase the default number
|
||||
# of sockets that Node will hold open.
|
||||
http = require('http')
|
||||
http.globalAgent.maxSockets = 300
|
||||
https = require('https')
|
||||
https.globalAgent.maxSockets = 300
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 739 KiB |
@@ -1,20 +0,0 @@
|
||||
version: '2.2'
|
||||
services:
|
||||
sharelatex:
|
||||
ports:
|
||||
- 40000:40000
|
||||
- 30150:30150
|
||||
- 30120:30120
|
||||
- 30050:30050
|
||||
- 30420:30420
|
||||
- 30030:30030
|
||||
- 30160:30160
|
||||
- 30360:30360
|
||||
- 30130:30130
|
||||
- 30100:30100
|
||||
|
||||
# Server Pro
|
||||
- 30070:30070
|
||||
- 30400:30400
|
||||
environment:
|
||||
DEBUG_NODE: 'true'
|
||||
@@ -1,147 +0,0 @@
|
||||
version: '2.2'
|
||||
services:
|
||||
sharelatex:
|
||||
restart: always
|
||||
# Server Pro users:
|
||||
# image: quay.io/sharelatex/sharelatex-pro
|
||||
image: sharelatex/sharelatex
|
||||
container_name: sharelatex
|
||||
depends_on:
|
||||
mongo:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_started
|
||||
ports:
|
||||
- 80:80
|
||||
links:
|
||||
- mongo
|
||||
- redis
|
||||
volumes:
|
||||
- ~/sharelatex_data:/var/lib/sharelatex
|
||||
########################################################################
|
||||
#### Server Pro: Uncomment the following line to mount the docker ####
|
||||
#### socket, required for Sibling Containers to work ####
|
||||
########################################################################
|
||||
# - /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
|
||||
SHARELATEX_APP_NAME: Overleaf Community Edition
|
||||
|
||||
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
|
||||
|
||||
# Same property, unfortunately with different names in
|
||||
# different locations
|
||||
SHARELATEX_REDIS_HOST: redis
|
||||
REDIS_HOST: redis
|
||||
|
||||
ENABLED_LINKED_FILE_TYPES: 'project_file,project_output_file'
|
||||
|
||||
# Enables Thumbnail generation using ImageMagick
|
||||
ENABLE_CONVERSIONS: 'true'
|
||||
|
||||
# Disables email confirmation requirement
|
||||
EMAIL_CONFIRMATION_DISABLED: 'true'
|
||||
|
||||
# temporary fix for LuaLaTex compiles
|
||||
# see https://github.com/overleaf/overleaf/issues/695
|
||||
TEXMFVAR: /var/lib/sharelatex/tmp/texmf-var
|
||||
|
||||
## Set for SSL via nginx-proxy
|
||||
#VIRTUAL_HOST: 103.112.212.22
|
||||
|
||||
# SHARELATEX_SITE_URL: http://sharelatex.mydomain.com
|
||||
# SHARELATEX_NAV_TITLE: Our ShareLaTeX Instance
|
||||
# SHARELATEX_HEADER_IMAGE_URL: http://somewhere.com/mylogo.png
|
||||
# SHARELATEX_ADMIN_EMAIL: support@it.com
|
||||
|
||||
# SHARELATEX_LEFT_FOOTER: '[{"text": "Powered by <a href=\"https://www.sharelatex.com\">ShareLaTeX</a> 2016"},{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
|
||||
# SHARELATEX_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'
|
||||
|
||||
# SHARELATEX_EMAIL_FROM_ADDRESS: "team@sharelatex.com"
|
||||
|
||||
# SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID:
|
||||
# SHARELATEX_EMAIL_AWS_SES_SECRET_KEY:
|
||||
|
||||
# SHARELATEX_EMAIL_SMTP_HOST: smtp.mydomain.com
|
||||
# SHARELATEX_EMAIL_SMTP_PORT: 587
|
||||
# SHARELATEX_EMAIL_SMTP_SECURE: false
|
||||
# SHARELATEX_EMAIL_SMTP_USER:
|
||||
# SHARELATEX_EMAIL_SMTP_PASS:
|
||||
# SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
|
||||
# SHARELATEX_EMAIL_SMTP_IGNORE_TLS: false
|
||||
# SHARELATEX_EMAIL_SMTP_NAME: '127.0.0.1'
|
||||
# SHARELATEX_EMAIL_SMTP_LOGGER: true
|
||||
# SHARELATEX_CUSTOM_EMAIL_FOOTER: "This system is run by department x"
|
||||
|
||||
################
|
||||
## Server Pro ##
|
||||
################
|
||||
|
||||
# SANDBOXED_COMPILES: 'true'
|
||||
|
||||
# SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true'
|
||||
# SANDBOXED_COMPILES_HOST_DIR: '/var/sharelatex_data/data/compiles'
|
||||
|
||||
# DOCKER_RUNNER: 'false'
|
||||
|
||||
## Works with test LDAP server shown at bottom of docker compose
|
||||
# SHARELATEX_LDAP_URL: 'ldap://ldap:389'
|
||||
# SHARELATEX_LDAP_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
|
||||
# SHARELATEX_LDAP_SEARCH_FILTER: '(uid={{username}})'
|
||||
# SHARELATEX_LDAP_BIND_DN: 'cn=admin,dc=planetexpress,dc=com'
|
||||
# SHARELATEX_LDAP_BIND_CREDENTIALS: 'GoodNewsEveryone'
|
||||
# SHARELATEX_LDAP_EMAIL_ATT: 'mail'
|
||||
# SHARELATEX_LDAP_NAME_ATT: 'cn'
|
||||
# SHARELATEX_LDAP_LAST_NAME_ATT: 'sn'
|
||||
# SHARELATEX_LDAP_UPDATE_USER_DETAILS_ON_LOGIN: 'true'
|
||||
|
||||
# SHARELATEX_TEMPLATES_USER_ID: "578773160210479700917ee5"
|
||||
# SHARELATEX_NEW_PROJECT_TEMPLATE_LINKS: '[ {"name":"All Templates","url":"/templates/all"}]'
|
||||
|
||||
|
||||
# SHARELATEX_PROXY_LEARN: "true"
|
||||
|
||||
mongo:
|
||||
restart: always
|
||||
image: mongo:4.0
|
||||
container_name: mongo
|
||||
expose:
|
||||
- 27017
|
||||
volumes:
|
||||
- ~/mongo_data:/data/db
|
||||
healthcheck:
|
||||
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
||||
interval: 10s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
restart: always
|
||||
image: redis:5
|
||||
container_name: redis
|
||||
expose:
|
||||
- 6379
|
||||
volumes:
|
||||
- ~/redis_data:/data
|
||||
|
||||
# ldap:
|
||||
# restart: always
|
||||
# image: rroemhild/test-openldap
|
||||
# container_name: ldap
|
||||
# expose:
|
||||
# - 389
|
||||
|
||||
# See https://github.com/jwilder/nginx-proxy for documentation on how to configure the nginx-proxy container,
|
||||
# and https://github.com/overleaf/overleaf/wiki/HTTPS-reverse-proxy-using-Nginx for an example of some recommended
|
||||
# settings. We recommend using a properly managed nginx instance outside of the Overleaf Server Pro setup,
|
||||
# but the example here can be used if you'd prefer to run everything with docker-compose
|
||||
|
||||
# nginx-proxy:
|
||||
# image: jwilder/nginx-proxy
|
||||
# container_name: nginx-proxy
|
||||
# ports:
|
||||
# #- "80:80"
|
||||
# - "443:443"
|
||||
# volumes:
|
||||
# - /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
# - /home/sharelatex/tmp:/etc/nginx/certs
|
||||
@@ -1,73 +0,0 @@
|
||||
// this file was auto-generated, do not edit it directly.
|
||||
// instead run bin/update_build_scripts from
|
||||
// https://github.com/sharelatex/sharelatex-dev-environment
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"standard",
|
||||
"prettier"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": [
|
||||
"mocha",
|
||||
"chai-expect",
|
||||
"chai-friendly"
|
||||
],
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
// Swap the no-unused-expressions rule with a more chai-friendly one
|
||||
"no-unused-expressions": 0,
|
||||
"chai-friendly/no-unused-expressions": "error",
|
||||
|
||||
// Do not allow importing of implicit dependencies.
|
||||
"import/no-extraneous-dependencies": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
// Test specific rules
|
||||
"files": ["test/**/*.js"],
|
||||
"globals": {
|
||||
"expect": true
|
||||
},
|
||||
"rules": {
|
||||
// mocha-specific rules
|
||||
"mocha/handle-done-callback": "error",
|
||||
"mocha/no-exclusive-tests": "error",
|
||||
"mocha/no-global-tests": "error",
|
||||
"mocha/no-identical-title": "error",
|
||||
"mocha/no-nested-tests": "error",
|
||||
"mocha/no-pending-tests": "error",
|
||||
"mocha/no-skipped-tests": "error",
|
||||
"mocha/no-mocha-arrows": "error",
|
||||
|
||||
// chai-specific rules
|
||||
"chai-expect/missing-assertion": "error",
|
||||
"chai-expect/terminating-properties": "error",
|
||||
|
||||
// prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
|
||||
// we don't enforce this at the top-level - just in tests to manage `this` scope
|
||||
// based on mocha's context mechanism
|
||||
"mocha/prefer-arrow-callback": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
// Backend specific rules
|
||||
"files": ["lib/**/*.js", "index.js"],
|
||||
"rules": {
|
||||
// don't allow console.log in backend code
|
||||
"no-console": "error",
|
||||
|
||||
// Do not allow importing of implicit dependencies.
|
||||
"import/no-extraneous-dependencies": ["error", {
|
||||
// Do not allow importing of devDependencies.
|
||||
"devDependencies": false
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
compileFolder
|
||||
|
||||
Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store?
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
/node_modules/*
|
||||
data/*/*
|
||||
|
||||
**.swp
|
||||
|
||||
/log.json
|
||||
hash_folder
|
||||
|
||||
.npmrc
|
||||
Dockerfile
|
||||
@@ -1,11 +0,0 @@
|
||||
# This file was auto-generated, do not edit it directly.
|
||||
# Instead run bin/update_build_scripts from
|
||||
# https://github.com/sharelatex/sharelatex-dev-environment
|
||||
{
|
||||
"arrowParens": "avoid",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"useTabs": false
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
@@ -1,3 +0,0 @@
|
||||
# Access Token Encryptor
|
||||
|
||||
Used in third-party-references, to encrypt access tokens
|
||||
@@ -1,9 +0,0 @@
|
||||
access-token-encryptor
|
||||
--dependencies=None
|
||||
--docker-repos=gcr.io/overleaf-ops
|
||||
--env-add=
|
||||
--env-pass-through=
|
||||
--is-library=True
|
||||
--node-version=12.22.3
|
||||
--public-repo=False
|
||||
--script-version=3.11.0
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('./lib/js/AccessTokenEncryptor')
|
||||
@@ -1,117 +0,0 @@
|
||||
const crypto = require('crypto')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
const ALGORITHM = 'aes-256-ctr'
|
||||
|
||||
const keyFn = (password, salt, callback) =>
|
||||
crypto.pbkdf2(password, salt, 10000, 64, 'sha1', callback)
|
||||
|
||||
const keyFn32 = (password, salt, keyLength, callback) =>
|
||||
crypto.pbkdf2(password, salt, 10000, 32, 'sha1', callback)
|
||||
|
||||
class AccessTokenEncryptor {
|
||||
constructor(settings) {
|
||||
this.settings = settings
|
||||
this.cipherLabel = this.settings.cipherLabel
|
||||
if (this.cipherLabel && this.cipherLabel.match(/:/)) {
|
||||
throw Error('cipherLabel must not contain a colon (:)')
|
||||
}
|
||||
|
||||
this.cipherPassword = this.settings.cipherPasswords[this.cipherLabel]
|
||||
if (!this.cipherPassword) {
|
||||
throw Error('cipherPassword not set')
|
||||
}
|
||||
if (this.cipherPassword.length < 16) {
|
||||
throw Error('cipherPassword too short')
|
||||
}
|
||||
}
|
||||
|
||||
encryptJson(json, callback) {
|
||||
const string = JSON.stringify(json)
|
||||
crypto.randomBytes(32, (err, bytes) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
const salt = bytes.slice(0, 16)
|
||||
const iv = bytes.slice(16, 32)
|
||||
|
||||
keyFn32(this.cipherPassword, salt, 32, (err, key) => {
|
||||
if (err) {
|
||||
logger.err({ err }, 'error getting Fn key')
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
const cipher = crypto.createCipheriv(ALGORITHM, key, iv)
|
||||
const crypted =
|
||||
cipher.update(string, 'utf8', 'base64') + cipher.final('base64')
|
||||
|
||||
callback(
|
||||
null,
|
||||
`${this.cipherLabel}:${salt.toString('hex')}:${crypted}:${iv.toString(
|
||||
'hex'
|
||||
)}`
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
decryptToJson(encryptedJson, callback) {
|
||||
const [label, salt, cipherText, iv] = encryptedJson.split(':', 4)
|
||||
const password = this.settings.cipherPasswords[label]
|
||||
if (!password || password.length < 16) {
|
||||
return callback(new Error('invalid password'))
|
||||
}
|
||||
|
||||
if (iv) {
|
||||
this.decryptToJsonV2(password, salt, cipherText, iv, callback)
|
||||
} else {
|
||||
this.decryptToJsonV1(password, salt, cipherText, callback)
|
||||
}
|
||||
}
|
||||
|
||||
decryptToJsonV1(password, salt, cipherText, callback) {
|
||||
keyFn(password, Buffer.from(salt, 'hex'), (err, key) => {
|
||||
let json
|
||||
if (err) {
|
||||
logger.err({ err }, 'error getting Fn key')
|
||||
return callback(err)
|
||||
}
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const decipher = crypto.createDecipher(ALGORITHM, key)
|
||||
const dec =
|
||||
decipher.update(cipherText, 'base64', 'utf8') + decipher.final('utf8')
|
||||
try {
|
||||
json = JSON.parse(dec)
|
||||
} catch (e) {
|
||||
return callback(new Error('error decrypting token'))
|
||||
}
|
||||
callback(null, json, true)
|
||||
})
|
||||
}
|
||||
|
||||
decryptToJsonV2(password, salt, cipherText, iv, callback) {
|
||||
keyFn32(password, Buffer.from(salt, 'hex'), 32, (err, key) => {
|
||||
let json
|
||||
if (err) {
|
||||
logger.err({ err }, 'error getting Fn key')
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
const decipher = crypto.createDecipheriv(
|
||||
ALGORITHM,
|
||||
key,
|
||||
Buffer.from(iv, 'hex')
|
||||
)
|
||||
const dec =
|
||||
decipher.update(cipherText, 'base64', 'utf8') + decipher.final('utf8')
|
||||
try {
|
||||
json = JSON.parse(dec)
|
||||
} catch (e) {
|
||||
return callback(new Error('error decrypting token'))
|
||||
}
|
||||
callback(null, json)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AccessTokenEncryptor
|
||||
-3494
File diff suppressed because it is too large
Load Diff
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"name": "@overleaf/access-token-encryptor",
|
||||
"version": "2.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha test/**/*.js",
|
||||
"lint": "eslint --max-warnings 0 --format unix .",
|
||||
"lint:fix": "eslint --fix .",
|
||||
"format": "prettier --list-different $PWD/'**/*.js'",
|
||||
"format:fix": "prettier --write $PWD/'**/*.js'",
|
||||
"test:ci": "npm run test"
|
||||
},
|
||||
"author": "",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {},
|
||||
"peerDependencies": {
|
||||
"logger-sharelatex": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bunyan": "^1.8.15",
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^7.21.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-config-standard": "^16.0.2",
|
||||
"eslint-plugin-chai-expect": "^2.2.0",
|
||||
"eslint-plugin-chai-friendly": "^0.6.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-mocha": "^8.0.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"logger-sharelatex": "^2.2.0",
|
||||
"mocha": "^6.2.2",
|
||||
"nock": "0.15.2",
|
||||
"prettier": "^2.2.1",
|
||||
"sandboxed-module": "^2.0.3",
|
||||
"sinon": "^7.5.0"
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
const chai = require('chai')
|
||||
chai.should()
|
||||
const { expect } = chai
|
||||
const modulePath = '../../../index.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('AccessTokenEncryptor', function () {
|
||||
beforeEach(function () {
|
||||
this.testObject = { hello: 'world' }
|
||||
this.encrypted2015 =
|
||||
'2015.1:473a66fb5d816bc716f278ab819d88a5:+mTg7O9sgUND8pNQFG6h2GE='
|
||||
this.encrypted2016 =
|
||||
'2016.1:76a7d64a444ccee1a515b49c44844a69:m5YSkexUsLjcF4gLncm72+k='
|
||||
this.encrypted2019 =
|
||||
'2019.1:627143b2ab185a020c8720253a4c984e:7gnY6Ez3/Y3UWgLHLfBtJsE=:bf75cecb6aeea55b3c060e1122d2a82d'
|
||||
this.badLabel = 'xxxxxx:c7a39310056b694c:jQf+Uh5Den3JREtvc82GW5Q='
|
||||
this.badKey = '2015.1:d7a39310056b694c:jQf+Uh5Den3JREtvc82GW5Q='
|
||||
this.badCipherText = '2015.1:c7a39310056b694c:xQf+Uh5Den3JREtvc82GW5Q='
|
||||
this.settings = {
|
||||
cipherLabel: '2019.1',
|
||||
cipherPasswords: {
|
||||
2016.1: '11111111111111111111111111111111111111',
|
||||
2015.1: '22222222222222222222222222222222222222',
|
||||
2019.1: '33333333333333333333333333333333333333',
|
||||
},
|
||||
}
|
||||
this.AccessTokenEncryptor = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
Buffer,
|
||||
},
|
||||
requires: {
|
||||
'logger-sharelatex': {
|
||||
err() {},
|
||||
},
|
||||
},
|
||||
})
|
||||
this.encryptor = new this.AccessTokenEncryptor(this.settings)
|
||||
})
|
||||
|
||||
describe('encrypt', function () {
|
||||
it('should encrypt the object', function (done) {
|
||||
this.encryptor.encryptJson(this.testObject, (err, encrypted) => {
|
||||
expect(err).to.be.null
|
||||
encrypted.should.match(
|
||||
/^2019.1:[0-9a-f]{32}:[a-zA-Z0-9=+/]+:[0-9a-f]{32}$/
|
||||
)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should encrypt the object differently the next time', function (done) {
|
||||
this.encryptor.encryptJson(this.testObject, (err, encrypted1) => {
|
||||
expect(err).to.be.null
|
||||
this.encryptor.encryptJson(this.testObject, (err, encrypted2) => {
|
||||
expect(err).to.be.null
|
||||
encrypted1.should.not.equal(encrypted2)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('decrypt', function () {
|
||||
it('should decrypt the string to get the same object', function (done) {
|
||||
this.encryptor.encryptJson(this.testObject, (err, encrypted) => {
|
||||
expect(err).to.be.null
|
||||
this.encryptor.decryptToJson(encrypted, (err, decrypted) => {
|
||||
expect(err).to.be.null
|
||||
expect(decrypted).to.deep.equal(this.testObject)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should decrypt an 2015 string to get the same object', function (done) {
|
||||
this.encryptor.decryptToJson(this.encrypted2015, (err, decrypted) => {
|
||||
expect(err).to.be.null
|
||||
expect(decrypted).to.deep.equal(this.testObject)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should decrypt an 2016 string to get the same object', function (done) {
|
||||
this.encryptor.decryptToJson(this.encrypted2016, (err, decrypted) => {
|
||||
expect(err).to.be.null
|
||||
expect(decrypted).to.deep.equal(this.testObject)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should decrypt an 2019 string to get the same object', function (done) {
|
||||
this.encryptor.decryptToJson(this.encrypted2019, (err, decrypted) => {
|
||||
expect(err).to.be.null
|
||||
expect(decrypted).to.deep.equal(this.testObject)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an error when decrypting an invalid label', function (done) {
|
||||
this.encryptor.decryptToJson(this.badLabel, (err, decrypted) => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
expect(decrypted).to.be.undefined
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an error when decrypting an invalid key', function (done) {
|
||||
this.encryptor.decryptToJson(this.badKey, (err, decrypted) => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
expect(decrypted).to.be.undefined
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an error when decrypting an invalid ciphertext', function (done) {
|
||||
this.encryptor.decryptToJson(this.badCipherText, (err, decrypted) => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
expect(decrypted).to.be.undefined
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"standard",
|
||||
"prettier",
|
||||
"prettier/standard"
|
||||
],
|
||||
"plugins": [
|
||||
"mocha",
|
||||
"chai-expect",
|
||||
"chai-friendly"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"globals": {
|
||||
"expect": true,
|
||||
"define": true,
|
||||
},
|
||||
"settings": {
|
||||
},
|
||||
"rules": {
|
||||
// Add some mocha specific rules
|
||||
"mocha/handle-done-callback": "error",
|
||||
"mocha/no-exclusive-tests": "error",
|
||||
"mocha/no-global-tests": "error",
|
||||
"mocha/no-identical-title": "error",
|
||||
"mocha/no-nested-tests": "error",
|
||||
"mocha/no-pending-tests": "error",
|
||||
"mocha/no-skipped-tests": "error",
|
||||
|
||||
// Add some chai specific rules
|
||||
"chai-expect/missing-assertion": "error",
|
||||
"chai-expect/terminating-properties": "error",
|
||||
// Swap the no-unused-expressions rule with a more chai-friendly one
|
||||
"no-unused-expressions": 0,
|
||||
"chai-friendly/no-unused-expressions": "error"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
node_modules
|
||||
|
||||
.npmrc
|
||||
Dockerfile
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
@@ -1,9 +0,0 @@
|
||||
logger
|
||||
--dependencies=None
|
||||
--docker-repos=gcr.io/overleaf-ops
|
||||
--env-add=
|
||||
--env-pass-through=
|
||||
--is-library=True
|
||||
--node-version=12.22.3
|
||||
--public-repo=False
|
||||
--script-version=3.11.0
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('./logging-manager.js')
|
||||
@@ -1,267 +0,0 @@
|
||||
const bunyan = require('bunyan')
|
||||
const fetch = require('node-fetch')
|
||||
const fs = require('fs')
|
||||
const yn = require('yn')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const GCPLogging = require('@google-cloud/logging-bunyan')
|
||||
|
||||
// bunyan error serializer
|
||||
const errSerializer = function (err) {
|
||||
if (!err || !err.stack) {
|
||||
return err
|
||||
}
|
||||
return {
|
||||
message: err.message,
|
||||
name: err.name,
|
||||
stack: OError.getFullStack(err),
|
||||
info: OError.getFullInfo(err),
|
||||
code: err.code,
|
||||
signal: err.signal
|
||||
}
|
||||
}
|
||||
|
||||
const Logger = (module.exports = {
|
||||
initialize(name) {
|
||||
this.logLevelSource = (process.env.LOG_LEVEL_SOURCE || 'file').toLowerCase()
|
||||
this.isProduction =
|
||||
(process.env.NODE_ENV || '').toLowerCase() === 'production'
|
||||
this.defaultLevel =
|
||||
process.env.LOG_LEVEL || (this.isProduction ? 'warn' : 'debug')
|
||||
this.loggerName = name
|
||||
this.logger = bunyan.createLogger({
|
||||
name,
|
||||
serializers: {
|
||||
err: errSerializer,
|
||||
req: bunyan.stdSerializers.req,
|
||||
res: bunyan.stdSerializers.res
|
||||
},
|
||||
streams: [{ level: this.defaultLevel, stream: process.stdout }]
|
||||
})
|
||||
this._setupRingBuffer()
|
||||
this._setupStackdriver()
|
||||
this._setupLogLevelChecker()
|
||||
return this
|
||||
},
|
||||
|
||||
async checkLogLevel() {
|
||||
try {
|
||||
const end = await this.getTracingEndTime()
|
||||
if (parseInt(end, 10) > Date.now()) {
|
||||
this.logger.level('trace')
|
||||
} else {
|
||||
this.logger.level(this.defaultLevel)
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.level(this.defaultLevel)
|
||||
}
|
||||
},
|
||||
|
||||
async getTracingEndTimeFile() {
|
||||
return fs.promises.readFile('/logging/tracingEndTime')
|
||||
},
|
||||
|
||||
async getTracingEndTimeMetadata() {
|
||||
const options = {
|
||||
headers: {
|
||||
'Metadata-Flavor': 'Google'
|
||||
}
|
||||
}
|
||||
const uri = `http://metadata.google.internal/computeMetadata/v1/project/attributes/${this.loggerName}-setLogLevelEndTime`
|
||||
const res = await fetch(uri, options)
|
||||
if (!res.ok) throw new Error('Metadata not okay')
|
||||
return res.text()
|
||||
},
|
||||
|
||||
initializeErrorReporting(dsn, options) {
|
||||
this.Sentry = require('@sentry/node')
|
||||
this.Sentry.init({ dsn, ...options })
|
||||
this.lastErrorTimeStamp = 0 // for rate limiting on sentry reporting
|
||||
this.lastErrorCount = 0
|
||||
},
|
||||
|
||||
captureException(attributes, message, level) {
|
||||
// handle case of logger.error "message"
|
||||
let key, value
|
||||
if (typeof attributes === 'string') {
|
||||
attributes = { err: new Error(attributes) }
|
||||
}
|
||||
// extract any error object
|
||||
let error = attributes.err || attributes.error
|
||||
// avoid reporting errors twice
|
||||
for (key in attributes) {
|
||||
value = attributes[key]
|
||||
if (value instanceof Error && value.reportedToSentry) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// include our log message in the error report
|
||||
if (error == null) {
|
||||
if (typeof message === 'string') {
|
||||
error = { message }
|
||||
}
|
||||
} else if (message != null) {
|
||||
attributes.description = message
|
||||
}
|
||||
// report the error
|
||||
if (error != null) {
|
||||
// capture attributes and use *_id objects as tags
|
||||
const tags = {}
|
||||
const extra = {}
|
||||
for (key in attributes) {
|
||||
value = attributes[key]
|
||||
if (key.match(/_id/) && typeof value === 'string') {
|
||||
tags[key] = value
|
||||
}
|
||||
extra[key] = value
|
||||
}
|
||||
// capture req object if available
|
||||
const { req } = attributes
|
||||
if (req != null) {
|
||||
extra.req = {
|
||||
method: req.method,
|
||||
url: req.originalUrl,
|
||||
query: req.query,
|
||||
headers: req.headers,
|
||||
ip: req.ip
|
||||
}
|
||||
}
|
||||
// recreate error objects that have been converted to a normal object
|
||||
if (!(error instanceof Error) && typeof error === 'object') {
|
||||
const newError = new Error(error.message)
|
||||
for (key of Object.keys(error || {})) {
|
||||
value = error[key]
|
||||
newError[key] = value
|
||||
}
|
||||
error = newError
|
||||
}
|
||||
// filter paths from the message to avoid duplicate errors in sentry
|
||||
// (e.g. errors from `fs` methods which have a path attribute)
|
||||
try {
|
||||
if (error.path) {
|
||||
error.message = error.message.replace(` '${error.path}'`, '')
|
||||
}
|
||||
|
||||
// send the error to sentry
|
||||
this.Sentry.captureException(error, { tags, extra, level })
|
||||
|
||||
// put a flag on the errors to avoid reporting them multiple times
|
||||
for (key in attributes) {
|
||||
value = attributes[key]
|
||||
if (value instanceof Error) {
|
||||
value.reportedToSentry = true
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore Sentry errors
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
debug() {
|
||||
return this.logger.debug.apply(this.logger, arguments)
|
||||
},
|
||||
|
||||
info() {
|
||||
return this.logger.info.apply(this.logger, arguments)
|
||||
},
|
||||
|
||||
log() {
|
||||
return this.logger.info.apply(this.logger, arguments)
|
||||
},
|
||||
|
||||
error(attributes, message, ...args) {
|
||||
if (this.ringBuffer !== null && Array.isArray(this.ringBuffer.records)) {
|
||||
attributes.logBuffer = this.ringBuffer.records.filter(function (record) {
|
||||
return record.level !== 50
|
||||
})
|
||||
}
|
||||
this.logger.error(attributes, message, ...Array.from(args))
|
||||
if (this.Sentry) {
|
||||
const MAX_ERRORS = 5 // maximum number of errors in 1 minute
|
||||
const now = new Date()
|
||||
// have we recently reported an error?
|
||||
const recentSentryReport = now - this.lastErrorTimeStamp < 60 * 1000
|
||||
// if so, increment the error count
|
||||
if (recentSentryReport) {
|
||||
this.lastErrorCount++
|
||||
} else {
|
||||
this.lastErrorCount = 0
|
||||
this.lastErrorTimeStamp = now
|
||||
}
|
||||
// only report 5 errors every minute to avoid overload
|
||||
if (this.lastErrorCount < MAX_ERRORS) {
|
||||
// add a note if the rate limit has been hit
|
||||
const note =
|
||||
this.lastErrorCount + 1 === MAX_ERRORS ? '(rate limited)' : ''
|
||||
// report the exception
|
||||
return this.captureException(attributes, message, `error${note}`)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
err() {
|
||||
return this.error.apply(this, arguments)
|
||||
},
|
||||
|
||||
warn() {
|
||||
return this.logger.warn.apply(this.logger, arguments)
|
||||
},
|
||||
|
||||
fatal(attributes, message) {
|
||||
this.logger.fatal(attributes, message)
|
||||
if (this.Sentry) {
|
||||
this.captureException(attributes, message, 'fatal')
|
||||
}
|
||||
},
|
||||
|
||||
_setupRingBuffer() {
|
||||
this.ringBufferSize = parseInt(process.env.LOG_RING_BUFFER_SIZE) || 0
|
||||
if (this.ringBufferSize > 0) {
|
||||
this.ringBuffer = new bunyan.RingBuffer({ limit: this.ringBufferSize })
|
||||
this.logger.addStream({
|
||||
level: 'trace',
|
||||
type: 'raw',
|
||||
stream: this.ringBuffer
|
||||
})
|
||||
} else {
|
||||
this.ringBuffer = null
|
||||
}
|
||||
},
|
||||
|
||||
_setupStackdriver() {
|
||||
const stackdriverEnabled = yn(process.env.STACKDRIVER_LOGGING)
|
||||
if (!stackdriverEnabled) {
|
||||
return
|
||||
}
|
||||
const stackdriverClient = new GCPLogging.LoggingBunyan({
|
||||
logName: this.loggerName,
|
||||
serviceContext: { service: this.loggerName }
|
||||
})
|
||||
this.logger.addStream(stackdriverClient.stream(this.defaultLevel))
|
||||
},
|
||||
|
||||
_setupLogLevelChecker() {
|
||||
if (this.isProduction) {
|
||||
// clear interval if already set
|
||||
if (this.checkInterval) {
|
||||
clearInterval(this.checkInterval)
|
||||
}
|
||||
if (this.logLevelSource === 'file') {
|
||||
this.getTracingEndTime = this.getTracingEndTimeFile
|
||||
} else if (this.logLevelSource === 'gce_metadata') {
|
||||
this.getTracingEndTime = this.getTracingEndTimeMetadata
|
||||
} else if (this.logLevelSource === 'none') {
|
||||
return
|
||||
} else {
|
||||
console.log('Unrecognised log level source')
|
||||
return
|
||||
}
|
||||
// check for log level override on startup
|
||||
this.checkLogLevel()
|
||||
// re-check log level every minute
|
||||
this.checkInterval = setInterval(this.checkLogLevel.bind(this), 1000 * 60)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Logger.initialize('default-sharelatex')
|
||||
Generated
-4809
File diff suppressed because it is too large
Load Diff
@@ -1,45 +0,0 @@
|
||||
{
|
||||
"name": "@overleaf/logger",
|
||||
"homepage": "www.overleaf.com",
|
||||
"description": "A centralised logging system for Overleaf",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/overleaf/overleaf"
|
||||
},
|
||||
"license": "AGPL-3.0-only",
|
||||
"version": "2.3.0",
|
||||
"scripts": {
|
||||
"test": "mocha --grep=$MOCHA_GREP test/**/*.js",
|
||||
"format": "prettier-eslint $PWD'/**/*.js' --list-different",
|
||||
"format:fix": "prettier-eslint $PWD'/**/*.js' --write",
|
||||
"lint": "eslint -f unix .",
|
||||
"test:ci": "npm run test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google-cloud/logging-bunyan": "^3.1.0",
|
||||
"@overleaf/o-error": "^3.0.0",
|
||||
"@sentry/node": "^6.13.2",
|
||||
"bunyan": "^1.8.14",
|
||||
"node-fetch": "^2.6.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^7.3.1",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-config-standard": "^14.1.1",
|
||||
"eslint-plugin-chai-expect": "^2.1.0",
|
||||
"eslint-plugin-chai-friendly": "^0.6.0",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"eslint-plugin-mocha": "^7.0.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"eslint-plugin-standard": "^4.0.1",
|
||||
"mocha": "^8.4.0",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier-eslint-cli": "^5.0.0",
|
||||
"sandboxed-module": "^2.0.4",
|
||||
"sinon": "^9.0.2",
|
||||
"sinon-chai": "^3.5.0"
|
||||
}
|
||||
}
|
||||
@@ -1,568 +0,0 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const bunyan = require('bunyan')
|
||||
const chai = require('chai')
|
||||
const path = require('path')
|
||||
const sinon = require('sinon')
|
||||
const sinonChai = require('sinon-chai')
|
||||
|
||||
chai.use(sinonChai)
|
||||
chai.should()
|
||||
const expect = chai.expect
|
||||
|
||||
const modulePath = path.join(__dirname, '../../logging-manager.js')
|
||||
|
||||
describe('LoggingManager', function () {
|
||||
beforeEach(function () {
|
||||
this.start = Date.now()
|
||||
this.clock = sinon.useFakeTimers(this.start)
|
||||
this.captureException = sinon.stub()
|
||||
this.bunyanLogger = {
|
||||
addStream: sinon.stub(),
|
||||
debug: sinon.stub(),
|
||||
error: sinon.stub(),
|
||||
fatal: sinon.stub(),
|
||||
info: sinon.stub(),
|
||||
level: sinon.stub(),
|
||||
warn: sinon.stub()
|
||||
}
|
||||
this.Sentry = {
|
||||
init: sinon.stub(),
|
||||
captureException: this.captureException
|
||||
}
|
||||
this.fetchResponse = {
|
||||
text: sinon.stub().resolves(''),
|
||||
status: 200,
|
||||
ok: true
|
||||
}
|
||||
this.Bunyan = {
|
||||
createLogger: sinon.stub().returns(this.bunyanLogger),
|
||||
RingBuffer: bunyan.RingBuffer,
|
||||
stdSerializers: {
|
||||
req: sinon.stub(),
|
||||
res: sinon.stub()
|
||||
}
|
||||
}
|
||||
this.Fetch = sinon.stub().resolves(this.fetchResponse)
|
||||
this.Fs = {
|
||||
readFile: sinon.stub(),
|
||||
promises: {
|
||||
readFile: sinon.stub()
|
||||
}
|
||||
}
|
||||
this.stackdriverStreamConfig = { stream: 'stackdriver' }
|
||||
this.stackdriverClient = {
|
||||
stream: sinon.stub().returns(this.stackdriverStreamConfig)
|
||||
}
|
||||
this.GCPLogging = {
|
||||
LoggingBunyan: sinon.stub().returns(this.stackdriverClient)
|
||||
}
|
||||
this.LoggingManager = SandboxedModule.require(modulePath, {
|
||||
globals: { console, process },
|
||||
requires: {
|
||||
bunyan: this.Bunyan,
|
||||
'@sentry/node': this.Sentry,
|
||||
'node-fetch': this.Fetch,
|
||||
fs: this.Fs,
|
||||
'@google-cloud/logging-bunyan': this.GCPLogging
|
||||
}
|
||||
})
|
||||
this.loggerName = 'test'
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
this.logger.initializeErrorReporting('test_dsn')
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.clock.restore()
|
||||
})
|
||||
|
||||
describe('initialize', function () {
|
||||
beforeEach(function () {
|
||||
this.checkLogLevelStub = sinon
|
||||
.stub(this.LoggingManager, 'checkLogLevel')
|
||||
.resolves('')
|
||||
this.Bunyan.createLogger.reset()
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.checkLogLevelStub.restore()
|
||||
})
|
||||
|
||||
describe('not in production', function () {
|
||||
beforeEach(function () {
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
})
|
||||
|
||||
it('should default to log level debug', function () {
|
||||
this.Bunyan.createLogger.firstCall.args[0].streams[0].level.should.equal(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not run checkLogLevel', function () {
|
||||
this.checkLogLevelStub.should.not.have.been.called
|
||||
})
|
||||
})
|
||||
|
||||
describe('in production', function () {
|
||||
beforeEach(function () {
|
||||
process.env.NODE_ENV = 'production'
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
})
|
||||
|
||||
afterEach(() => delete process.env.NODE_ENV)
|
||||
|
||||
it('should default to log level warn', function () {
|
||||
this.Bunyan.createLogger.firstCall.args[0].streams[0].level.should.equal(
|
||||
'warn'
|
||||
)
|
||||
})
|
||||
|
||||
describe('logLevelSource file', function () {
|
||||
it('should run checkLogLevel', function () {
|
||||
this.checkLogLevelStub.should.have.been.calledOnce
|
||||
})
|
||||
|
||||
describe('after 1 minute', () =>
|
||||
it('should run checkLogLevel again', function () {
|
||||
this.clock.tick(61 * 1000)
|
||||
this.checkLogLevelStub.should.have.been.calledTwice
|
||||
}))
|
||||
|
||||
describe('after 2 minutes', () =>
|
||||
it('should run checkLogLevel again', function () {
|
||||
this.clock.tick(121 * 1000)
|
||||
this.checkLogLevelStub.should.have.been.calledThrice
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('when LOG_LEVEL set in env', function () {
|
||||
beforeEach(function () {
|
||||
process.env.LOG_LEVEL = 'trace'
|
||||
this.LoggingManager.initialize()
|
||||
})
|
||||
|
||||
afterEach(() => delete process.env.LOG_LEVEL)
|
||||
|
||||
it('should use custom log level', function () {
|
||||
this.Bunyan.createLogger.firstCall.args[0].streams[0].level.should.equal(
|
||||
'trace'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('bunyan logging', function () {
|
||||
beforeEach(function () {
|
||||
this.logArgs = [{ foo: 'bar' }, 'foo', 'bar']
|
||||
})
|
||||
|
||||
it('should log debug', function () {
|
||||
this.logger.debug(this.logArgs)
|
||||
this.bunyanLogger.debug.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log error', function () {
|
||||
this.logger.error(this.logArgs)
|
||||
this.bunyanLogger.error.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log fatal', function () {
|
||||
this.logger.fatal(this.logArgs)
|
||||
this.bunyanLogger.fatal.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log info', function () {
|
||||
this.logger.info(this.logArgs)
|
||||
this.bunyanLogger.info.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log warn', function () {
|
||||
this.logger.warn(this.logArgs)
|
||||
this.bunyanLogger.warn.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log err', function () {
|
||||
this.logger.err(this.logArgs)
|
||||
this.bunyanLogger.error.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
|
||||
it('should log log', function () {
|
||||
this.logger.log(this.logArgs)
|
||||
this.bunyanLogger.info.should.have.been.calledWith(this.logArgs)
|
||||
})
|
||||
})
|
||||
|
||||
describe('logger.error', function () {
|
||||
it('should report a single error to sentry', function () {
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.captureException.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should report the same error to sentry only once', function () {
|
||||
const error1 = new Error('this is the error')
|
||||
this.logger.error({ foo: error1 }, 'first message')
|
||||
this.logger.error({ bar: error1 }, 'second message')
|
||||
this.captureException.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should report two different errors to sentry individually', function () {
|
||||
const error1 = new Error('this is the error')
|
||||
const error2 = new Error('this is the error')
|
||||
this.logger.error({ foo: error1 }, 'first message')
|
||||
this.logger.error({ bar: error2 }, 'second message')
|
||||
this.captureException.callCount.should.equal(2)
|
||||
})
|
||||
|
||||
it('should remove the path from fs errors', function () {
|
||||
const fsError = new Error(
|
||||
"Error: ENOENT: no such file or directory, stat '/tmp/3279b8d0-da10-11e8-8255-efd98985942b'"
|
||||
)
|
||||
fsError.path = '/tmp/3279b8d0-da10-11e8-8255-efd98985942b'
|
||||
this.logger.error({ err: fsError }, 'message')
|
||||
this.captureException
|
||||
.calledWith(
|
||||
sinon.match.has(
|
||||
'message',
|
||||
'Error: ENOENT: no such file or directory, stat'
|
||||
)
|
||||
)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('for multiple errors should only report a maximum of 5 errors to sentry', function () {
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.captureException.callCount.should.equal(5)
|
||||
})
|
||||
|
||||
it('for multiple errors with a minute delay should report 10 errors to sentry', function () {
|
||||
// the first five errors should be reported to sentry
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
// the following errors should not be reported
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
// allow a minute to pass
|
||||
this.clock.tick(this.start + 61 * 1000)
|
||||
// after a minute the next five errors should be reported to sentry
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
// the following errors should not be reported to sentry
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.logger.error({ foo: 'bar' }, 'message')
|
||||
this.captureException.callCount.should.equal(10)
|
||||
})
|
||||
|
||||
describe('reportedToSentry', function () {
|
||||
it('should mark the error as reported to sentry', function () {
|
||||
const err = new Error()
|
||||
this.logger.error({ err }, 'message')
|
||||
expect(this.captureException.called).to.equal(true)
|
||||
expect(err.reportedToSentry).to.equal(true)
|
||||
})
|
||||
|
||||
it('should mark two errors as reported to sentry', function () {
|
||||
const err1 = new Error()
|
||||
const err2 = new Error()
|
||||
this.logger.error({ err: err1, err2 }, 'message')
|
||||
expect(this.captureException.called).to.equal(true)
|
||||
expect(err1.reportedToSentry).to.equal(true)
|
||||
expect(err2.reportedToSentry).to.equal(true)
|
||||
})
|
||||
|
||||
it('should not mark arbitrary objects as reported to sentry', function () {
|
||||
const err = new Error()
|
||||
const ctx = { foo: 'bar' }
|
||||
this.logger.error({ err, ctx }, 'message')
|
||||
expect(this.captureException.called).to.equal(true)
|
||||
expect(ctx.reportedToSentry).to.equal(undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkLogLevelFile', function () {
|
||||
it('should request log level override from the config map', async function () {
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
this.Fs.promises.readFile.should.have.been.calledWithMatch(
|
||||
'/logging/tracingEndTime'
|
||||
)
|
||||
})
|
||||
|
||||
describe('when read errors', function () {
|
||||
beforeEach(async function () {
|
||||
this.Fs.promises.readFile.throws(new Error('test read error'))
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the file is empty', function () {
|
||||
beforeEach(async function () {
|
||||
this.Fs.promises.readFile.returns('')
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when time value returned that is less than current time', function () {
|
||||
beforeEach(async function () {
|
||||
this.Fs.promises.readFile.returns('1')
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when time value returned that is more than current time', function () {
|
||||
describe('when level is already set', function () {
|
||||
beforeEach(async function () {
|
||||
this.bunyanLogger.level.returns(10)
|
||||
this.Fs.promises.readFile.returns((this.start + 1000).toString())
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should set trace level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'trace'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when level is not already set', function () {
|
||||
beforeEach(async function () {
|
||||
this.bunyanLogger.level.returns(20)
|
||||
this.Fs.promises.readFile.returns((this.start + 1000).toString())
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeFile
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should set trace level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'trace'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkLogLevelMetadata', function () {
|
||||
beforeEach(function () {
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
})
|
||||
|
||||
describe('checkLogLevel', function () {
|
||||
it('should request log level override from google meta data service', async function () {
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeMetadata
|
||||
await this.logger.checkLogLevel()
|
||||
const options = {
|
||||
headers: {
|
||||
'Metadata-Flavor': 'Google'
|
||||
}
|
||||
}
|
||||
const uri = `http://metadata.google.internal/computeMetadata/v1/project/attributes/${this.loggerName}-setLogLevelEndTime`
|
||||
this.Fetch.should.have.been.calledWithMatch(uri, options)
|
||||
})
|
||||
|
||||
describe('when request has error', function () {
|
||||
beforeEach(async function () {
|
||||
this.Fetch = sinon.stub().throws()
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeMetadata
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when statusCode is not 200', function () {
|
||||
beforeEach(async function () {
|
||||
this.fetchResponse.status = 404
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeMetadata
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when time value returned that is less than current time', function () {
|
||||
beforeEach(async function () {
|
||||
this.logger.getTracingEndTime = this.logger.getTracingEndTimeMetadata
|
||||
this.fetchResponse.text = sinon.stub().resolves('1')
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should only set default level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'debug'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when time value returned that is more than current time', function () {
|
||||
describe('when level is already set', function () {
|
||||
beforeEach(async function () {
|
||||
this.bunyanLogger.level.returns(10)
|
||||
this.fetchResponse.text = sinon
|
||||
.stub()
|
||||
.resolves((this.start + 1000).toString())
|
||||
this.logger.getTracingEndTime =
|
||||
this.logger.getTracingEndTimeMetadata
|
||||
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should set trace level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'trace'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when level is not already set', function () {
|
||||
beforeEach(async function () {
|
||||
this.bunyanLogger.level.returns(20)
|
||||
this.fetchResponse.text = sinon
|
||||
.stub()
|
||||
.resolves((this.start + 1000).toString())
|
||||
this.Fetch.fetch = sinon.stub().resolves(this.fetchResponse)
|
||||
this.logger.getTracingEndTime =
|
||||
this.logger.getTracingEndTimeMetadata
|
||||
|
||||
await this.logger.checkLogLevel()
|
||||
})
|
||||
|
||||
it('should set trace level', function () {
|
||||
this.bunyanLogger.level.should.have.been.calledOnce.and.calledWith(
|
||||
'trace'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ringbuffer', function () {
|
||||
beforeEach(function () {
|
||||
this.logBufferMock = [
|
||||
{ msg: 'log 1' },
|
||||
{ msg: 'log 2' },
|
||||
{ level: 50, msg: 'error' }
|
||||
]
|
||||
})
|
||||
|
||||
describe('when ring buffer size is positive', function () {
|
||||
beforeEach(function () {
|
||||
process.env.LOG_RING_BUFFER_SIZE = '20'
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
this.logger.ringBuffer.records = this.logBufferMock
|
||||
this.logger.error({}, 'error')
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
process.env.LOG_RING_BUFFER_SIZE = undefined
|
||||
})
|
||||
|
||||
it('should include buffered logs in error log and filter out error logs in buffer', function () {
|
||||
this.bunyanLogger.error.lastCall.args[0].logBuffer.should.deep.equal([
|
||||
{ msg: 'log 1' },
|
||||
{ msg: 'log 2' }
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('when ring buffer size is zero', function () {
|
||||
beforeEach(function () {
|
||||
process.env.LOG_RING_BUFFER_SIZE = '0'
|
||||
this.logger = this.LoggingManager.initialize(this.loggerName)
|
||||
this.logger.error({}, 'error')
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
process.env.LOG_RING_BUFFER_SIZE = undefined
|
||||
})
|
||||
|
||||
it('should not include buffered logs in error log', function () {
|
||||
expect(this.bunyanLogger.error.lastCall.args[0].logBuffer).be.undefined
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('stackdriver logging', function () {
|
||||
describe('when STACKDRIVER_LOGGING is unset', function () {
|
||||
beforeEach(function () {
|
||||
process.env.STACKDRIVER_LOGGING = undefined
|
||||
this.LoggingManager.initialize(this.loggerName)
|
||||
})
|
||||
|
||||
it('is disabled', function () {
|
||||
expect(this.bunyanLogger.addStream).not.to.have.been.calledWith(
|
||||
this.stackdriverStreamConfig
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when STACKDRIVER_LOGGING is true', function () {
|
||||
beforeEach(function () {
|
||||
process.env.STACKDRIVER_LOGGING = 'true'
|
||||
this.LoggingManager.initialize(this.loggerName)
|
||||
})
|
||||
|
||||
it('is enabled', function () {
|
||||
expect(this.bunyanLogger.addStream).to.have.been.calledWith(
|
||||
this.stackdriverStreamConfig
|
||||
)
|
||||
})
|
||||
|
||||
it('is configured properly', function () {
|
||||
expect(this.GCPLogging.LoggingBunyan).to.have.been.calledWith({
|
||||
logName: this.loggerName,
|
||||
serviceContext: { service: this.loggerName }
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,11 +0,0 @@
|
||||
version: 2.1
|
||||
|
||||
orbs:
|
||||
node: circleci/node@3.0.0
|
||||
|
||||
workflows:
|
||||
test:
|
||||
jobs:
|
||||
- node/test:
|
||||
version: "10.22"
|
||||
override-ci-command: npm install
|
||||
@@ -1,55 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"standard",
|
||||
"prettier",
|
||||
"prettier/standard"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": [
|
||||
"mocha",
|
||||
"chai-expect",
|
||||
"chai-friendly"
|
||||
],
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
// Swap the no-unused-expressions rule with a more chai-friendly one
|
||||
"no-unused-expressions": 0,
|
||||
"chai-friendly/no-unused-expressions": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
// Test specific rules
|
||||
"files": ["test/**/*.js"],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"globals": {
|
||||
"expect": true
|
||||
},
|
||||
"rules": {
|
||||
// mocha-specific rules
|
||||
"mocha/handle-done-callback": "error",
|
||||
"mocha/no-exclusive-tests": "error",
|
||||
"mocha/no-global-tests": "error",
|
||||
"mocha/no-identical-title": "error",
|
||||
"mocha/no-nested-tests": "error",
|
||||
"mocha/no-pending-tests": "error",
|
||||
"mocha/no-skipped-tests": "error",
|
||||
"mocha/no-mocha-arrows": "error",
|
||||
|
||||
// chai-specific rules
|
||||
"chai-expect/missing-assertion": "error",
|
||||
"chai-expect/terminating-properties": "error",
|
||||
|
||||
// prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
|
||||
// we don't enforce this at the top-level - just in tests to manage `this` scope
|
||||
// based on mocha's context mechanism
|
||||
"mocha/prefer-arrow-callback": "error"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
node_modules
|
||||
|
||||
.npmrc
|
||||
Dockerfile
|
||||
@@ -1,4 +0,0 @@
|
||||
/.circleci
|
||||
/.eslintrc
|
||||
/.nvmrc
|
||||
/.prettierrc
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 ShareLaTeX
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,30 +0,0 @@
|
||||
overleaf/metrics-module
|
||||
=======================
|
||||
|
||||
Wrappers the [prom-client](https://github.com/siimon/prom-client) npm module to provide [Prometheus](https://prometheus.io/) metrics at `/metrics`.
|
||||
|
||||
Use:
|
||||
```
|
||||
const metrics = require('@overleaf/metrics')
|
||||
metrics.initialize('myapp')
|
||||
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
metrics.injectMetricsRoute(app)
|
||||
```
|
||||
Request logging can be enabled:
|
||||
```
|
||||
const logger = require('logger-sharelatex')
|
||||
...
|
||||
app.use(metrics.http.monitor(logger))
|
||||
```
|
||||
|
||||
The metrics module can be configured through the following environment variables:
|
||||
|
||||
* `DEBUG_METRICS` - enables display of debugging messages to the console.
|
||||
* `ENABLE_TRACE_AGENT` - enables @google-cloud/trace-agent on Google Cloud
|
||||
* `ENABLE_DEBUG_AGENT` - enables @google-cloud/debug-agent on Google Cloud
|
||||
* `ENABLE_PROFILE_AGENT` - enables @google-cloud/profiler on Google Cloud
|
||||
* `METRICS_COMPRESSION_LEVEL` - sets the [compression level](https://www.npmjs.com/package/compression#level) for `/metrics`
|
||||
* `STACKDRIVER_LOGGING` - toggles the request logging format
|
||||
* `UV_THREADPOOL_SIZE` - sets the libuv [thread pool](http://docs.libuv.org/en/v1.x/threadpool.html) size
|
||||
@@ -1,9 +0,0 @@
|
||||
metrics
|
||||
--dependencies=None
|
||||
--docker-repos=gcr.io/overleaf-ops
|
||||
--env-add=
|
||||
--env-pass-through=
|
||||
--is-library=True
|
||||
--node-version=12.22.3
|
||||
--public-repo=False
|
||||
--script-version=3.11.0
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
module.exports = {
|
||||
monitor(logger, interval, logThreshold) {
|
||||
if (interval == null) {
|
||||
interval = 1000
|
||||
}
|
||||
if (logThreshold == null) {
|
||||
logThreshold = 100
|
||||
}
|
||||
const Metrics = require('./index')
|
||||
// check for logger on startup to avoid exceptions later if undefined
|
||||
if (logger == null) {
|
||||
throw new Error('logger is undefined')
|
||||
}
|
||||
// monitor delay in setInterval to detect event loop blocking
|
||||
let previous = Date.now()
|
||||
const intervalId = setInterval(function() {
|
||||
const now = Date.now()
|
||||
const offset = now - previous - interval
|
||||
if (offset > logThreshold) {
|
||||
logger.warn({ offset }, 'slow event loop')
|
||||
}
|
||||
previous = now
|
||||
return Metrics.timing('event-loop-millsec', offset)
|
||||
}, interval)
|
||||
|
||||
return Metrics.registerDestructor(() => clearInterval(intervalId))
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
const yn = require('yn')
|
||||
|
||||
const STACKDRIVER_LOGGING = yn(process.env.STACKDRIVER_LOGGING)
|
||||
|
||||
module.exports.monitor = logger =>
|
||||
function(req, res, next) {
|
||||
const Metrics = require('./index')
|
||||
const startTime = process.hrtime()
|
||||
const { end } = res
|
||||
res.end = function() {
|
||||
end.apply(this, arguments)
|
||||
const responseTime = process.hrtime(startTime)
|
||||
const responseTimeMs = Math.round(
|
||||
responseTime[0] * 1000 + responseTime[1] / 1000000
|
||||
)
|
||||
const requestSize = parseInt(req.headers['content-length'], 10)
|
||||
const routePath = getRoutePath(req)
|
||||
const remoteIp = getRemoteIp(req)
|
||||
const reqUrl = req.originalUrl || req.url
|
||||
const referrer = req.headers.referer || req.headers.referrer
|
||||
|
||||
if (routePath != null) {
|
||||
Metrics.timing('http_request', responseTimeMs, null, {
|
||||
method: req.method,
|
||||
status_code: res.statusCode,
|
||||
path: routePath
|
||||
})
|
||||
if (requestSize) {
|
||||
Metrics.summary('http_request_size_bytes', requestSize, {
|
||||
method: req.method,
|
||||
status_code: res.statusCode,
|
||||
path: routePath
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let info
|
||||
if (STACKDRIVER_LOGGING) {
|
||||
info = {
|
||||
httpRequest: {
|
||||
requestMethod: req.method,
|
||||
requestUrl: reqUrl,
|
||||
requestSize,
|
||||
status: res.statusCode,
|
||||
responseSize: res.getHeader('content-length'),
|
||||
userAgent: req.headers['user-agent'],
|
||||
remoteIp,
|
||||
referer: referrer,
|
||||
latency: {
|
||||
seconds: responseTime[0],
|
||||
nanos: responseTime[1]
|
||||
},
|
||||
protocol: req.protocol
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info = {
|
||||
req: {
|
||||
url: reqUrl,
|
||||
method: req.method,
|
||||
referrer,
|
||||
'remote-addr': remoteIp,
|
||||
'user-agent': req.headers['user-agent'],
|
||||
'content-length': req.headers['content-length']
|
||||
},
|
||||
res: {
|
||||
'content-length': res.getHeader('content-length'),
|
||||
statusCode: res.statusCode
|
||||
},
|
||||
'response-time': responseTimeMs
|
||||
}
|
||||
}
|
||||
logger.info(info, '%s %s', req.method, reqUrl)
|
||||
}
|
||||
next()
|
||||
}
|
||||
|
||||
function getRoutePath(req) {
|
||||
if (req.route && req.route.path != null) {
|
||||
return req.route.path
|
||||
.toString()
|
||||
.replace(/\//g, '_')
|
||||
.replace(/:/g, '')
|
||||
.slice(1)
|
||||
}
|
||||
if (req.swagger && req.swagger.apiPath != null) {
|
||||
return req.swagger.apiPath
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function getRemoteIp(req) {
|
||||
if (req.ip) {
|
||||
return req.ip
|
||||
}
|
||||
if (req.socket) {
|
||||
if (req.socket.socket && req.socket.socket.remoteAddress) {
|
||||
return req.socket.socket.remoteAddress
|
||||
} else if (req.socket.remoteAddress) {
|
||||
return req.socket.remoteAddress
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
const os = require('os')
|
||||
const ExpressCompression = require('compression')
|
||||
const promClient = require('prom-client')
|
||||
const promWrapper = require('./prom_wrapper')
|
||||
|
||||
const DEFAULT_APP_NAME = 'unknown'
|
||||
|
||||
const { collectDefaultMetrics } = promWrapper
|
||||
const destructors = []
|
||||
|
||||
require('./uv_threadpool_size')
|
||||
|
||||
/**
|
||||
* Configure the metrics module
|
||||
*/
|
||||
function configure(opts = {}) {
|
||||
const appName = opts.appName || DEFAULT_APP_NAME
|
||||
const hostname = os.hostname()
|
||||
promClient.register.setDefaultLabels({ app: appName, host: hostname })
|
||||
if (opts.ttlInMinutes) {
|
||||
promWrapper.ttlInMinutes = opts.ttlInMinutes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the metrics module and start the default metrics collectors and
|
||||
* profiling agents.
|
||||
*/
|
||||
function initialize(appName, opts = {}) {
|
||||
appName = appName || DEFAULT_APP_NAME
|
||||
configure({ ...opts, appName })
|
||||
collectDefaultMetrics({ timeout: 5000, prefix: '' })
|
||||
promWrapper.setupSweeping()
|
||||
|
||||
console.log(`ENABLE_TRACE_AGENT set to ${process.env.ENABLE_TRACE_AGENT}`)
|
||||
if (process.env.ENABLE_TRACE_AGENT === 'true') {
|
||||
console.log('starting google trace agent')
|
||||
const traceAgent = require('@google-cloud/trace-agent')
|
||||
|
||||
const traceOpts = { ignoreUrls: [/^\/status/, /^\/health_check/] }
|
||||
traceAgent.start(traceOpts)
|
||||
}
|
||||
|
||||
console.log(`ENABLE_DEBUG_AGENT set to ${process.env.ENABLE_DEBUG_AGENT}`)
|
||||
if (process.env.ENABLE_DEBUG_AGENT === 'true') {
|
||||
console.log('starting google debug agent')
|
||||
const debugAgent = require('@google-cloud/debug-agent')
|
||||
debugAgent.start({
|
||||
allowExpressions: true,
|
||||
serviceContext: {
|
||||
service: appName,
|
||||
version: process.env.BUILD_VERSION
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
console.log(`ENABLE_PROFILE_AGENT set to ${process.env.ENABLE_PROFILE_AGENT}`)
|
||||
if (process.env.ENABLE_PROFILE_AGENT === 'true') {
|
||||
console.log('starting google profile agent')
|
||||
const profiler = require('@google-cloud/profiler')
|
||||
profiler.start({
|
||||
serviceContext: {
|
||||
service: appName,
|
||||
version: process.env.BUILD_VERSION
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
inc('process_startup')
|
||||
}
|
||||
|
||||
function registerDestructor(func) {
|
||||
destructors.push(func)
|
||||
}
|
||||
|
||||
function injectMetricsRoute(app) {
|
||||
app.get(
|
||||
'/metrics',
|
||||
ExpressCompression({
|
||||
level: parseInt(process.env.METRICS_COMPRESSION_LEVEL || '1', 10)
|
||||
}),
|
||||
function(req, res) {
|
||||
res.set('Content-Type', promWrapper.registry.contentType)
|
||||
res.end(promWrapper.registry.metrics())
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function buildPromKey(key) {
|
||||
return key.replace(/[^a-zA-Z0-9]/g, '_')
|
||||
}
|
||||
|
||||
function sanitizeValue(value) {
|
||||
return parseFloat(value)
|
||||
}
|
||||
|
||||
function set(key, value, sampleRate = 1) {
|
||||
console.log('counts are not currently supported')
|
||||
}
|
||||
|
||||
function inc(key, sampleRate = 1, opts = {}) {
|
||||
key = buildPromKey(key)
|
||||
promWrapper.metric('counter', key).inc(opts)
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('doing inc', key, opts)
|
||||
}
|
||||
}
|
||||
|
||||
function count(key, count, sampleRate = 1, opts = {}) {
|
||||
key = buildPromKey(key)
|
||||
promWrapper.metric('counter', key).inc(opts, count)
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('doing count/inc', key, opts)
|
||||
}
|
||||
}
|
||||
|
||||
function summary(key, value, opts = {}) {
|
||||
key = buildPromKey(key)
|
||||
promWrapper.metric('summary', key).observe(opts, value)
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('doing summary', key, value, opts)
|
||||
}
|
||||
}
|
||||
|
||||
function timing(key, timeSpan, sampleRate = 1, opts = {}) {
|
||||
key = buildPromKey('timer_' + key)
|
||||
promWrapper.metric('summary', key).observe(opts, timeSpan)
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('doing timing', key, opts)
|
||||
}
|
||||
}
|
||||
|
||||
class Timer {
|
||||
constructor(key, sampleRate = 1, opts = {}) {
|
||||
this.start = new Date()
|
||||
key = buildPromKey(key)
|
||||
this.key = key
|
||||
this.sampleRate = sampleRate
|
||||
this.opts = opts
|
||||
}
|
||||
|
||||
done() {
|
||||
const timeSpan = new Date() - this.start
|
||||
timing(this.key, timeSpan, this.sampleRate, this.opts)
|
||||
return timeSpan
|
||||
}
|
||||
}
|
||||
|
||||
function gauge(key, value, sampleRate = 1, opts = {}) {
|
||||
key = buildPromKey(key)
|
||||
promWrapper
|
||||
.metric('gauge', key)
|
||||
.set({ status: opts.status }, sanitizeValue(value))
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('doing gauge', key, opts)
|
||||
}
|
||||
}
|
||||
|
||||
function globalGauge(key, value, sampleRate = 1, opts = {}) {
|
||||
key = buildPromKey(key)
|
||||
promWrapper
|
||||
.metric('gauge', key)
|
||||
.set({ host: 'global', status: opts.status }, sanitizeValue(value))
|
||||
}
|
||||
|
||||
function close() {
|
||||
for (const func of destructors) {
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
configure,
|
||||
initialize,
|
||||
registerDestructor,
|
||||
injectMetricsRoute,
|
||||
buildPromKey,
|
||||
sanitizeValue,
|
||||
set,
|
||||
inc,
|
||||
count,
|
||||
summary,
|
||||
timing,
|
||||
Timer,
|
||||
gauge,
|
||||
globalGauge,
|
||||
close,
|
||||
prom: promClient,
|
||||
|
||||
register: promWrapper.registry,
|
||||
|
||||
mongodb: require('./mongodb'),
|
||||
http: require('./http'),
|
||||
open_sockets: require('./open_sockets'),
|
||||
event_loop: require('./event_loop'),
|
||||
memory: require('./memory'),
|
||||
timeAsyncMethod: require('./timeAsyncMethod')
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
// record memory usage each minute and run a periodic gc(), keeping cpu
|
||||
// usage within allowable range of 1ms per minute. Also, dynamically
|
||||
// adjust the period between gc()'s to reach a target of the gc saving
|
||||
// 4 megabytes each time.
|
||||
|
||||
let MemoryMonitor
|
||||
const oneMinute = 60 * 1000
|
||||
const oneMegaByte = 1024 * 1024
|
||||
|
||||
let CpuTimeBucket = 100 // current cpu time allowance in milliseconds
|
||||
const CpuTimeBucketMax = 100 // maximum amount of cpu time allowed in bucket
|
||||
const CpuTimeBucketRate = 10 // add this many milliseconds per minute
|
||||
|
||||
let gcInterval = 1 // how many minutes between gc (parameter is dynamically adjusted)
|
||||
let countSinceLastGc = 0 // how many minutes since last gc
|
||||
const MemoryChunkSize = 4 // how many megabytes we need to free to consider gc worth doing
|
||||
|
||||
const readyToGc = function() {
|
||||
// update allowed cpu time
|
||||
CpuTimeBucket = CpuTimeBucket + CpuTimeBucketRate
|
||||
CpuTimeBucket =
|
||||
CpuTimeBucket < CpuTimeBucketMax ? CpuTimeBucket : CpuTimeBucketMax
|
||||
// update counts since last gc
|
||||
countSinceLastGc = countSinceLastGc + 1
|
||||
// check there is enough time since last gc and we have enough cpu
|
||||
return countSinceLastGc > gcInterval && CpuTimeBucket > 0
|
||||
}
|
||||
|
||||
const executeAndTime = function(fn) {
|
||||
// time the execution of fn() and subtract from cpu allowance
|
||||
const t0 = process.hrtime()
|
||||
fn()
|
||||
const dt = process.hrtime(t0)
|
||||
const timeTaken = (dt[0] + dt[1] * 1e-9) * 1e3 // in milliseconds
|
||||
CpuTimeBucket -= Math.ceil(timeTaken)
|
||||
return timeTaken
|
||||
}
|
||||
|
||||
const inMegaBytes = function(obj) {
|
||||
// convert process.memoryUsage hash {rss,heapTotal,heapFreed} into megabytes
|
||||
const result = {}
|
||||
for (const k in obj) {
|
||||
const v = obj[k]
|
||||
result[k] = (v / oneMegaByte).toFixed(2)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const updateMemoryStats = function(oldMem, newMem) {
|
||||
countSinceLastGc = 0
|
||||
const delta = {}
|
||||
for (const k in newMem) {
|
||||
delta[k] = (newMem[k] - oldMem[k]).toFixed(2)
|
||||
}
|
||||
// take the max of all memory measures
|
||||
const savedMemory = Math.max(-delta.rss, -delta.heapTotal, -delta.heapUsed)
|
||||
delta.megabytesFreed = savedMemory
|
||||
// did it do any good?
|
||||
if (savedMemory < MemoryChunkSize) {
|
||||
gcInterval = gcInterval + 1 // no, so wait longer next time
|
||||
} else {
|
||||
gcInterval = Math.max(gcInterval - 1, 1) // yes, wait less time
|
||||
}
|
||||
return delta
|
||||
}
|
||||
|
||||
module.exports = MemoryMonitor = {
|
||||
monitor(logger) {
|
||||
const interval = setInterval(() => MemoryMonitor.Check(logger), oneMinute)
|
||||
const Metrics = require('./index')
|
||||
return Metrics.registerDestructor(() => clearInterval(interval))
|
||||
},
|
||||
|
||||
Check(logger) {
|
||||
let mem
|
||||
const Metrics = require('./index')
|
||||
const memBeforeGc = (mem = inMegaBytes(process.memoryUsage()))
|
||||
Metrics.gauge('memory.rss', mem.rss)
|
||||
Metrics.gauge('memory.heaptotal', mem.heapTotal)
|
||||
Metrics.gauge('memory.heapused', mem.heapUsed)
|
||||
Metrics.gauge('memory.gc-interval', gcInterval)
|
||||
// Metrics.gauge("memory.cpu-time-bucket", CpuTimeBucket)
|
||||
|
||||
logger.log(mem, 'process.memoryUsage()')
|
||||
|
||||
if (global.gc != null && readyToGc()) {
|
||||
const gcTime = executeAndTime(global.gc).toFixed(2)
|
||||
const memAfterGc = inMegaBytes(process.memoryUsage())
|
||||
const deltaMem = updateMemoryStats(memBeforeGc, memAfterGc)
|
||||
logger.log(
|
||||
{
|
||||
gcTime,
|
||||
memBeforeGc,
|
||||
memAfterGc,
|
||||
deltaMem,
|
||||
gcInterval,
|
||||
CpuTimeBucket
|
||||
},
|
||||
'global.gc() forced'
|
||||
)
|
||||
// Metrics.timing("memory.gc-time", gcTime)
|
||||
Metrics.gauge('memory.gc-rss-freed', -deltaMem.rss)
|
||||
Metrics.gauge('memory.gc-heaptotal-freed', -deltaMem.heapTotal)
|
||||
return Metrics.gauge('memory.gc-heapused-freed', -deltaMem.heapUsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
module.exports = {
|
||||
monitor(mongodbRequirePath, logger) {
|
||||
let mongodb, mongodbCore
|
||||
try {
|
||||
// for the v1 driver the methods to wrap are in the mongodb
|
||||
// module in lib/mongodb/db.js
|
||||
mongodb = require(mongodbRequirePath)
|
||||
} catch (error) {}
|
||||
|
||||
try {
|
||||
// for the v2 driver the relevant methods are in the mongodb-core
|
||||
// module in lib/topologies/{server,replset,mongos}.js
|
||||
const v2Path = mongodbRequirePath.replace(/\/mongodb$/, '/mongodb-core')
|
||||
mongodbCore = require(v2Path)
|
||||
} catch (error1) {}
|
||||
|
||||
const Metrics = require('./index')
|
||||
|
||||
const monitorMethod = function(base, method, type) {
|
||||
let _method
|
||||
if (base == null) {
|
||||
return
|
||||
}
|
||||
if ((_method = base[method]) == null) {
|
||||
return
|
||||
}
|
||||
const arglen = _method.length
|
||||
|
||||
const mongoDriverV1Wrapper = function(dbCommand, options, callback) {
|
||||
let query
|
||||
if (typeof callback === 'undefined') {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
const collection = dbCommand.collectionName
|
||||
if (collection.match(/\$cmd$/)) {
|
||||
// Ignore noisy command methods like authenticating, ismaster and ping
|
||||
return _method.call(this, dbCommand, options, callback)
|
||||
}
|
||||
|
||||
if (dbCommand.query != null) {
|
||||
query = Object.keys(dbCommand.query)
|
||||
.sort()
|
||||
.join('_')
|
||||
}
|
||||
|
||||
const timer = new Metrics.Timer('mongo', { collection, query })
|
||||
const start = new Date()
|
||||
return _method.call(this, dbCommand, options, function() {
|
||||
timer.done()
|
||||
logger.log(
|
||||
{
|
||||
query: dbCommand.query,
|
||||
query_type: type,
|
||||
collection,
|
||||
'response-time': new Date() - start
|
||||
},
|
||||
'mongo request'
|
||||
)
|
||||
return callback.apply(this, arguments)
|
||||
})
|
||||
}
|
||||
|
||||
const mongoDriverV2Wrapper = function(ns, ops, options, callback) {
|
||||
let query
|
||||
if (typeof callback === 'undefined') {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
if (ns.match(/\$cmd$/)) {
|
||||
// Ignore noisy command methods like authenticating, ismaster and ping
|
||||
return _method.call(this, ns, ops, options, callback)
|
||||
}
|
||||
|
||||
let key = `mongo-requests.${ns}.${type}`
|
||||
if (ops[0].q != null) {
|
||||
// ops[0].q
|
||||
query = Object.keys(ops[0].q)
|
||||
.sort()
|
||||
.join('_')
|
||||
key += '.' + query
|
||||
}
|
||||
|
||||
const timer = new Metrics.Timer(key)
|
||||
const start = new Date()
|
||||
return _method.call(this, ns, ops, options, function() {
|
||||
timer.done()
|
||||
logger.log(
|
||||
{
|
||||
query: ops[0].q,
|
||||
query_type: type,
|
||||
collection: ns,
|
||||
'response-time': new Date() - start
|
||||
},
|
||||
'mongo request'
|
||||
)
|
||||
return callback.apply(this, arguments)
|
||||
})
|
||||
}
|
||||
|
||||
if (arglen === 3) {
|
||||
return (base[method] = mongoDriverV1Wrapper)
|
||||
} else if (arglen === 4) {
|
||||
return (base[method] = mongoDriverV2Wrapper)
|
||||
}
|
||||
}
|
||||
|
||||
monitorMethod(
|
||||
mongodb != null ? mongodb.Db.prototype : undefined,
|
||||
'_executeQueryCommand',
|
||||
'query'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodb != null ? mongodb.Db.prototype : undefined,
|
||||
'_executeRemoveCommand',
|
||||
'remove'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodb != null ? mongodb.Db.prototype : undefined,
|
||||
'_executeInsertCommand',
|
||||
'insert'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodb != null ? mongodb.Db.prototype : undefined,
|
||||
'_executeUpdateCommand',
|
||||
'update'
|
||||
)
|
||||
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Server.prototype : undefined,
|
||||
'command',
|
||||
'command'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Server.prototype : undefined,
|
||||
'remove',
|
||||
'remove'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Server.prototype : undefined,
|
||||
'insert',
|
||||
'insert'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Server.prototype : undefined,
|
||||
'update',
|
||||
'update'
|
||||
)
|
||||
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.ReplSet.prototype : undefined,
|
||||
'command',
|
||||
'command'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.ReplSet.prototype : undefined,
|
||||
'remove',
|
||||
'remove'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.ReplSet.prototype : undefined,
|
||||
'insert',
|
||||
'insert'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.ReplSet.prototype : undefined,
|
||||
'update',
|
||||
'update'
|
||||
)
|
||||
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Mongos.prototype : undefined,
|
||||
'command',
|
||||
'command'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Mongos.prototype : undefined,
|
||||
'remove',
|
||||
'remove'
|
||||
)
|
||||
monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Mongos.prototype : undefined,
|
||||
'insert',
|
||||
'insert'
|
||||
)
|
||||
return monitorMethod(
|
||||
mongodbCore != null ? mongodbCore.Mongos.prototype : undefined,
|
||||
'update',
|
||||
'update'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS205: Consider reworking code to avoid use of IIFEs
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let OpenSocketsMonitor
|
||||
const seconds = 1000
|
||||
|
||||
// In Node 0.10 the default is 5, which means only 5 open connections at one.
|
||||
// Node 0.12 has a default of Infinity. Make sure we have no limit set,
|
||||
// regardless of Node version.
|
||||
require('http').globalAgent.maxSockets = Infinity
|
||||
require('https').globalAgent.maxSockets = Infinity
|
||||
|
||||
const SOCKETS_HTTP = require('http').globalAgent.sockets
|
||||
const SOCKETS_HTTPS = require('https').globalAgent.sockets
|
||||
|
||||
// keep track of set gauges and reset them in the next collection cycle
|
||||
const SEEN_HOSTS_HTTP = new Set()
|
||||
const SEEN_HOSTS_HTTPS = new Set()
|
||||
|
||||
function collectOpenConnections(sockets, seenHosts, prefix) {
|
||||
const Metrics = require('./index')
|
||||
Object.keys(sockets).forEach(host => seenHosts.add(host))
|
||||
seenHosts.forEach(host => {
|
||||
// host: 'HOST:PORT:'
|
||||
const hostname = host.split(':')[0]
|
||||
const openConnections = (sockets[host] || []).length
|
||||
if (!openConnections) {
|
||||
seenHosts.delete(host)
|
||||
}
|
||||
Metrics.gauge(`open_connections.${prefix}.${hostname}`, openConnections)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = OpenSocketsMonitor = {
|
||||
monitor(logger) {
|
||||
const interval = setInterval(
|
||||
() => OpenSocketsMonitor.gaugeOpenSockets(),
|
||||
5 * seconds
|
||||
)
|
||||
const Metrics = require('./index')
|
||||
return Metrics.registerDestructor(() => clearInterval(interval))
|
||||
},
|
||||
|
||||
gaugeOpenSockets() {
|
||||
collectOpenConnections(SOCKETS_HTTP, SEEN_HOSTS_HTTP, 'http')
|
||||
collectOpenConnections(SOCKETS_HTTPS, SEEN_HOSTS_HTTPS, 'https')
|
||||
}
|
||||
}
|
||||
Generated
-5189
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
||||
{
|
||||
"name": "@overleaf/metrics",
|
||||
"version": "3.5.2",
|
||||
"description": "A drop-in metrics and monitoring module for node.js apps",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/overleaf/metrics-module.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google-cloud/debug-agent": "^5.1.2",
|
||||
"@google-cloud/profiler": "^4.1.3",
|
||||
"@google-cloud/trace-agent": "^5.1.1",
|
||||
"compression": "^1.7.4",
|
||||
"prom-client": "^11.1.3",
|
||||
"yn": "^3.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bunyan": "^1.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^7.8.1",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-config-standard": "^14.1.1",
|
||||
"eslint-plugin-chai-expect": "^2.2.0",
|
||||
"eslint-plugin-chai-friendly": "^0.6.0",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"eslint-plugin-mocha": "^8.0.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"eslint-plugin-standard": "^4.0.1",
|
||||
"mocha": "^8.0.1",
|
||||
"prettier-eslint-cli": "^5.0.0",
|
||||
"sandboxed-module": "^2.0.4",
|
||||
"sinon": "^9.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --max-warnings 0 .",
|
||||
"test:unit": "mocha --reporter spec --recursive --exit --grep=$MOCHA_GREP test/unit",
|
||||
"test:acceptance": "mocha --reporter spec --recursive --exit --grep=$MOCHA_GREP test/acceptance",
|
||||
"test": "npm run test:unit && npm run test:acceptance",
|
||||
"format": "prettier-eslint $PWD'/**/*.js' --list-different",
|
||||
"format:fix": "prettier-eslint $PWD'/**/*.js' --write",
|
||||
"test:ci": "npm run test"
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS205: Consider reworking code to avoid use of IIFEs
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const prom = require('prom-client')
|
||||
const registry = require('prom-client').register
|
||||
const metrics = new Map()
|
||||
|
||||
const optsKey = function(opts) {
|
||||
let keys = Object.keys(opts)
|
||||
if (keys.length === 0) {
|
||||
return ''
|
||||
}
|
||||
|
||||
keys = keys.sort()
|
||||
|
||||
let hash = ''
|
||||
for (const key of Array.from(keys)) {
|
||||
if (hash.length) {
|
||||
hash += ','
|
||||
}
|
||||
hash += `${key}:${opts[key]}`
|
||||
}
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
const extendOpts = function(opts, labelNames) {
|
||||
for (const label of Array.from(labelNames)) {
|
||||
if (!opts[label]) {
|
||||
opts[label] = ''
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
const optsAsArgs = function(opts, labelNames) {
|
||||
const args = []
|
||||
for (const label of Array.from(labelNames)) {
|
||||
args.push(opts[label] || '')
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
const PromWrapper = {
|
||||
ttlInMinutes: 0,
|
||||
registry,
|
||||
|
||||
metric(type, name) {
|
||||
return metrics.get(name) || new MetricWrapper(type, name)
|
||||
},
|
||||
|
||||
collectDefaultMetrics: prom.collectDefaultMetrics
|
||||
}
|
||||
|
||||
class MetricWrapper {
|
||||
constructor(type, name) {
|
||||
metrics.set(name, this)
|
||||
this.name = name
|
||||
this.instances = new Map()
|
||||
this.lastAccess = new Date()
|
||||
this.metric = (() => {
|
||||
switch (type) {
|
||||
case 'counter':
|
||||
return new prom.Counter({
|
||||
name,
|
||||
help: name,
|
||||
labelNames: ['status', 'method', 'path']
|
||||
})
|
||||
case 'summary':
|
||||
return new prom.Summary({
|
||||
name,
|
||||
help: name,
|
||||
maxAgeSeconds: 60,
|
||||
ageBuckets: 10,
|
||||
labelNames: ['path', 'status_code', 'method', 'collection', 'query']
|
||||
})
|
||||
case 'gauge':
|
||||
return new prom.Gauge({
|
||||
name,
|
||||
help: name,
|
||||
labelNames: ['host', 'status']
|
||||
})
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
inc(opts, value) {
|
||||
return this._execMethod('inc', opts, value)
|
||||
}
|
||||
|
||||
observe(opts, value) {
|
||||
return this._execMethod('observe', opts, value)
|
||||
}
|
||||
|
||||
set(opts, value) {
|
||||
return this._execMethod('set', opts, value)
|
||||
}
|
||||
|
||||
sweep() {
|
||||
const thresh = new Date(Date.now() - 1000 * 60 * PromWrapper.ttlInMinutes)
|
||||
this.instances.forEach((instance, key) => {
|
||||
if (thresh > instance.time) {
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log(
|
||||
'Sweeping stale metric instance',
|
||||
this.name,
|
||||
{ opts: instance.opts },
|
||||
key
|
||||
)
|
||||
}
|
||||
return this.metric.remove(
|
||||
...Array.from(optsAsArgs(instance.opts, this.metric.labelNames) || [])
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
if (thresh > this.lastAccess) {
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('Sweeping stale metric', this.name, thresh, this.lastAccess)
|
||||
}
|
||||
metrics.delete(this.name)
|
||||
return registry.removeSingleMetric(this.name)
|
||||
}
|
||||
}
|
||||
|
||||
_execMethod(method, opts, value) {
|
||||
opts = extendOpts(opts, this.metric.labelNames)
|
||||
const key = optsKey(opts)
|
||||
if (key !== '') {
|
||||
this.instances.set(key, { time: new Date(), opts })
|
||||
}
|
||||
this.lastAccess = new Date()
|
||||
return this.metric[method](opts, value)
|
||||
}
|
||||
}
|
||||
|
||||
let sweepingInterval
|
||||
PromWrapper.setupSweeping = function() {
|
||||
if (sweepingInterval) {
|
||||
clearInterval(sweepingInterval)
|
||||
}
|
||||
if (!PromWrapper.ttlInMinutes) {
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('Not registering sweep method -- empty ttl')
|
||||
}
|
||||
return
|
||||
}
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('Registering sweep method')
|
||||
}
|
||||
sweepingInterval = setInterval(function() {
|
||||
if (process.env.DEBUG_METRICS) {
|
||||
console.log('Sweeping metrics')
|
||||
}
|
||||
return metrics.forEach((metric, key) => {
|
||||
return metric.sweep()
|
||||
})
|
||||
}, 60000)
|
||||
|
||||
const Metrics = require('./index')
|
||||
Metrics.registerDestructor(() => clearInterval(sweepingInterval))
|
||||
}
|
||||
|
||||
module.exports = PromWrapper
|
||||
@@ -1,245 +0,0 @@
|
||||
const os = require('os')
|
||||
const http = require('http')
|
||||
const { expect } = require('chai')
|
||||
const Metrics = require('../..')
|
||||
|
||||
const HOSTNAME = os.hostname()
|
||||
const APP_NAME = 'test-app'
|
||||
|
||||
describe('Metrics module', function() {
|
||||
before(function() {
|
||||
Metrics.initialize(APP_NAME)
|
||||
})
|
||||
|
||||
describe('at startup', function() {
|
||||
it('increments the process_startup counter', async function() {
|
||||
await expectMetricValue('process_startup', 1)
|
||||
})
|
||||
|
||||
it('collects default metrics', async function() {
|
||||
const metric = await getMetric('process_cpu_user_seconds_total')
|
||||
expect(metric).to.exist
|
||||
})
|
||||
})
|
||||
|
||||
describe('inc()', function() {
|
||||
it('increments counts by 1', async function() {
|
||||
Metrics.inc('duck_count')
|
||||
await expectMetricValue('duck_count', 1)
|
||||
Metrics.inc('duck_count')
|
||||
Metrics.inc('duck_count')
|
||||
await expectMetricValue('duck_count', 3)
|
||||
})
|
||||
|
||||
it('escapes special characters in the key', async function() {
|
||||
Metrics.inc('show.me the $!!')
|
||||
await expectMetricValue('show_me_the____', 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('count()', function() {
|
||||
it('increments counts by the given count', async function() {
|
||||
Metrics.count('rabbit_count', 5)
|
||||
await expectMetricValue('rabbit_count', 5)
|
||||
Metrics.count('rabbit_count', 6)
|
||||
Metrics.count('rabbit_count', 7)
|
||||
await expectMetricValue('rabbit_count', 18)
|
||||
})
|
||||
})
|
||||
|
||||
describe('summary()', function() {
|
||||
it('collects observations', async function() {
|
||||
Metrics.summary('oven_temp', 200)
|
||||
Metrics.summary('oven_temp', 300)
|
||||
Metrics.summary('oven_temp', 450)
|
||||
const sum = await getSummarySum('oven_temp')
|
||||
expect(sum).to.equal(950)
|
||||
})
|
||||
})
|
||||
|
||||
describe('timing()', function() {
|
||||
it('collects timings', async function() {
|
||||
Metrics.timing('sprint_100m', 10)
|
||||
Metrics.timing('sprint_100m', 20)
|
||||
Metrics.timing('sprint_100m', 30)
|
||||
const sum = await getSummarySum('timer_sprint_100m')
|
||||
expect(sum).to.equal(60)
|
||||
})
|
||||
})
|
||||
|
||||
describe('gauge()', function() {
|
||||
it('records values', async function() {
|
||||
Metrics.gauge('water_level', 1.5)
|
||||
await expectMetricValue('water_level', 1.5)
|
||||
Metrics.gauge('water_level', 4.2)
|
||||
await expectMetricValue('water_level', 4.2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('globalGauge()', function() {
|
||||
it('records values without a host label', async function() {
|
||||
Metrics.globalGauge('tire_pressure', 99.99)
|
||||
const { value, labels } = await getMetricValue('tire_pressure')
|
||||
expect(value).to.equal(99.99)
|
||||
expect(labels.host).to.equal('global')
|
||||
expect(labels.app).to.equal(APP_NAME)
|
||||
})
|
||||
})
|
||||
|
||||
describe('open_sockets', function() {
|
||||
const keyServer1 = 'open_connections_http_127_42_42_1'
|
||||
const keyServer2 = 'open_connections_http_127_42_42_2'
|
||||
|
||||
let finish1, finish2, emitResponse1, emitResponse2
|
||||
function resetEmitResponse1() {
|
||||
emitResponse1 = new Promise(resolve => (finish1 = resolve))
|
||||
}
|
||||
resetEmitResponse1()
|
||||
function resetEmitResponse2() {
|
||||
emitResponse2 = new Promise(resolve => (finish2 = resolve))
|
||||
}
|
||||
resetEmitResponse2()
|
||||
|
||||
let server1, server2
|
||||
before(function setupServer1(done) {
|
||||
server1 = http.createServer((req, res) => {
|
||||
res.write('...')
|
||||
emitResponse1.then(() => res.end())
|
||||
})
|
||||
server1.listen(0, '127.42.42.1', done)
|
||||
})
|
||||
before(function setupServer2(done) {
|
||||
server2 = http.createServer((req, res) => {
|
||||
res.write('...')
|
||||
emitResponse2.then(() => res.end())
|
||||
})
|
||||
server2.listen(0, '127.42.42.2', done)
|
||||
})
|
||||
after(function cleanupPendingRequests() {
|
||||
finish1()
|
||||
finish2()
|
||||
})
|
||||
after(function shutdownServer1(done) {
|
||||
if (server1) server1.close(done)
|
||||
})
|
||||
after(function shutdownServer2(done) {
|
||||
if (server2) server2.close(done)
|
||||
})
|
||||
|
||||
let urlServer1, urlServer2
|
||||
before(function setUrls() {
|
||||
urlServer1 = `http://127.42.42.1:${server1.address().port}/`
|
||||
urlServer2 = `http://127.42.42.2:${server2.address().port}/`
|
||||
})
|
||||
describe('gaugeOpenSockets()', function() {
|
||||
beforeEach(function runGaugeOpenSockets() {
|
||||
Metrics.open_sockets.gaugeOpenSockets()
|
||||
})
|
||||
|
||||
describe('without pending connections', function() {
|
||||
it('emits no open_connections', async function() {
|
||||
await expectNoMetricValue(keyServer1)
|
||||
await expectNoMetricValue(keyServer2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with pending connections for server1', function() {
|
||||
before(function(done) {
|
||||
http.get(urlServer1)
|
||||
http.get(urlServer1)
|
||||
setTimeout(done, 10)
|
||||
})
|
||||
|
||||
it('emits 2 open_connections for server1', async function() {
|
||||
await expectMetricValue(keyServer1, 2)
|
||||
})
|
||||
|
||||
it('emits no open_connections for server2', async function() {
|
||||
await expectNoMetricValue(keyServer2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with pending connections for server1 and server2', function() {
|
||||
before(function(done) {
|
||||
http.get(urlServer2)
|
||||
http.get(urlServer2)
|
||||
setTimeout(done, 10)
|
||||
})
|
||||
|
||||
it('emits 2 open_connections for server1', async function() {
|
||||
await expectMetricValue(keyServer1, 2)
|
||||
})
|
||||
|
||||
it('emits 2 open_connections for server2', async function() {
|
||||
await expectMetricValue(keyServer2, 2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when requests finish for server1', function() {
|
||||
before(function(done) {
|
||||
finish1()
|
||||
resetEmitResponse1()
|
||||
http.get(urlServer1)
|
||||
|
||||
setTimeout(done, 10)
|
||||
})
|
||||
|
||||
it('emits 1 open_connections for server1', async function() {
|
||||
await expectMetricValue(keyServer1, 1)
|
||||
})
|
||||
|
||||
it('emits 2 open_connections for server2', async function() {
|
||||
await expectMetricValue(keyServer2, 2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when all requests complete', function() {
|
||||
before(function(done) {
|
||||
finish1()
|
||||
finish2()
|
||||
|
||||
setTimeout(done, 10)
|
||||
})
|
||||
|
||||
it('emits no open_connections', async function() {
|
||||
await expectNoMetricValue(keyServer1)
|
||||
await expectNoMetricValue(keyServer2)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function getMetric(key) {
|
||||
return Metrics.register.getSingleMetric(key)
|
||||
}
|
||||
|
||||
async function getSummarySum(key) {
|
||||
const metric = getMetric(key)
|
||||
const item = await metric.get()
|
||||
for (const value of item.values) {
|
||||
if (value.metricName === `${key}_sum`) {
|
||||
return value.value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function getMetricValue(key) {
|
||||
const metrics = await Metrics.register.getMetricsAsJSON()
|
||||
const metric = metrics.find(m => m.name === key)
|
||||
return metric.values[0]
|
||||
}
|
||||
|
||||
async function expectMetricValue(key, expectedValue) {
|
||||
const value = await getMetricValue(key)
|
||||
expect(value.value).to.equal(expectedValue)
|
||||
expect(value.labels.host).to.equal(HOSTNAME)
|
||||
expect(value.labels.app).to.equal(APP_NAME)
|
||||
}
|
||||
|
||||
async function expectNoMetricValue(key) {
|
||||
const metric = getMetric(key)
|
||||
if (!metric) return
|
||||
await expectMetricValue(key, 0)
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const chai = require('chai')
|
||||
const { expect } = chai
|
||||
const path = require('path')
|
||||
const modulePath = path.join(__dirname, '../../../event_loop.js')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
|
||||
describe('event_loop', function() {
|
||||
before(function() {
|
||||
this.metrics = {
|
||||
timing: sinon.stub(),
|
||||
registerDestructor: sinon.stub()
|
||||
}
|
||||
this.logger = {
|
||||
warn: sinon.stub()
|
||||
}
|
||||
return (this.event_loop = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./index': this.metrics
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
describe('with a logger provided', function() {
|
||||
before(function() {
|
||||
return this.event_loop.monitor(this.logger)
|
||||
})
|
||||
|
||||
return it('should register a destructor with metrics', function() {
|
||||
return expect(this.metrics.registerDestructor.called).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('without a logger provided', function() {
|
||||
return it('should throw an exception', function() {
|
||||
return expect(this.event_loop.monitor).to.throw('logger is undefined')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const chai = require('chai')
|
||||
const { expect } = chai
|
||||
const path = require('path')
|
||||
const modulePath = path.join(__dirname, '../../../timeAsyncMethod.js')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
|
||||
describe('timeAsyncMethod', function() {
|
||||
beforeEach(function() {
|
||||
this.Timer = { done: sinon.stub() }
|
||||
this.TimerConstructor = sinon.stub().returns(this.Timer)
|
||||
this.metrics = {
|
||||
Timer: this.TimerConstructor,
|
||||
inc: sinon.stub()
|
||||
}
|
||||
this.timeAsyncMethod = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./index': this.metrics
|
||||
}
|
||||
})
|
||||
|
||||
return (this.testObject = {
|
||||
nextNumber(n, callback) {
|
||||
return setTimeout(() => callback(null, n + 1), 100)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should have the testObject behave correctly before wrapping', function(done) {
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
expect(err).to.not.exist
|
||||
expect(result).to.equal(3)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should wrap method without error', function(done) {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
return done()
|
||||
})
|
||||
|
||||
it('should transparently wrap method invocation in timer', function(done) {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
expect(err).to.not.exist
|
||||
expect(result).to.equal(3)
|
||||
expect(this.TimerConstructor.callCount).to.equal(1)
|
||||
expect(this.Timer.done.callCount).to.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should increment success count', function(done) {
|
||||
this.metrics.inc = sinon.stub()
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
if (err) {
|
||||
return done(err)
|
||||
}
|
||||
expect(this.metrics.inc.callCount).to.equal(1)
|
||||
expect(
|
||||
this.metrics.inc.calledWith('someContext_result', 1, {
|
||||
method: 'TestObject_nextNumber',
|
||||
status: 'success'
|
||||
})
|
||||
).to.equal(true)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when base method produces an error', function() {
|
||||
beforeEach(function() {
|
||||
this.metrics.inc = sinon.stub()
|
||||
return (this.testObject.nextNumber = function(n, callback) {
|
||||
return setTimeout(() => callback(new Error('woops')), 100)
|
||||
})
|
||||
})
|
||||
|
||||
it('should propagate the error transparently', function(done) {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
expect(err).to.exist
|
||||
expect(err).to.be.instanceof(Error)
|
||||
expect(result).to.not.exist
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
return it('should increment failure count', function(done) {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
expect(err).to.exist
|
||||
expect(this.metrics.inc.callCount).to.equal(1)
|
||||
expect(
|
||||
this.metrics.inc.calledWith('someContext_result', 1, {
|
||||
method: 'TestObject_nextNumber',
|
||||
status: 'failed'
|
||||
})
|
||||
).to.equal(true)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a logger is supplied', function() {
|
||||
beforeEach(function() {
|
||||
return (this.logger = { log: sinon.stub() })
|
||||
})
|
||||
|
||||
return it('should also call logger.log', function(done) {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject',
|
||||
this.logger
|
||||
)
|
||||
return this.testObject.nextNumber(2, (err, result) => {
|
||||
expect(err).to.not.exist
|
||||
expect(result).to.equal(3)
|
||||
expect(this.TimerConstructor.callCount).to.equal(1)
|
||||
expect(this.Timer.done.callCount).to.equal(1)
|
||||
expect(this.logger.log.callCount).to.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the wrapper cannot be applied', function() {
|
||||
beforeEach(function() {})
|
||||
|
||||
return it('should raise an error', function() {
|
||||
const badWrap = () => {
|
||||
return this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'DEFINITELY_NOT_A_REAL_METHOD',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
}
|
||||
return expect(badWrap).to.throw(
|
||||
/^.*expected object property 'DEFINITELY_NOT_A_REAL_METHOD' to be a function.*$/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the wrapped function is not using a callback', function() {
|
||||
beforeEach(function() {
|
||||
this.realMethod = sinon.stub().returns(42)
|
||||
return (this.testObject.nextNumber = this.realMethod)
|
||||
})
|
||||
|
||||
it('should not throw an error', function() {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
const badCall = () => {
|
||||
return this.testObject.nextNumber(2)
|
||||
}
|
||||
return expect(badCall).to.not.throw(Error)
|
||||
})
|
||||
|
||||
return it('should call the underlying method', function() {
|
||||
this.timeAsyncMethod(
|
||||
this.testObject,
|
||||
'nextNumber',
|
||||
'someContext.TestObject'
|
||||
)
|
||||
const result = this.testObject.nextNumber(12)
|
||||
expect(this.realMethod.callCount).to.equal(1)
|
||||
expect(this.realMethod.calledWith(12)).to.equal(true)
|
||||
return expect(result).to.equal(42)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS201: Simplify complex destructure assignments
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
||||
module.exports = function(obj, methodName, prefix, logger) {
|
||||
let modifedMethodName
|
||||
const metrics = require('./index')
|
||||
|
||||
if (typeof obj[methodName] !== 'function') {
|
||||
throw new Error(
|
||||
`[Metrics] expected object property '${methodName}' to be a function`
|
||||
)
|
||||
}
|
||||
|
||||
const key = `${prefix}.${methodName}`
|
||||
|
||||
const realMethod = obj[methodName]
|
||||
|
||||
const splitPrefix = prefix.split('.')
|
||||
const startPrefix = splitPrefix[0]
|
||||
|
||||
if (splitPrefix[1] != null) {
|
||||
modifedMethodName = `${splitPrefix[1]}_${methodName}`
|
||||
} else {
|
||||
modifedMethodName = methodName
|
||||
}
|
||||
return (obj[methodName] = function(...originalArgs) {
|
||||
const adjustedLength = Math.max(originalArgs.length, 1)
|
||||
const firstArgs = originalArgs.slice(0, adjustedLength - 1)
|
||||
const callback = originalArgs[adjustedLength - 1]
|
||||
|
||||
if (callback == null || typeof callback !== 'function') {
|
||||
if (logger != null) {
|
||||
logger.log(
|
||||
`[Metrics] expected wrapped method '${methodName}' to be invoked with a callback`
|
||||
)
|
||||
}
|
||||
return realMethod.apply(this, originalArgs)
|
||||
}
|
||||
|
||||
const timer = new metrics.Timer(startPrefix, 1, {
|
||||
method: modifedMethodName
|
||||
})
|
||||
|
||||
return realMethod.call(this, ...Array.from(firstArgs), function(
|
||||
...callbackArgs
|
||||
) {
|
||||
const elapsedTime = timer.done()
|
||||
const possibleError = callbackArgs[0]
|
||||
if (possibleError != null) {
|
||||
metrics.inc(`${startPrefix}_result`, 1, {
|
||||
status: 'failed',
|
||||
method: modifedMethodName
|
||||
})
|
||||
} else {
|
||||
metrics.inc(`${startPrefix}_result`, 1, {
|
||||
status: 'success',
|
||||
method: modifedMethodName
|
||||
})
|
||||
}
|
||||
if (logger != null) {
|
||||
const loggableArgs = {}
|
||||
try {
|
||||
for (let idx = 0; idx < firstArgs.length; idx++) {
|
||||
const arg = firstArgs[idx]
|
||||
if (arg.toString().match(/^[0-9a-f]{24}$/)) {
|
||||
loggableArgs[`${idx}`] = arg
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
logger.log(
|
||||
{ key, args: loggableArgs, elapsedTime },
|
||||
'[Metrics] timed async method call'
|
||||
)
|
||||
}
|
||||
return callback.apply(this, callbackArgs)
|
||||
})
|
||||
})
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user