Add Gitea Actions CI/CD to build, push, and deploy on main.
Mirrors the airports runner flow: test, publish to the Gitea registry, then pull APP_IMAGE into the z00 compose stack.
This commit is contained in:
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Deploy a pre-built APP_IMAGE to one or more AndyTranscribe directories.
|
||||
|
||||
Environment:
|
||||
APP_IMAGE Required. e.g. gitea.z00.nu/ben/andytranscribe:abc1234
|
||||
DEPLOY_PATHS Comma-separated instance directories (default: current directory)
|
||||
GIT_PULL When 1 (default), run git pull --ff-only in each directory first
|
||||
|
||||
Usage:
|
||||
APP_IMAGE=gitea.z00.nu/ben/andytranscribe:tag DEPLOY_PATHS=$HOME/andyTranscibe ./scripts/deploy-production.sh
|
||||
EOF
|
||||
}
|
||||
|
||||
IMAGE="${APP_IMAGE:-${1:-}}"
|
||||
if [[ -z "${IMAGE}" ]]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATHS_CSV="${DEPLOY_PATHS:-${2:-.}}"
|
||||
GIT_PULL="${GIT_PULL:-1}"
|
||||
IFS=',' read -r -a DIRS <<< "${PATHS_CSV}"
|
||||
|
||||
for dir in "${DIRS[@]}"; do
|
||||
dir="${dir#"${dir%%[![:space:]]*}"}"
|
||||
dir="${dir%"${dir##*[![:space:]]}"}"
|
||||
|
||||
if [[ ! -d "${dir}" ]]; then
|
||||
echo "Missing instance directory: ${dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
name="$(basename "${dir}")"
|
||||
echo "==> Deploying ${IMAGE} in ${dir}"
|
||||
|
||||
(
|
||||
cd "${dir}"
|
||||
|
||||
if [[ "${GIT_PULL}" == "1" ]] && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
git pull --ff-only
|
||||
fi
|
||||
|
||||
export APP_IMAGE="${IMAGE}"
|
||||
export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-${name,,}}"
|
||||
|
||||
compose_files=(-f docker-compose.yml)
|
||||
if [[ -f compose.z00.yaml ]]; then
|
||||
compose_files+=(-f compose.z00.yaml)
|
||||
fi
|
||||
|
||||
if grep -q '^APP_IMAGE=' .env 2>/dev/null; then
|
||||
sed -i "s|^APP_IMAGE=.*|APP_IMAGE=${IMAGE}|" .env
|
||||
else
|
||||
printf '\nAPP_IMAGE=%s\n' "${IMAGE}" >> .env
|
||||
fi
|
||||
|
||||
docker compose "${compose_files[@]}" pull app queue reverb
|
||||
docker compose "${compose_files[@]}" up -d
|
||||
docker compose "${compose_files[@]}" ps
|
||||
|
||||
app_port="$(awk -F= '/^APP_HOST_PORT=/ {print $2; exit}' .env 2>/dev/null || true)"
|
||||
app_port="${app_port:-18080}"
|
||||
health_url="http://127.0.0.1:${app_port}/up"
|
||||
echo "waiting for ${health_url}"
|
||||
ok=0
|
||||
for _ in $(seq 1 45); do
|
||||
if curl -fsS "${health_url}" >/dev/null 2>&1; then
|
||||
echo "healthy"
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
if [[ "${ok}" -ne 1 ]]; then
|
||||
echo "ERROR: health check failed for ${name}" >&2
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
done
|
||||
|
||||
echo "Deploy complete: ${IMAGE}"
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
# Idempotent bootstrap for AndyTranscribe Gitea Actions secrets on z00.
|
||||
# Requires an already-running Gitea + act_runner (see airports setup).
|
||||
set -euo pipefail
|
||||
|
||||
GITEA_DIR="${GITEA_DIR:-${HOME}/gitea}"
|
||||
REPO_OWNER="${REPO_OWNER:-ben}"
|
||||
REPO_NAME="${REPO_NAME:-AndyTranscribe}"
|
||||
REGISTRY_HOST="${REGISTRY_HOST:-gitea.z00.nu}"
|
||||
DEPLOY_PATH="${DEPLOY_PATH:-${HOME}/andyTranscibe}"
|
||||
CREDENTIALS_FILE="${GITEA_DIR}/.credentials"
|
||||
|
||||
if [[ ! -f "${CREDENTIALS_FILE}" ]]; then
|
||||
echo "Missing ${CREDENTIALS_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${CREDENTIALS_FILE}"
|
||||
|
||||
API="https://${REGISTRY_HOST}/api/v1"
|
||||
AUTH=(-u "${ADMIN_USERNAME}:${ADMIN_PASSWORD}")
|
||||
|
||||
if ! curl -fsS "${AUTH[@]}" "${API}/repos/${REPO_OWNER}/${REPO_NAME}" >/dev/null 2>&1; then
|
||||
echo "Repository ${REPO_OWNER}/${REPO_NAME} not found on ${REGISTRY_HOST}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CI_TOKEN="$(
|
||||
docker exec -u git gitea gitea admin user generate-access-token \
|
||||
-u "${ADMIN_USERNAME}" \
|
||||
-t "ci-${REPO_NAME}-$(date +%Y%m%d%H%M%S)" \
|
||||
--scopes "write:package,read:package,write:repository,read:repository" \
|
||||
--raw
|
||||
)"
|
||||
|
||||
PULL_TOKEN="$(
|
||||
docker exec -u git gitea gitea admin user generate-access-token \
|
||||
-u "${ADMIN_USERNAME}" \
|
||||
-t "pull-${REPO_NAME}-$(date +%Y%m%d%H%M%S)" \
|
||||
--scopes "read:package" \
|
||||
--raw
|
||||
)"
|
||||
|
||||
set_secret() {
|
||||
local name="$1"
|
||||
local value="$2"
|
||||
local tmp
|
||||
tmp="$(mktemp)"
|
||||
python3 -c 'import json,sys; json.dump({"data": sys.argv[1]}, open(sys.argv[2], "w"))' "${value}" "${tmp}"
|
||||
curl -fsS "${AUTH[@]}" -X PUT \
|
||||
"${API}/repos/${REPO_OWNER}/${REPO_NAME}/actions/secrets/${name}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @"${tmp}" >/dev/null
|
||||
rm -f "${tmp}"
|
||||
}
|
||||
|
||||
set_secret "REGISTRY_TOKEN" "${CI_TOKEN}"
|
||||
set_secret "DEPLOY_PATHS" "${DEPLOY_PATH}"
|
||||
|
||||
printf '%s' "${PULL_TOKEN}" | docker login "${REGISTRY_HOST}" -u "${ADMIN_USERNAME}" --password-stdin
|
||||
|
||||
REPO_LC="$(echo "${REPO_OWNER}/${REPO_NAME}" | tr '[:upper:]' '[:lower:]')"
|
||||
if [[ -f "${DEPLOY_PATH}/.env" ]]; then
|
||||
if grep -q '^APP_IMAGE=' "${DEPLOY_PATH}/.env"; then
|
||||
sed -i "s|^APP_IMAGE=.*|APP_IMAGE=${REGISTRY_HOST}/${REPO_LC}:latest|" "${DEPLOY_PATH}/.env"
|
||||
else
|
||||
printf '\nAPP_IMAGE=%s/%s:latest\n' "${REGISTRY_HOST}" "${REPO_LC}" >> "${DEPLOY_PATH}/.env"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ensure the existing host runner is up (shared with airports).
|
||||
if systemctl --user is-enabled gitea-act-runner.service >/dev/null 2>&1; then
|
||||
systemctl --user restart gitea-act-runner.service || true
|
||||
systemctl --user --no-pager --lines=5 status gitea-act-runner.service || true
|
||||
fi
|
||||
|
||||
echo "Gitea CI secrets configured for ${REGISTRY_HOST}/${REPO_OWNER}/${REPO_NAME}"
|
||||
echo "Deploy path: ${DEPLOY_PATH}"
|
||||
echo "Push to main to build, push the image, and deploy."
|
||||
Reference in New Issue
Block a user