feat: modernize application — source, platform artifacts, CI/CD
Some checks failed
Build and Publish TechDocs / build-and-publish (push) Successful in 1m3s
Build and Push to ACR / Build and Push (push) Failing after 3m8s

- chore: ingest source code

108 files from https://github.com/spring-projects/spring-petclinic
- feat: add platform deployment artifacts
- feat: add CI/CD workflow automation
This commit is contained in:
2026-04-16 18:20:27 +00:00
parent 1a98aae37d
commit d85a368833
14 changed files with 873 additions and 466 deletions

View File

@@ -12,102 +12,104 @@ on:
required: true
default: 'dev'
type: choice
options:
- dev
- staging
- prod
options: [dev, staging, production]
env:
HUMANITEC_ORG: skillful-wild-chicken-2617
PROJECT_ID: demo-fss-1
HUMANITEC_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
HUMANITEC_API_PREFIX: https://api.humanitec.dev
PROJECT_ID: demo-fss-1
DEFAULT_ENV_ID: dev
ACR_REGISTRY: bstagecjotdevacr.azurecr.io
jobs:
guard:
name: Platform guard
runs-on: ubuntu-latest
outputs:
ready: ${{ steps.check.outputs.ready }}
steps:
- uses: actions/checkout@v4
- name: Check platform initialized
id: check
run: |
if [ -f ".platform/initialized.md" ]; then
echo "ready=true" >> $GITHUB_OUTPUT
else
echo "ready=false" >> $GITHUB_OUTPUT
echo "Skipping: .platform/initialized.md not found"
fi
deploy:
name: Deploy to Humanitec v2
needs: guard
if: >-
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && needs.guard.outputs.ready == 'true') ||
(github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Install dependencies
run: apt-get update -qq && apt-get install -y jq
- name: Install hctl CLI
run: |
if ! command -v jq &>/dev/null; then
apt-get update -qq && apt-get install -y -qq jq
fi
HCTL_VERSION=$(curl -s https://api.github.com/repos/humanitec/hctl/releases/latest | jq -r '.tag_name')
mkdir -p /tmp/hctl-install
curl -sLo /tmp/hctl-install/hctl.tar.gz "https://github.com/humanitec/hctl/releases/download/${HCTL_VERSION}/hctl_${HCTL_VERSION#v}_linux_amd64.tar.gz"
tar -xzf /tmp/hctl-install/hctl.tar.gz -C /tmp/hctl-install
install -m 755 /tmp/hctl-install/hctl /usr/local/bin/hctl
hctl --version
- name: Derive environment
- name: Ensure Humanitec project and environment exist
env:
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
run: |
DISPATCH_ENV="${{ github.event.inputs.environment }}"
if [ -n "$DISPATCH_ENV" ]; then
ENV_ID="$DISPATCH_ENV"
else
# workflow_run: derive from upstream build-push branch
BRANCH="${{ github.event.workflow_run.head_branch }}"
BRANCH="${BRANCH:-${GITHUB_REF_NAME}}"
case "$BRANCH" in
dev) ENV_ID="dev" ;;
staging) ENV_ID="staging" ;;
prod) ENV_ID="prod" ;;
*) ENV_ID="dev" ;;
esac
fi
echo "ENV_ID=$ENV_ID" >> $GITHUB_ENV
echo "Deploying to environment: $ENV_ID"
ENV_ID="${DISPATCH_ENV:-$DEFAULT_ENV_ID}"
# Create project if it doesn't exist (hctl exits 0 if already exists)
hctl create project "$PROJECT_ID" --set display_name="demo-fss-1" 2>&1 | grep -v "already exists" || true
# Create environment if it doesn't exist
hctl create environment "$PROJECT_ID" "$ENV_ID" --set env_type_id=development --set display_name="Development" 2>&1 | grep -v "already exists" || true
echo "✓ Project $PROJECT_ID / env $ENV_ID ready"
- name: Deploy with Score
env:
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
run: |
MAX_RETRIES=8
RETRY_DELAY=30
attempt=0
until hctl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml --no-prompt; do
attempt=$((attempt + 1))
if [[ $attempt -ge $MAX_RETRIES ]]; then
echo "All $MAX_RETRIES deploy attempts failed."
exit 1
DISPATCH_ENV="${{ github.event.inputs.environment }}"
ENV_ID="${DISPATCH_ENV:-$DEFAULT_ENV_ID}"
DEFAULT_IMAGE="$ACR_REGISTRY/demo-fss-1:latest"
# Pre-flight: wait for any deployment from a prior run to finish before calling hctl.
# hctl refuses to start a new deployment while one is still executing.
echo "Pre-flight: checking for in-progress deployments..."
MAX_PREFLIGHT=420
PREFLIGHT_WAITED=0
while [ $PREFLIGHT_WAITED -lt $MAX_PREFLIGHT ]; do
PREFLIGHT_STATUS=$(curl -sf -H "Authorization: Bearer $HUMANITEC_AUTH_TOKEN" "https://api.humanitec.dev/orgs/$HUMANITEC_ORG/last-deployments?env_id=$ENV_ID&project_id=$PROJECT_ID&state_change_only=true" | jq -r '.items[0].status // "none"' 2>/dev/null || echo "none")
if [ "$PREFLIGHT_STATUS" != "in progress" ] && [ "$PREFLIGHT_STATUS" != "pending" ] && [ "$PREFLIGHT_STATUS" != "executing" ]; then
echo "Pre-flight passed (status=$PREFLIGHT_STATUS). Proceeding."
break
fi
echo "Attempt $attempt failed. Retrying in ${RETRY_DELAY}s..."
sleep $RETRY_DELAY
echo " Prior deployment still running ($PREFLIGHT_WAITED s elapsed, status=$PREFLIGHT_STATUS)..."
sleep 15
PREFLIGHT_WAITED=$((PREFLIGHT_WAITED + 15))
done
echo "Deployment successful!"
- name: Deployment summary
if: always()
run: |
SHORT_SHA="${GITHUB_SHA:0:7}"
echo "## Deployment Result" >> $GITHUB_STEP_SUMMARY
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| Project | \`$PROJECT_ID\` |" >> $GITHUB_STEP_SUMMARY
echo "| Environment | \`$ENV_ID\` |" >> $GITHUB_STEP_SUMMARY
echo "| Commit | \`$SHORT_SHA\` |" >> $GITHUB_STEP_SUMMARY
echo "[View in Humanitec Console](https://console.humanitec.dev/orgs/$HUMANITEC_ORG/projects/$PROJECT_ID/environments/$ENV_ID)" >> $GITHUB_STEP_SUMMARY
# First deploy — provisions all resources. On a brand-new Humanitec project the
# dns-k8s-ingress Terraform module runs before the K8s Service exists, so the
# ingress backend port falls back to 3000. A second deploy (below) corrects it
# once the Service is up, which is essential for Java/Python apps on port 8080.
HCTL_EXIT=0
timeout 300 hctl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml --no-prompt --default-image "$DEFAULT_IMAGE" || HCTL_EXIT=$?
if [ "$HCTL_EXIT" -eq 0 ]; then
echo " First deployment complete for demo-fss-1 to $ENV_ID"
elif [ "$HCTL_EXIT" -eq 124 ]; then
echo "✓ First deployment submitted (polling timed out — waiting for K8s to settle)"
else
echo "✗ hctl failed with exit code $HCTL_EXIT"
exit $HCTL_EXIT
fi
# Poll Humanitec API until the first deployment is no longer in-progress before
# re-deploying. A flat sleep is unreliable — Terraform DNS modules can take 4-6 min.
echo "Waiting for first deployment to finish (polling Humanitec API)..."
MAX_WAIT=360
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
DEPLOY_STATUS=$(curl -sf -H "Authorization: Bearer $HUMANITEC_AUTH_TOKEN" "https://api.humanitec.dev/orgs/$HUMANITEC_ORG/last-deployments?env_id=$ENV_ID&project_id=$PROJECT_ID&state_change_only=true" | jq -r '.items[0].status // "unknown"' 2>/dev/null || echo "unknown")
if [ "$DEPLOY_STATUS" != "in progress" ] && [ "$DEPLOY_STATUS" != "pending" ] && [ "$DEPLOY_STATUS" != "executing" ]; then
echo "First deployment finished with status: $DEPLOY_STATUS"
break
fi
echo " Still running ($WAITED s elapsed, status=$DEPLOY_STATUS)..."
sleep 15
WAITED=$((WAITED + 15))
done
if [ $WAITED -ge $MAX_WAIT ]; then
echo "Warning: first deployment still running after $MAX_WAIT s — proceeding anyway"
fi
# Second deploy — dns module now reads the real K8s Service port, fixing the ingress
HCTL_EXIT2=0
timeout 120 hctl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml --no-prompt --default-image "$DEFAULT_IMAGE" || HCTL_EXIT2=$?
if [ "$HCTL_EXIT2" -eq 0 ]; then
echo "✓ Deployment finalised for demo-fss-1 to $ENV_ID"
elif [ "$HCTL_EXIT2" -eq 124 ]; then
echo "✓ Second deployment submitted for demo-fss-1 to $ENV_ID (polling timed out)"
else
echo "✗ Second hctl deploy failed with exit code $HCTL_EXIT2"
exit $HCTL_EXIT2
fi