Compare commits
3 Commits
fd7b232efb
...
e7319c3f1a
Author | SHA1 | Date |
---|---|---|
qvalentin | e7319c3f1a | |
qvalentin | ed324581ab | |
qvalentin | 0d2aedee88 |
|
@ -0,0 +1,59 @@
|
||||||
|
name: Docker
|
||||||
|
|
||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ $default-branch ]
|
||||||
|
# Publish semver tags as releases.
|
||||||
|
tags: [ 'v*.*.*' ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Use docker.io for Docker Hub if empty
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
# github.repository as <account>/<repo>
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Login against a Docker registry except on PR
|
||||||
|
# https://github.com/docker/login-action
|
||||||
|
- name: Log into registry ${{ env.REGISTRY }}
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Extract metadata (tags, labels) for Docker
|
||||||
|
# https://github.com/docker/metadata-action
|
||||||
|
- name: Extract Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
# Build and push Docker image with Buildx (don't push on PR)
|
||||||
|
# https://github.com/docker/build-push-action
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
87
server.py
87
server.py
|
@ -1,87 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""A meaningful docstring
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import re
|
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
||||||
from urllib.parse import urlparse, parse_qs
|
|
||||||
|
|
||||||
import requests
|
|
||||||
from jinja2 import Template
|
|
||||||
from pygments import highlight
|
|
||||||
from pygments.formatters.html import HtmlFormatter
|
|
||||||
from pygments.lexers import guess_lexer_for_filename
|
|
||||||
|
|
||||||
|
|
||||||
def render_gist_js(code, path):
|
|
||||||
template = Template("""script = document.querySelector('script[src$="{{ path }}"]')
|
|
||||||
script.insertAdjacentHTML( 'afterend',{{ code|tojson }} );""")
|
|
||||||
|
|
||||||
return template.render(code=str(code), path=path)
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPRequestHandler(BaseHTTPRequestHandler):
|
|
||||||
|
|
||||||
def do_GET(self):
|
|
||||||
if self.path == "/":
|
|
||||||
self.send_response(200, "running")
|
|
||||||
elif re.search("https://github.com/.*/.*", self.path):
|
|
||||||
github_raw_url = self.path[1:].replace("https://github.com/", "https://raw.githubusercontent.com/").replace("/blob/", "/")
|
|
||||||
|
|
||||||
response = requests.get(url=github_raw_url)
|
|
||||||
code = response.content.decode('UTF-8')
|
|
||||||
|
|
||||||
parsed_url = urlparse(self.path)
|
|
||||||
params = parse_qs(parsed_url.query)
|
|
||||||
|
|
||||||
style = "default"
|
|
||||||
if 'style' in params:
|
|
||||||
style = params['style'][0]
|
|
||||||
|
|
||||||
if 'slice' in params:
|
|
||||||
slice_value = params['slice'][0].split(":")
|
|
||||||
from_ = int(slice_value[0])
|
|
||||||
to_ = int(slice_value[1])
|
|
||||||
lines = str(code).splitlines()
|
|
||||||
selected_lines = lines[from_:to_]
|
|
||||||
|
|
||||||
code = "\n".join(selected_lines)
|
|
||||||
|
|
||||||
filename = parsed_url.path.split('/')[-1:][0]
|
|
||||||
lexer = guess_lexer_for_filename(filename, response.content)
|
|
||||||
|
|
||||||
formatter = HtmlFormatter(linenos=False, cssclass="gist-it-highlight", style=style)
|
|
||||||
|
|
||||||
highlighted_code = highlight(code, lexer, formatter)
|
|
||||||
css = formatter.get_style_defs('.gist-it-highlight')
|
|
||||||
|
|
||||||
result = highlighted_code + f"<style> {css}</style>"
|
|
||||||
|
|
||||||
js_rendered = render_gist_js(result, self.path)
|
|
||||||
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header('Content-Type', 'text/html')
|
|
||||||
self.end_headers()
|
|
||||||
self.wfile.write(js_rendered.encode('utf8'))
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.send_response(404)
|
|
||||||
|
|
||||||
self.end_headers()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description='HTTP Server')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
server = HTTPServer(("0.0.0.0", 4876), HTTPRequestHandler)
|
|
||||||
print('HTTP Server Running on localhost:4876')
|
|
||||||
server.serve_forever()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
|
@ -78,8 +78,8 @@ def main():
|
||||||
parser = argparse.ArgumentParser(description='HTTP Server')
|
parser = argparse.ArgumentParser(description='HTTP Server')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
server = HTTPServer(("localhost", 4876), HTTPRequestHandler)
|
server = HTTPServer(("0.0.0.0", 4876), HTTPRequestHandler)
|
||||||
print('HTTP Server Running...........')
|
print('HTTP Server Running on localhost:4876')
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue