Compare commits
No commits in common. "03df8bbb65946bfa90e7ad458ba11f5cff30147e" and "2838efa0c256fb39126f4e0f0d19560d57c83abd" have entirely different histories.
03df8bbb65
...
2838efa0c2
7 changed files with 12 additions and 264 deletions
102
Dockerfile
102
Dockerfile
|
|
@ -1,57 +1,9 @@
|
||||||
ARG NODE_VERSION=24
|
|
||||||
ARG PYTHON_VERSION=3.14-slim
|
|
||||||
|
|
||||||
#############
|
|
||||||
# build api #
|
|
||||||
#############
|
|
||||||
|
|
||||||
ARG PYTHON_VERSION
|
|
||||||
FROM python:${PYTHON_VERSION} AS build-api
|
|
||||||
|
|
||||||
# env setup
|
|
||||||
WORKDIR /usr/local/src/advent22_api
|
|
||||||
ENV \
|
|
||||||
PATH="/root/.local/bin:${PATH}"
|
|
||||||
|
|
||||||
# install poetry with export plugin
|
|
||||||
RUN set -ex; \
|
|
||||||
\
|
|
||||||
python -m pip --no-cache-dir install --upgrade pip wheel; \
|
|
||||||
\
|
|
||||||
apt-get update; apt-get install --yes --no-install-recommends \
|
|
||||||
curl \
|
|
||||||
; rm -rf /var/lib/apt/lists/*; \
|
|
||||||
\
|
|
||||||
curl -sSL https://install.python-poetry.org | python3 -; \
|
|
||||||
poetry self add poetry-plugin-export;
|
|
||||||
|
|
||||||
# build dependency wheels
|
|
||||||
COPY api/pyproject.toml api/poetry.lock ./
|
|
||||||
RUN set -ex; \
|
|
||||||
\
|
|
||||||
# # buildtime dependencies
|
|
||||||
# apt-get update; apt-get install --yes --no-install-recommends \
|
|
||||||
# build-essential \
|
|
||||||
# ; rm -rf /var/lib/apt/lists/*; \
|
|
||||||
\
|
|
||||||
# generate requirements.txt
|
|
||||||
poetry export \
|
|
||||||
--format requirements.txt \
|
|
||||||
--output requirements.txt; \
|
|
||||||
\
|
|
||||||
python3 -m pip --no-cache-dir wheel \
|
|
||||||
--wheel-dir ./dist \
|
|
||||||
--requirement requirements.txt;
|
|
||||||
|
|
||||||
# build advent22_api wheel
|
|
||||||
COPY api ./
|
|
||||||
RUN poetry build --format wheel --output ./dist
|
|
||||||
|
|
||||||
############
|
############
|
||||||
# build ui #
|
# build ui #
|
||||||
############
|
############
|
||||||
|
|
||||||
ARG NODE_VERSION
|
ARG NODE_VERSION=18.18
|
||||||
|
ARG PYTHON_VERSION=3.11-slim
|
||||||
FROM node:${NODE_VERSION} AS build-ui
|
FROM node:${NODE_VERSION} AS build-ui
|
||||||
|
|
||||||
# env setup
|
# env setup
|
||||||
|
|
@ -59,68 +11,34 @@ WORKDIR /usr/local/src/advent22_ui
|
||||||
|
|
||||||
# install advent22_ui dependencies
|
# install advent22_ui dependencies
|
||||||
COPY ui/package*.json ui/yarn*.lock ./
|
COPY ui/package*.json ui/yarn*.lock ./
|
||||||
RUN set -ex; \
|
RUN yarn install --production false
|
||||||
corepack enable; \
|
|
||||||
yarn install;
|
|
||||||
|
|
||||||
# copy and build advent22_ui
|
# copy and build advent22_ui
|
||||||
COPY ui ./
|
COPY ui ./
|
||||||
RUN set -ex; \
|
RUN yarn build --dest /tmp/advent22_ui/html
|
||||||
yarn dlx update-browserslist-db@latest; \
|
|
||||||
yarn build --dest /tmp/advent22_ui/html; \
|
|
||||||
# exclude webpack-bundle-analyzer output
|
|
||||||
rm -f /tmp/advent22_ui/html/report.html;
|
|
||||||
|
|
||||||
######################
|
|
||||||
# python preparation #
|
|
||||||
######################
|
|
||||||
|
|
||||||
ARG PYTHON_VERSION
|
|
||||||
FROM python:${PYTHON_VERSION} AS uvicorn-gunicorn
|
|
||||||
|
|
||||||
# where credit is due ...
|
|
||||||
LABEL maintainer="Sebastián Ramirez <tiangolo@gmail.com>"
|
|
||||||
WORKDIR /usr/local/share/uvicorn-gunicorn
|
|
||||||
|
|
||||||
# install uvicorn-gunicorn
|
|
||||||
COPY ./scripts/mini-tiangolo ./
|
|
||||||
|
|
||||||
RUN set -ex; \
|
|
||||||
chmod +x start.sh; \
|
|
||||||
python3 -m pip --no-cache-dir install gunicorn;
|
|
||||||
|
|
||||||
CMD ["/usr/local/share/uvicorn-gunicorn/start.sh"]
|
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# web app #
|
# web app #
|
||||||
###########
|
###########
|
||||||
|
|
||||||
FROM uvicorn-gunicorn AS production
|
ARG PYTHON_VERSION
|
||||||
|
FROM tiangolo/uvicorn-gunicorn:python${PYTHON_VERSION} AS production
|
||||||
|
|
||||||
# env setup
|
# env setup
|
||||||
|
WORKDIR /usr/local/src/advent22_api
|
||||||
ENV \
|
ENV \
|
||||||
PRODUCTION_MODE="true" \
|
PRODUCTION_MODE="true" \
|
||||||
PORT="8000" \
|
PORT="8000" \
|
||||||
MODULE_NAME="advent22_api.app"
|
MODULE_NAME="advent22_api.app"
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
WORKDIR /opt/advent22
|
# install advent22_api
|
||||||
VOLUME [ "/opt/advent22" ]
|
COPY api ./
|
||||||
|
|
||||||
COPY --from=build-api /usr/local/src/advent22_api/dist /usr/local/share/advent22_api.dist
|
|
||||||
RUN set -ex; \
|
RUN set -ex; \
|
||||||
# remove example app
|
# remove example app
|
||||||
rm -rf /app; \
|
rm -rf /app; \
|
||||||
\
|
\
|
||||||
# # runtime dependencies
|
python -m pip --no-cache-dir install ./
|
||||||
# apt-get update; apt-get install --yes --no-install-recommends \
|
|
||||||
# ; rm -rf /var/lib/apt/lists/*; \
|
|
||||||
\
|
|
||||||
# install advent22_api wheels
|
|
||||||
python3 -m pip --no-cache-dir install --no-deps /usr/local/share/advent22_api.dist/*.whl; \
|
|
||||||
\
|
|
||||||
# prepare data directory
|
|
||||||
chown nobody:nogroup ./
|
|
||||||
|
|
||||||
# add prepared advent22_ui
|
# add prepared advent22_ui
|
||||||
COPY --from=build-ui /tmp/advent22_ui /usr/local/share/advent22_ui
|
COPY --from=build-ui /tmp/advent22_ui /usr/local/share/advent22_ui
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
script="$( readlink -f "${0}" )"
|
|
||||||
script_dir="$( dirname "${script}" )"
|
|
||||||
|
|
||||||
git rev-parse --abbrev-ref HEAD | grep -E '^develop$|^feature/' >/dev/null \
|
|
||||||
&& git_status="developing"
|
|
||||||
git rev-parse --abbrev-ref HEAD | grep -E '^release/|^hotfix/' >/dev/null \
|
|
||||||
&& git_status="releasing"
|
|
||||||
git rev-parse --abbrev-ref HEAD | grep -E '^master$' >/dev/null \
|
|
||||||
&& git_status="released"
|
|
||||||
|
|
||||||
|
|
||||||
if [ "${git_status}" = "developing" ]; then
|
|
||||||
echo "Status: Developing"
|
|
||||||
# => version from most recent tag
|
|
||||||
git_version="$( \
|
|
||||||
git describe --tags --abbrev=0 \
|
|
||||||
| sed -E 's/^v[^0-9]*((0|[1-9][0-9]*)[0-9\.]*[0-9]).*$/\1/'
|
|
||||||
)"
|
|
||||||
elif [ "${git_status}" = "releasing" ]; then
|
|
||||||
echo "Status: Releasing"
|
|
||||||
# => version from releasing branch
|
|
||||||
git_version="$( \
|
|
||||||
git rev-parse --abbrev-ref HEAD \
|
|
||||||
| cut -d '/' -f 2
|
|
||||||
)"
|
|
||||||
elif [ "${git_status}" = "released" ]; then
|
|
||||||
echo "Status: Released"
|
|
||||||
# => version from current tag
|
|
||||||
git_version="$( \
|
|
||||||
git describe --tags \
|
|
||||||
| sed -E 's/^v[^0-9]*((0|[1-9][0-9]*)[0-9\.]*[0-9])$/\1/'
|
|
||||||
)"
|
|
||||||
else
|
|
||||||
echo "ERROR: Invalid git branch"
|
|
||||||
echo "ERROR: Chores cannot be run on '$( git rev-parse --abbrev-ref HEAD )'!"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
api_version="$( \
|
|
||||||
grep '^version' "${script_dir}/../api/pyproject.toml" \
|
|
||||||
| sed -E 's/^version[^0-9]*((0|[1-9][0-9]*)[0-9\.]*[0-9]).*$/\1/'
|
|
||||||
)"
|
|
||||||
|
|
||||||
ui_version="$( \
|
|
||||||
grep '"version":' "${script_dir}/../ui/package.json" \
|
|
||||||
| sed -E 's/.*"version":[^0-9]*((0|[1-9][0-9]*)[0-9\.]*[0-9]).*$/\1/'
|
|
||||||
)"
|
|
||||||
|
|
||||||
if [ "${git_version}" = "${api_version}" ] \
|
|
||||||
&& [ "${git_version}" = "${ui_version}" ]; then
|
|
||||||
mark="✅️"
|
|
||||||
else
|
|
||||||
mark="❌️"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "git: ${git_version}, api: ${api_version}, ui: ${ui_version}"
|
|
||||||
echo ">>>>> RESULT: ${mark} <<<<<"
|
|
||||||
|
|
||||||
[ "${mark}" = "✅️" ] || exit 1
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
import json
|
|
||||||
import multiprocessing
|
|
||||||
import os
|
|
||||||
|
|
||||||
workers_per_core_str = os.getenv("WORKERS_PER_CORE", "1")
|
|
||||||
max_workers_str = os.getenv("MAX_WORKERS")
|
|
||||||
use_max_workers = None
|
|
||||||
if max_workers_str:
|
|
||||||
use_max_workers = int(max_workers_str)
|
|
||||||
web_concurrency_str = os.getenv("WEB_CONCURRENCY", None)
|
|
||||||
|
|
||||||
host = os.getenv("HOST", "0.0.0.0")
|
|
||||||
port = os.getenv("PORT", "80")
|
|
||||||
bind_env = os.getenv("BIND", None)
|
|
||||||
use_loglevel = os.getenv("LOG_LEVEL", "info")
|
|
||||||
if bind_env:
|
|
||||||
use_bind = bind_env
|
|
||||||
else:
|
|
||||||
use_bind = f"{host}:{port}"
|
|
||||||
|
|
||||||
cores = multiprocessing.cpu_count()
|
|
||||||
workers_per_core = float(workers_per_core_str)
|
|
||||||
default_web_concurrency = workers_per_core * cores
|
|
||||||
if web_concurrency_str:
|
|
||||||
web_concurrency = int(web_concurrency_str)
|
|
||||||
assert web_concurrency > 0
|
|
||||||
else:
|
|
||||||
web_concurrency = max(int(default_web_concurrency), 2)
|
|
||||||
if use_max_workers:
|
|
||||||
web_concurrency = min(web_concurrency, use_max_workers)
|
|
||||||
accesslog_var = os.getenv("ACCESS_LOG", "-")
|
|
||||||
use_accesslog = accesslog_var or None
|
|
||||||
errorlog_var = os.getenv("ERROR_LOG", "-")
|
|
||||||
use_errorlog = errorlog_var or None
|
|
||||||
graceful_timeout_str = os.getenv("GRACEFUL_TIMEOUT", "120")
|
|
||||||
timeout_str = os.getenv("TIMEOUT", "120")
|
|
||||||
keepalive_str = os.getenv("KEEP_ALIVE", "5")
|
|
||||||
|
|
||||||
# Gunicorn config variables
|
|
||||||
loglevel = use_loglevel
|
|
||||||
workers = web_concurrency
|
|
||||||
bind = use_bind
|
|
||||||
errorlog = use_errorlog
|
|
||||||
worker_tmp_dir = "/dev/shm"
|
|
||||||
accesslog = use_accesslog
|
|
||||||
graceful_timeout = int(graceful_timeout_str)
|
|
||||||
timeout = int(timeout_str)
|
|
||||||
keepalive = int(keepalive_str)
|
|
||||||
|
|
||||||
|
|
||||||
# For debugging and testing
|
|
||||||
log_data = {
|
|
||||||
"loglevel": loglevel,
|
|
||||||
"workers": workers,
|
|
||||||
"bind": bind,
|
|
||||||
"graceful_timeout": graceful_timeout,
|
|
||||||
"timeout": timeout,
|
|
||||||
"keepalive": keepalive,
|
|
||||||
"errorlog": errorlog,
|
|
||||||
"accesslog": accesslog,
|
|
||||||
# Additional, non-gunicorn variables
|
|
||||||
"workers_per_core": workers_per_core,
|
|
||||||
"use_max_workers": use_max_workers,
|
|
||||||
"host": host,
|
|
||||||
"port": port,
|
|
||||||
}
|
|
||||||
print(json.dumps(log_data))
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
MODULE_NAME=${MODULE_NAME:-"app.main"}
|
|
||||||
VARIABLE_NAME=${VARIABLE_NAME:-"app"}
|
|
||||||
export APP_MODULE="${APP_MODULE:-"$MODULE_NAME:$VARIABLE_NAME"}"
|
|
||||||
export GUNICORN_CONF="${GUNICORN_CONF:-"/usr/local/share/uvicorn-gunicorn/gunicorn_conf.py"}"
|
|
||||||
export WORKER_CLASS="${WORKER_CLASS:-"uvicorn.workers.UvicornWorker"}"
|
|
||||||
|
|
||||||
if [ -f "${PRE_START_PATH}" ] ; then
|
|
||||||
echo "Running script ${PRE_START_PATH}"
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
. "${PRE_START_PATH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start Gunicorn
|
|
||||||
exec gunicorn \
|
|
||||||
-k "${WORKER_CLASS}" \
|
|
||||||
-c "${GUNICORN_CONF}" \
|
|
||||||
"${APP_MODULE}"
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
script="$( readlink -f "${0}" )"
|
|
||||||
script_dir="$( dirname "${script}" )"
|
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
. "${script_dir}/check_version"
|
|
||||||
|
|
||||||
# vars defined in `check_version` script
|
|
||||||
# shellcheck disable=SC2154
|
|
||||||
if [ "${git_status}" = "releasing" ] || [ "${git_status}" = "released" ]; then
|
|
||||||
# shellcheck disable=SC2154
|
|
||||||
image_tag="${git_version}"
|
|
||||||
else
|
|
||||||
image_tag="latest"
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker buildx build \
|
|
||||||
--pull --push \
|
|
||||||
--tag "code.lenaisten.de/lenaisten/advent22:${image_tag}" \
|
|
||||||
--platform "linux/amd64" \
|
|
||||||
"${script_dir}/.."
|
|
||||||
|
|
@ -46,7 +46,7 @@ export class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get creds(): AxiosBasicCredentials {
|
public static get creds(): AxiosBasicCredentials {
|
||||||
const stored_auth = JSON.parse(localStorage.getItem(this.creds_key) ?? "null");
|
const stored_auth = JSON.parse(localStorage.getItem(this.creds_key) ?? "");
|
||||||
if (
|
if (
|
||||||
stored_auth !== null &&
|
stored_auth !== null &&
|
||||||
Object.hasOwn(stored_auth, "username") &&
|
Object.hasOwn(stored_auth, "username") &&
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ const webpack = require("webpack");
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
transpileDependencies: true,
|
transpileDependencies: true,
|
||||||
devServer: {
|
devServer: {
|
||||||
host: "127.0.0.1",
|
host: "0.0.0.0",
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
index: {
|
index: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue