Files
adcloud-server/.gitea/workflows/docker-deploy.yml
T
codex-bot 789ab64013
Docker test deployment / test-build-deploy (push) Successful in 4m5s
Add Docker test deployment on Gitea Actions
2026-09-16 01:27:57 +08:00

87 lines
3.8 KiB
YAML

name: Docker test deployment
on:
push:
branches: [main]
workflow_dispatch:
inputs:
deploy_port:
description: Public host port for the test API
required: false
default: '18080'
public_base_url:
description: Public HTTP URL, such as http://SERVER_IP:18080
required: false
default: ''
concurrency:
group: adcloud-server-test
cancel-in-progress: false
jobs:
test-build-deploy:
if: gitea.ref == 'refs/heads/main'
runs-on: ubuntu-latest
container:
image: docker:27-cli
timeout-minutes: 30
env:
SOURCE_SERVER: ${{ gitea.server_url }}
SOURCE_REPOSITORY: ${{ gitea.repository }}
SOURCE_REVISION: ${{ gitea.sha }}
DEPLOY_PORT: ${{ inputs.deploy_port || vars.ADCLOUD_DEPLOY_PORT || '18080' }}
PUBLIC_BASE_URL: ${{ inputs.public_base_url || vars.ADCLOUD_PUBLIC_BASE_URL || '' }}
steps:
- name: Check Docker daemon and tools
run: |
set -eu
apk add --no-cache python3 bash curl
if ! docker info --format 'Docker daemon: {{.Name}}; OS: {{.OperatingSystem}}; version: {{.ServerVersion}}'; then
echo 'Runner job cannot reach Docker. Set runner container.docker_host to the host socket and restart runner.'
exit 1
fi
docker version --format 'Client={{.Client.Version}} Server={{.Server.Version}}'
- name: Fetch the exact repository revision
env:
SOURCE_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
python3 - <<'PY'
import io, os, shutil, tarfile, tempfile, urllib.request
from pathlib import Path
server = os.environ['SOURCE_SERVER'].rstrip('/')
repo = os.environ['SOURCE_REPOSITORY']
revision = os.environ['SOURCE_REVISION']
request = urllib.request.Request(server + '/api/v1/repos/' + repo + '/archive/' + revision + '.tar.gz', headers={'Authorization': 'token ' + os.environ['SOURCE_TOKEN']})
with urllib.request.urlopen(request, timeout=60) as response:
data = response.read()
with tempfile.TemporaryDirectory() as directory:
with tarfile.open(fileobj=io.BytesIO(data), mode='r:gz') as archive:
archive.extractall(directory, filter='data')
roots = list(Path(directory).iterdir())
if len(roots) != 1 or not roots[0].is_dir():
raise RuntimeError('Unexpected repository archive structure')
shutil.copytree(roots[0], Path.cwd(), dirs_exist_ok=True)
print('Checked out exact commit:', revision)
PY
- name: Build and run the test image
run: |
set -eu
docker build --target test --tag "adcloud-server-ci:$SOURCE_REVISION-test" .
docker run --rm "adcloud-server-ci:$SOURCE_REVISION-test"
- name: Build the runtime image
run: |
docker build --target runtime --tag "adcloud-server-ci:$SOURCE_REVISION" --label "org.opencontainers.image.revision=$SOURCE_REVISION" .
- name: Deploy and verify published host port
run: |
export DEPLOY_IMAGE="adcloud-server-ci:$SOURCE_REVISION"
export DEPLOY_REPOSITORY="$SOURCE_REPOSITORY"
export DEPLOY_REVISION="$SOURCE_REVISION"
bash scripts/deploy_docker.sh
- name: Probe configured public URL
run: |
set -eu
if [ -n "$PUBLIC_BASE_URL" ]; then
case "$PUBLIC_BASE_URL" in http://*|https://*) ;; *) echo 'Invalid public URL'; exit 1 ;; esac
curl --fail --silent --show-error --connect-timeout 10 --max-time 20 "${PUBLIC_BASE_URL%/}/health"
printf '\nPublic API: %s\n' "$PUBLIC_BASE_URL"
else
echo "Host port $DEPLOY_PORT passed HTTP smoke; provide public_base_url to check public ingress."
fi