Add Web 2 workspace and controlled deployment updates
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
name: Web image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["v2.*"]
|
||||
pull_request:
|
||||
paths:
|
||||
- ranch_web/**
|
||||
- ranch_assistant/**
|
||||
- deploy/web/**
|
||||
- Dockerfile
|
||||
- .dockerignore
|
||||
- compose.yaml
|
||||
- .github/workflows/web-image.yml
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: web-image-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
image:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 25
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- name: Validate source version and publish tag
|
||||
id: version
|
||||
env:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
REF_TYPE: ${{ github.ref_type }}
|
||||
REF_NAME: ${{ github.ref_name }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
run: |
|
||||
python - <<'PY'
|
||||
import os
|
||||
from ranch_web import __version__
|
||||
from ranch_web.updates import current_version_key, validate_image_release
|
||||
current_version_key(__version__)
|
||||
publish = os.environ["EVENT_NAME"] == "push" and os.environ["REF_TYPE"] == "tag"
|
||||
tag = os.environ["REF_NAME"]
|
||||
if publish:
|
||||
validate_image_release(os.environ["REPOSITORY"], tag, __version__)
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
|
||||
print(f"version={__version__}", file=output)
|
||||
print(f"publish={'true' if publish else 'false'}", file=output)
|
||||
print(f"tag={tag if publish else ''}", file=output)
|
||||
PY
|
||||
- name: Install Web dependencies only
|
||||
run: python -m pip install -r ranch_web/requirements.txt
|
||||
- name: Offline updater regression
|
||||
run: python -B -m unittest ranch_web.tests.test_updates ranch_web.tests.test_web_updater -v
|
||||
- name: Build image
|
||||
env:
|
||||
WEB_VERSION: ${{ steps.version.outputs.version }}
|
||||
VCS_REF: ${{ github.sha }}
|
||||
run: docker build --build-arg "WEB_VERSION=$WEB_VERSION" --build-arg "VCS_REF=$VCS_REF" --tag ranch-web-smoke .
|
||||
- name: Offline container health, persistence permissions, and graceful stop
|
||||
run: |
|
||||
docker run --detach --name ranch-web-smoke --network none --read-only \
|
||||
--cap-drop ALL --security-opt no-new-privileges \
|
||||
--tmpfs /tmp:rw,noexec,nosuid,size=64m,mode=1777 \
|
||||
--tmpfs /data:rw,uid=10001,gid=10001,mode=0700 \
|
||||
--env RANCH_WEB_PASSWORD=ephemeral-offline-ci-only ranch-web-smoke
|
||||
for attempt in $(seq 1 35); do
|
||||
health=$(docker inspect --format '{{.State.Health.Status}}' ranch-web-smoke)
|
||||
if [ "$health" = healthy ]; then break; fi
|
||||
if [ "$health" = unhealthy ]; then exit 1; fi
|
||||
sleep 2
|
||||
done
|
||||
test "$health" = healthy
|
||||
docker exec ranch-web-smoke python -c "import importlib.util,os,pathlib; assert os.getuid()==10001; assert importlib.util.find_spec('PySide6') is None; p=pathlib.Path('/data/.permission-check'); p.write_text('ok'); assert p.read_text()=='ok'; p.unlink()"
|
||||
docker stop --time 120 ranch-web-smoke
|
||||
test "$(docker inspect --format '{{.State.ExitCode}}' ranch-web-smoke)" = 0
|
||||
- name: Remove smoke container
|
||||
if: always()
|
||||
run: docker rm --force ranch-web-smoke 2>/dev/null || true
|
||||
- name: Log in to GHCR
|
||||
if: steps.version.outputs.publish == 'true'
|
||||
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish only the exact stable 2.x tag
|
||||
if: steps.version.outputs.publish == 'true'
|
||||
env:
|
||||
PUBLISH_TAG: ${{ steps.version.outputs.tag }}
|
||||
run: |
|
||||
python -c "import os; from ranch_web.updates import stable_version; stable_version(os.environ['PUBLISH_TAG'])"
|
||||
docker tag ranch-web-smoke "ghcr.io/attilanet/myrzx_bot-web:$PUBLISH_TAG"
|
||||
docker push "ghcr.io/attilanet/myrzx_bot-web:$PUBLISH_TAG"
|
||||
Reference in New Issue
Block a user