name: Veyra CI/CD on: push: branches: [master] env: REMOTE_DIR: /home/workspace/sundynix-veyra jobs: verify: runs-on: ubuntu-latest steps: - name: Checkout exact commit from Gitea env: GITEA_TOKEN: ${{ github.token }} REPOSITORY: ${{ github.repository }} COMMIT_SHA: ${{ github.sha }} run: | set -euo pipefail curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \ "https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \ | tar -xz --strip-components=1 - name: Check App, embedded admin, Go and PostgreSQL integration run: bash deploy/check.sh deploy: needs: verify if: github.ref == 'refs/heads/master' && github.event_name == 'push' runs-on: ubuntu-latest steps: - name: Checkout verified commit from Gitea env: GITEA_TOKEN: ${{ github.token }} REPOSITORY: ${{ github.repository }} COMMIT_SHA: ${{ github.sha }} run: | set -euo pipefail curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \ "https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \ | tar -xz --strip-components=1 - name: Build and package immutable image env: COMMIT_SHA: ${{ github.sha }} run: | set -euo pipefail docker build -t "sundynix/veyra:${COMMIT_SHA}" . docker save "sundynix/veyra:${COMMIT_SHA}" | gzip > image.tar.gz sha256sum image.tar.gz > image.tar.gz.sha256 - name: Install SSH tools run: | set -eu if command -v sshpass >/dev/null && command -v ssh >/dev/null; then exit 0; fi if command -v apk >/dev/null; then apk add --no-cache sshpass openssh-client elif command -v apt-get >/dev/null; then apt-get update -qq apt-get install -y -qq --no-install-recommends sshpass openssh-client else echo 'Runner requires ssh and sshpass' >&2 exit 1 fi - name: Transfer and deploy env: SSHPASS: ${{ secrets.DEPLOY_PASSWORD }} DEPLOY_HOST: 192.168.100.132 DEPLOY_USER: root DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} VEYRA_ENV_FILE: ${{ secrets.VEYRA_ENV_FILE }} COMMIT_SHA: ${{ github.sha }} run: | set -euo pipefail : "${SSHPASS:?DEPLOY_PASSWORD is required}" : "${DEPLOY_HOST:?DEPLOY_HOST is required}" : "${DEPLOY_USER:?DEPLOY_USER is required}" : "${DEPLOY_KNOWN_HOSTS:?DEPLOY_KNOWN_HOSTS is required}" [[ "$DEPLOY_HOST" =~ ^[a-zA-Z0-9.-]+$ && "$DEPLOY_USER" =~ ^[a-zA-Z0-9_-]+$ ]] || exit 2 [[ "$COMMIT_SHA" =~ ^[0-9a-f]{40}$ ]] || exit 2 known_hosts="$(mktemp)" trap 'rm -f "$known_hosts"' EXIT printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$known_hosts" chmod 600 "$known_hosts" options=(-o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$known_hosts" -o ConnectTimeout=15) target="$DEPLOY_USER@$DEPLOY_HOST" release="$REMOTE_DIR/releases/$COMMIT_SHA" sshpass -e ssh "${options[@]}" "$target" "umask 077; mkdir -p '$release' '$REMOTE_DIR/configs'" sshpass -e scp "${options[@]}" deploy/bootstrap-config.sh "$target:$release/" # Bootstrap once via secret; never replace an existing server configuration. if [[ -n "$VEYRA_ENV_FILE" ]]; then printf '%s\n' "$VEYRA_ENV_FILE" | sshpass -e ssh "${options[@]}" "$target" \ "bash '$release/bootstrap-config.sh' '$REMOTE_DIR'" fi sshpass -e scp "${options[@]}" image.tar.gz image.tar.gz.sha256 deploy/docker-compose.yml deploy/release.sh "$target:$release/" sshpass -e ssh "${options[@]}" "$target" "bash '$release/release.sh' '$REMOTE_DIR' '$COMMIT_SHA'"