From a9bc7466b2952de0d2533db7df7c3b231597f296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Sun, 5 May 2019 20:43:57 +0200 Subject: [PATCH] Command line dependencies and static utilities --- poc/Dockerfile | 3 ++- poc/bin/static | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 poc/bin/static diff --git a/poc/Dockerfile b/poc/Dockerfile index 29699bd..b4e5d78 100644 --- a/poc/Dockerfile +++ b/poc/Dockerfile @@ -1,4 +1,5 @@ -FROM python:3.7 +FROM python:3.7-alpine +RUN apk update && apk add bash curl coreutils file RUN pip install pipenv COPY Pipfile Pipfile.lock /tmp/ RUN cd /tmp && pipenv install --system --deploy diff --git a/poc/bin/static b/poc/bin/static new file mode 100755 index 0000000..1149bbb --- /dev/null +++ b/poc/bin/static @@ -0,0 +1,21 @@ +#!/bin/sh + +BASE="$1" +PATHNAME="$2" +REAL="$(realpath --relative-base="$BASE" "$BASE/$PATHNAME")" + +if [ ! -f "$BASE/$PATHNAME" ]; then + response /status 404 + exit +else + case $REAL in + "/"*) + response /status 403 + exit + ;; + *) + response /status 200 + response /header/Content-Type "$(python -m mimetypes "$BASE/$REAL" | awk '/type:/ {print $2; exit 0}; !/type:/ {print "application/octet-stream"}')" + response /body < "$BASE/$REAL" + esac +fi