Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Build and Push Docker image
on:
pull_request:
branches:
- master
push:
branches:
- master
Expand All @@ -16,12 +19,17 @@ jobs:
run: |
docker build . --file oci_build/Dockerfile --tag xiangzhedev/upgradeall-server:latest

- name: Smoke test HTTP service
run: bash scripts/smoke-hello.sh xiangzhedev/upgradeall-server:latest

- name: Login DockerHub
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.HUB_USR }}
password: ${{ secrets.HUB_TKN }}

- name: Push to DockerHub
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
run: |
docker push xiangzhedev/upgradeall-server:latest
28 changes: 28 additions & 0 deletions scripts/smoke-hello.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

image=${1:?Usage: smoke-hello.sh IMAGE}
engine=${CONTAINER_ENGINE:-docker}
container=$("$engine" run -d --network none -e discovery_url=tcp://127.0.0.1:5256 "$image" hello)
trap '"$engine" rm -f "$container" >/dev/null' EXIT

for _ in {1..15}; do
if "$engine" exec "$container" python -c '
from urllib.request import urlopen

with urlopen("http://127.0.0.1:5255/about", timeout=2) as response:
assert response.status == 200 and b"DUpdateSystem" in response.read()
with urlopen("http://127.0.0.1:5255/server/status_check", timeout=2) as response:
assert response.status == 204
' >/dev/null 2>&1; then
echo 'HTTP smoke: /about 200, /server/status_check 204'
exit 0
fi
if [[ $("$engine" inspect -f '{{.State.Running}}' "$container") != true ]]; then
break
fi
sleep 1
done

"$engine" logs "$container" >&2
exit 1
30 changes: 14 additions & 16 deletions server/hello/web_api/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hashlib import md5
from quart import Quart, request, Request, Response
from quart import Quart, request, Response
from database.cache_manager import cache_manager


Expand All @@ -8,25 +8,23 @@ def regist_cache(app: Quart):
app.after_request(set_cache)


def check_cache_hash(path, cache_hash) -> bool:
return cache_manager.get_tmp_cache(path).decode() == cache_hash
def cache_key() -> str | None:
if request.blueprint != "update_server_page" or request.headers.get("Authorization"):
return None
return md5(request.path.encode()).hexdigest()


def check_cache():
try:
path = request.path
path_hash = md5(path.encode()).digest()
cache_hash = request.headers.get("cache_hash")
if check_cache_hash(path_hash, cache_hash):
return Request(204)
except ValueError:
return
key = cache_key()
cache_hash = request.headers.get("cache_hash")
if key and cache_hash:
cached = cache_manager.get_tmp_cache(key)
if cached is not None and cached.hex() == cache_hash:
return "", 204


async def set_cache(response: Response):
path = request.path
res_data = await response.get_data()
path_hash = md5(path.encode()).hexdigest()
cache_hash = md5(res_data).digest()
cache_manager.add_tmp_cache(path_hash, cache_hash)
key = cache_key()
if key and response.status_code == 200:
cache_manager.add_tmp_cache(key, md5(await response.get_data()).digest())
return response
4 changes: 2 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
beautifulsoup4==4.11.1
colorlog==6.6.0
pynng==0.7.1
quart==0.17.0
hypercorn==0.13.2
quart==0.20.0
hypercorn==0.18.0
peewee==3.14.10
PyMySQL==1.0.2
html5lib==1.1
Expand Down
Loading