Unverified Commit 5795f018 authored by PICHOU Kyâne's avatar PICHOU Kyâne
Browse files

Add archive container for pads

parent e53f056c
Pipeline #59244 failed with stages
in 35 seconds
export_all_html.py
README.md
FROM nginx:stable-alpine
COPY --chown=nginx config/archive.conf /etc/nginx/conf.d/default.conf
COPY --chown=nginx export /var/www/html
COPY --chown=nginx pages/index.html /var/www/html/index.html
COPY --chown=nginx pages/404.html /var/www/html/404.html
EXPOSE 80
# Archives Etherpad
Cette image Docker est un simple Nginx qui sert les pages HTML d'anciens pads exportés.
## Préparation
On récupère tout les pads au format HTML
```bash
ETHERPAD_API_KEY="WRITE_ETHERPAD_API_TOKEN_HERE" python3 export_all_html.py
```
Ce script, un peu long, va remplir le dossier `./export` avec les pages HTML à servir. Comme le volume reste assez faible, on va les intégrer directement dans l'image Docker.
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
version : "2.4"
networks:
docker_default:
external: true
services:
pad-archive:
image: registry.picasoft.net/pica-pad-archive
container_name: pad-archive
security_opt:
- no-new-privileges
mem_limit: "512m"
cpus: "0.10"
pids_limit: 1024
labels:
- "traefik.frontend.rule=Host:archive.pad.picasoft.net"
- "traefik.port=80"
- "traefik.enable=true"
restart: unless-stopped
networks:
- docker_default
#!/usr/bin/python3
# coding=utf-8
"""Export all Etherpad instance to HTML."""
# Imports
import os
import sys
import requests
# Constants
EXPORT_FOLDER = os.getenv('EXPORT_FOLDER', './export')
ETHERPAD_API = os.getenv('ETHERPAD_API', 'https://pad.picasoft.net/api/1.2.13')
ETHERPAD_API_KEY = os.getenv('ETHERPAD_API_KEY')
if not ETHERPAD_API_KEY:
print('ETHERPAD_API_KEY environment variable mus bet set')
sys.exit(-1)
def api_request(path, verb="GET", parameters={}):
"""
Send a request to Etherpad API.
"""
static_parameters = {
'apikey': ETHERPAD_API_KEY
}
try:
res = requests.request(
verb,
url=ETHERPAD_API + path,
params={**static_parameters, **parameters}
)
data = res.json()
except Exception as err:
print(err)
sys.exit(2)
return data['data']
def main():
"""Run the main function."""
try:
os.mkdir(EXPORT_FOLDER)
except FileExistsError:
pass
pads = api_request("/listAllPads")['padIDs']
for pad in pads:
if os.path.isfile(EXPORT_FOLDER + '/' + pad + '.html'):
continue
pad_obj = api_request(path="/getHTML", parameters={'padID': pad})
if not pad_obj:
print('UNABLE TO EXPORT PAD ' + pad)
continue
content = pad_obj['html']
with open(EXPORT_FOLDER + '/' + pad + '.html', 'w') as outfile:
outfile.write(content)
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment