Skip to content

Commit

Permalink
Merge pull request #25 from cmason3/23.9.1
Browse files Browse the repository at this point in the history
23.9.1
  • Loading branch information
cmason3 authored Sep 27, 2023
2 parents 58946e7 + ee3b211 commit 3492e7e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
20 changes: 8 additions & 12 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
FROM docker.io/library/python:3.11-slim
FROM docker.io/library/python:3.11-slim AS BUILD

ARG BRANCH="main"

ENV PATH ${PATH}:/opt/jinjafx/.local/bin

RUN set -eux; \

apt-get update; \
apt-get install -y --no-install-recommends git; \

groupadd -g 99 -r jinjafx; \
useradd -m jinjafx -u 99 -g 99 -d /opt/jinjafx -k /dev/null; \
python3 -m venv /opt/jinjafx; \
/opt/jinjafx/bin/python3 -m pip install --upgrade git+https://github.com/cmason3/jinjafx_server.git@${BRANCH} lxml; \
/opt/jinjafx/bin/python3 -m pip uninstall -y pip

# runuser -u jinjafx -- python3 -m pip --disable-pip-version-check --no-cache-dir install --user jinjafx-server
runuser -u jinjafx -- python3 -m pip --disable-pip-version-check --no-cache-dir install --user git+https://github.com/cmason3/jinjafx_server.git@${BRANCH} lxml; \

apt-get purge -y --auto-remove git; \
rm -rf /var/lib/apt/lists/*
FROM docker.io/library/python:3.11-slim

USER jinjafx
COPY --from=BUILD --chown=99:99 /opt/jinjafx /opt/jinjafx

WORKDIR /opt/jinjafx
USER 99:99

ENTRYPOINT [ "python3", "-u", ".local/bin/jinjafx_server", "-s", "-l", "0.0.0.0", "-p", "8080" ]
ENTRYPOINT [ "/opt/jinjafx/bin/python3", "-u", "-m", "jinjafx_server", "-s", "-l", "0.0.0.0", "-p", "8080" ]
27 changes: 27 additions & 0 deletions docker/Dockerfile.SCRATCH
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM docker.io/library/python:3.11-slim AS BUILD

ARG BRANCH="main"

RUN set -eux; \

apt-get update; \
apt-get install -y --no-install-recommends git; \

python3 -m venv --copies /opt/jinjafx; \
/opt/jinjafx/bin/python3 -m pip install --upgrade git+https://github.com/cmason3/jinjafx_server.git@${BRANCH} lxml; \
/opt/jinjafx/bin/python3 -m pip uninstall -y pip


FROM scratch

ENV LD_LIBRARY_PATH=/usr/local/lib

COPY --from=BUILD /usr/local/lib/python3.11 /usr/local/lib/python3.11
COPY --from=BUILD /usr/local/lib/libpython3* /usr/local/lib/
COPY --from=BUILD /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu
COPY --from=BUILD /lib64 /lib64
COPY --from=BUILD --chown=99:99 /opt/jinjafx /opt/jinjafx

USER 99:99

ENTRYPOINT [ "/opt/jinjafx/bin/python3", "-u", "-m", "jinjafx_server", "-s", "-l", "0.0.0.0", "-p", "8080" ]
6 changes: 3 additions & 3 deletions jinjafx_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import re, argparse, hashlib, traceback, glob, hmac, uuid, struct, binascii, gzip, requests, ctypes
import cmarkgfm, emoji

__version__ = '23.9.0'
__version__ = '23.9.1'

llock = threading.RLock()
rlock = threading.RLock()
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def aws_s3_put(s3_url, fname, content, ctype):
'Content-Type': ctype,
'Content-Encoding': 'gzip',
'x-amz-content-sha256': hashlib.sha256(content).hexdigest(),
'x-amz-date': datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')
'x-amz-date': datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
}
headers = aws_s3_authorization('PUT', fname, s3_url.split('.')[2], headers)
return requests.put('https://' + s3_url + '/' + fname, headers=headers, data=content)
Expand All @@ -1082,7 +1082,7 @@ def aws_s3_get(s3_url, fname):
'Host': s3_url,
'Accept-Encoding': 'gzip',
'x-amz-content-sha256': hashlib.sha256(b'').hexdigest(),
'x-amz-date': datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')
'x-amz-date': datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
}
headers = aws_s3_authorization('GET', fname, s3_url.split('.')[2], headers)
return requests.get('https://' + s3_url + '/' + fname, headers=headers)
Expand Down
21 changes: 21 additions & 0 deletions jinjafx_server/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

# JinjaFx Server - Jinja2 Templating Tool
# Copyright (c) 2020-2023 Chris Mason <chris@netnix.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import sys, jinjafx_server

sys.argv[0] = 'jinjafx_server'
sys.exit(jinjafx_server.main())

0 comments on commit 3492e7e

Please sign in to comment.