This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Donald Morton <[email protected]>
- Loading branch information
Showing
6 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Set autobuild to false if you do not want to enable compilation when a file changes. | ||
# This will enable http authentication if credentials section is filled. | ||
autobuild: true | ||
|
||
# Add files and folders you want autobuild watcher to ignore on changes. | ||
ignore: | ||
- .git | ||
|
||
# Add a username and a password if you want to enable http authentication. | ||
# This will not work if autobuild is enabled. | ||
credentials: | ||
username: ~ | ||
password: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3-alpine | ||
|
||
MAINTAINER Jan Doberstein <[email protected]> | ||
|
||
COPY ./requirements.txt requirements.txt | ||
|
||
RUN apk add --no-cache --virtual --update py3-pip make wget ca-certificates ttf-dejavu \ | ||
&& pip install --upgrade pip \ | ||
&& pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY ./server.py /opt/sphinx-server/ | ||
COPY ./.sphinx-server.yml /opt/sphinx-server/ | ||
|
||
WORKDIR /web | ||
|
||
EXPOSE 8000 35729 | ||
|
||
CMD ["python", "/opt/sphinx-server/server.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
services: | ||
graylog-documentation: | ||
build: . | ||
image: graylog/documentation | ||
container_name: graylog-documentation | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- .:/web | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
THIS_DIR=$(cd `dirname $0`; pwd -P) | ||
DOCKER_IMAGE_NAME="graylog/documentation" | ||
DOCKER_CONTAINER_NAME="graylog-documentation" | ||
|
||
function exit_error { | ||
message="${1}" | ||
echo -e "\n\033[31mERROR: $message\033[0m" >/dev/stderr | ||
exit 1 | ||
} | ||
|
||
# check if Docker is installed | ||
which docker >/dev/null | ||
if [[ $? != 0 ]] ; then | ||
exit_error "Docker does not seem to be installed (or resides in an unusual path). Please fix that first." | ||
fi | ||
|
||
# if the image is running ask to stop | ||
docker ps | grep -qw ${DOCKER_CONTAINER_NAME} | ||
if [[ $? == 0 ]] ; then | ||
read -p "Graylog documentation Docker container running, Stop? (y/n)" -n 1 -r | ||
echo # (optional) move to a new line | ||
if [[ $REPLY =~ ^[Yy]$ ]] ; then | ||
|
||
# stop | ||
docker stop ${DOCKER_CONTAINER_NAME} | ||
|
||
if [[ $? == 0 ]] ; then | ||
read -p "remove the Graylog documentation Docker image? (y/n)" -n 1 -r | ||
echo # (optional) move to a new line | ||
if [[ $REPLY =~ ^[Yy]$ ]] ; then | ||
docker rmi ${DOCKER_IMAGE_NAME} | ||
exit 0 | ||
fi | ||
fi | ||
|
||
exit 0 | ||
fi | ||
|
||
echo "no action needed." | ||
echo "connect to the Graylog Docker container" | ||
echo "defaults to http://127.0.0.1:8000" | ||
exit 0 | ||
fi | ||
|
||
# check if Docker image is present, otherwise build it | ||
docker images | grep -qw ${DOCKER_IMAGE_NAME} | ||
if [[ $? != 0 ]] ; then | ||
echo "Docker image not found, will build it now" | ||
docker build -t ${DOCKER_IMAGE_NAME} -f ${THIS_DIR}/Dockerfile . && echo "Done" | ||
fi | ||
|
||
# read additional environment variables from .env, if present | ||
[[ -e ${THIS_DIR}/.env ]] && source ${THIS_DIR}/.env | ||
|
||
# check if Docker container is present, otherwise make the first start with all arguments | ||
docker ps -a | grep -qw ${DOCKER_CONTAINER_NAME} | ||
if [[ $? != 0 ]] ; then | ||
echo "Docker starting:" | ||
docker run -it -d --rm -v "${THIS_DIR}":/web -u $(id -u):$(id -g) -p 8000:8000 --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME} | ||
|
||
echo "Graylog documentation Docker container created," | ||
echo "defaults to http://127.0.0.1:8000" | ||
exit 0 | ||
fi | ||
|
||
# now the normal start should be possible, but we will check | ||
docker images | grep -qw ${DOCKER_CONTAINER_NAME} | ||
if [[ $? == 0 ]] ; then | ||
echo "Starting the Docker container, will be serving on http://127.0.0.1:8000 by default" | ||
docker start graylog-documentation | ||
exit 0 | ||
fi | ||
|
||
exit_error "we should never reach this point!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import sphinx_autobuild | ||
import os | ||
import sys | ||
from contextlib import contextmanager | ||
import base64 | ||
from livereload import Server | ||
import http.server | ||
import http.server | ||
import socketserver | ||
import yaml | ||
|
||
|
||
class AuthHandler(http.server.SimpleHTTPRequestHandler): | ||
""" | ||
Authentication handler used to support HTTP authentication | ||
""" | ||
def do_HEAD(self): | ||
self.send_response(200) | ||
self.send_header('Content-type', 'text/html') | ||
self.end_headers() | ||
|
||
def do_AUTHHEAD(self): | ||
self.send_response(401) | ||
self.send_header('WWW-Authenticate', 'Basic realm=\"Restricted area\"') | ||
self.send_header('Content-type', 'text/html') | ||
self.end_headers() | ||
|
||
def do_GET(self): | ||
global key | ||
if self.headers.get('Authorization') is None: | ||
self.do_AUTHHEAD() | ||
self.wfile.write('Credentials required.'.encode('utf-8')) | ||
pass | ||
elif self.headers.get('Authorization') == 'Basic ' + key.decode('utf-8'): | ||
http.server.SimpleHTTPRequestHandler.do_GET(self) | ||
pass | ||
else: | ||
self.do_AUTHHEAD() | ||
self.wfile.write('Credentials required.'.encode('utf-8')) | ||
pass | ||
|
||
''' | ||
This function is used to simulate the manipulation of the stack (like pushd and popd in BASH) | ||
and change the folder with the usage of the context manager | ||
''' | ||
@contextmanager | ||
def pushd(new_dir): | ||
previous_dir = os.getcwd() | ||
os.chdir(new_dir) | ||
yield | ||
os.chdir(previous_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
key = '' | ||
config_file = '.sphinx-server.yml' | ||
install_folder = '/opt/sphinx-server/' | ||
build_folder = os.path.realpath('_build/html') | ||
source_folder = os.path.realpath('.') | ||
configuration = None | ||
|
||
with open(install_folder + config_file, 'r') as config_stream: | ||
configuration = yaml.safe_load(config_stream) | ||
|
||
if os.path.isfile(source_folder + '/' + config_file): | ||
with open(source_folder + '/' + config_file, "r") as custom_stream: | ||
configuration.update(yaml.safe_load(custom_stream)) | ||
|
||
if not os.path.exists(build_folder): | ||
os.makedirs(build_folder) | ||
|
||
if configuration.get('autobuild'): | ||
|
||
ignored_files = [] | ||
for path in configuration.get('ignore'): | ||
ignored_files.append(os.path.realpath(path)) | ||
|
||
builder = sphinx_autobuild.SphinxBuilder( | ||
outdir=build_folder, | ||
args=['-b', 'html', source_folder, build_folder]+sys.argv[1:], | ||
ignored=ignored_files | ||
) | ||
|
||
server = Server(watcher=sphinx_autobuild.LivereloadWatchdogWatcher()) | ||
server.watch(source_folder, builder) | ||
server.watch(build_folder) | ||
|
||
builder.build() | ||
|
||
server.serve(port=8000, host='0.0.0.0', root=build_folder) | ||
else: | ||
# Building once when server starts | ||
builder = sphinx_autobuild.SphinxBuilder(outdir=build_folder, args=['-b', 'html', source_folder, build_folder]+sys.argv[1:]) | ||
builder.build() | ||
|
||
sys.argv = ['nouser', '8000'] | ||
|
||
if configuration.get('credentials')['username'] is not None: | ||
auth = configuration.get('credentials')['username'] + ':' + configuration.get('credentials')['password'] | ||
key = base64.b64encode(auth.encode('utf-8')) | ||
|
||
with pushd(build_folder): | ||
http.server.test(AuthHandler, http.server.HTTPServer) | ||
else: | ||
with pushd(build_folder): | ||
Handler = http.server.SimpleHTTPRequestHandler | ||
httpd = socketserver.TCPServer(('', 8000), Handler) | ||
httpd.serve_forever() |