Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a99a8a28c6 | |||
| 6ae4766581 | |||
| bcac84f2fd | |||
| db9d6daebb | |||
| ba16e9e4eb | |||
| 6463dad6d7 | |||
| 21a6ef7ab1 | |||
| 84978784fe | |||
| f58497f5e8 | |||
| fa57a152e4 | |||
| a0cdf377f6 | |||
| 028fd748a6 | |||
| 7f53e2c303 | |||
| ec22d49039 | |||
| 13493de7b2 | |||
| 47df5a8017 | |||
| e84e37c9f8 | |||
| 9105675591 | |||
| 1385afcca6 | |||
| 5c9df73a66 | |||
| 86e73d87d3 |
@@ -3,18 +3,19 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- feature/gitops
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
name: Config load
|
||||
name: Load example-gitea-env.conf to pipeline env
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/example-gitea-env.conf
|
||||
|
||||
check-version:
|
||||
name: Latest versio
|
||||
name: Check existing artifact
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/check-version.yml@main
|
||||
secrets: inherit
|
||||
@@ -50,8 +51,8 @@ jobs:
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
|
||||
docker-gitops:
|
||||
name: GitOps
|
||||
needs: [docker-build-push, load-config, check-version]
|
||||
name: New docker to the cluster
|
||||
needs: [docker-build-push]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/gitops-dispatch.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
|
||||
@@ -10,14 +10,14 @@ on:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
name: Config load
|
||||
name: Load git-pages.gitea-env.conf to pipeline env
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/git-pages.gitea-env.conf
|
||||
|
||||
check-version:
|
||||
name: Latest version
|
||||
name: Check existing artifact
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/check-version.yml@main
|
||||
secrets: inherit
|
||||
@@ -36,9 +36,9 @@ jobs:
|
||||
chart_path: git-pages
|
||||
|
||||
chart-gitops:
|
||||
name: GitOps
|
||||
needs: [helm-push, load-config, check-version]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/gitops-dispatch.yml@main
|
||||
name: Update chart to the cluster
|
||||
needs: [helm-push]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/gitops-dispatch.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
|
||||
report-summary:
|
||||
name: Report Summary
|
||||
needs: [load-config, check-version, helm-push, chart-gitops]
|
||||
needs: [load-config, helm-push, chart-gitops]
|
||||
if: always()
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/report-summary.yml@main
|
||||
with:
|
||||
|
||||
@@ -35,149 +35,24 @@ env:
|
||||
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
||||
GITOPS_TAG_PREFIX: ${{ fromJson(inputs.env_json).GIT_TAG_PREFIX || '' }}
|
||||
GITOPS_WORKFLOW: gitops-service.yaml
|
||||
GITOPS_DISPATCH_TIMEOUT: 30
|
||||
|
||||
jobs:
|
||||
dispatch:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
summary: ${{ steps.summary.outputs.GITOPS_SUMMARY }}
|
||||
summary: ${{ steps.run.outputs.GITOPS_SUMMARY }}
|
||||
steps:
|
||||
- name: Generate dispatch_id
|
||||
id: gen
|
||||
run: |
|
||||
ID=$(date +%s | md5sum | head -c 8)
|
||||
echo "dispatch_id=$ID" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Dispatch to GitOps repo
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
- name: Run gitops dispatch
|
||||
id: run
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITOPS_DISPATCH_TOKEN }}
|
||||
run: |
|
||||
INPUTS=$(jq -nc \
|
||||
--arg dispatch_id "${{ steps.gen.outputs.dispatch_id }}" \
|
||||
--arg file "$GITOPS_FILE" \
|
||||
--arg yq_tpl "$GITOPS_YQ_TPL" \
|
||||
--arg version "$GITOPS_VERSION" \
|
||||
--arg source_repo "$GITOPS_SOURCE_REPO" \
|
||||
--arg source_commit "$GITOPS_SOURCE_COMMIT" \
|
||||
--arg git_tag_prefix "${GITOPS_TAG_PREFIX:-}" \
|
||||
'{dispatch_id: $dispatch_id, file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix}')
|
||||
curl -s -X POST \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/actions/workflows/${GITOPS_WORKFLOW}/dispatches" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -nc --arg ref "main" --argjson inputs "$INPUTS" '{ref: "main", inputs: $inputs}')"
|
||||
|
||||
- name: Poll for completion
|
||||
id: poll
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITOPS_DISPATCH_TOKEN }}
|
||||
run: |
|
||||
ID="${{ steps.gen.outputs.dispatch_id }}"
|
||||
TIMEOUT_MINUTES="${GITOPS_DISPATCH_TIMEOUT:-30}"
|
||||
POLL_INTERVAL=10
|
||||
START_TIME=$(date +%s)
|
||||
TIMEOUT_SECONDS=$((TIMEOUT_MINUTES * 60))
|
||||
|
||||
echo "Polling for run with dispatch_id=$ID"
|
||||
|
||||
while [ -z "$RUN_ID" ]; do
|
||||
NOW=$(date +%s)
|
||||
ELAPSED=$((NOW - START_TIME))
|
||||
if [ "$ELAPSED" -ge "$TIMEOUT_SECONDS" ]; then
|
||||
echo "ERROR: Timeout waiting for run to appear" >&2
|
||||
exit 124
|
||||
fi
|
||||
|
||||
RUNS_RESP=$(curl -s --connect-timeout 5 --max-time 10 \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/actions/runs?event=workflow_dispatch&limit=10" \
|
||||
-H "Authorization: token $GITEA_TOKEN")
|
||||
RUN_ID=$(echo "$RUNS_RESP" | jq -r --arg id "$ID" \
|
||||
'[.workflow_runs[] | select(.display_title | contains($id))] | .[0].id // empty')
|
||||
|
||||
[ -z "$RUN_ID" ] && sleep "$POLL_INTERVAL"
|
||||
done
|
||||
|
||||
echo "Run found: id=$RUN_ID"
|
||||
|
||||
while true; do
|
||||
NOW=$(date +%s)
|
||||
ELAPSED=$((NOW - START_TIME))
|
||||
if [ "$ELAPSED" -ge "$TIMEOUT_SECONDS" ]; then
|
||||
echo "ERROR: Timeout waiting for completion" >&2
|
||||
exit 124
|
||||
fi
|
||||
|
||||
RUN_RESP=$(curl -s --connect-timeout 5 --max-time 10 \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/actions/runs/${RUN_ID}" \
|
||||
-H "Authorization: token $GITEA_TOKEN")
|
||||
STATUS=$(echo "$RUN_RESP" | jq -r '.status // "running"')
|
||||
CONCLUSION=$(echo "$RUN_RESP" | jq -r '.conclusion // ""')
|
||||
|
||||
echo " status=$STATUS conclusion=$CONCLUSION"
|
||||
|
||||
if [ "$STATUS" = "completed" ]; then
|
||||
if [ "$CONCLUSION" = "success" ]; then
|
||||
echo "GitOps workflow completed successfully"
|
||||
|
||||
# 1. List recent commits from GitOps repo
|
||||
COMMITS=$(curl -s --connect-timeout 5 --max-time 10 \
|
||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/commits?sha=main&limit=10" \
|
||||
-H "Authorization: token $GITEA_TOKEN")
|
||||
|
||||
# 2. Find commit by message: "gitops: update version to X.Y.Z"
|
||||
SEARCH_MSG="gitops: update version to ${GITOPS_VERSION}"
|
||||
GITOPS_COMMIT=$(echo "$COMMITS" | jq -r \
|
||||
--arg msg "$SEARCH_MSG" \
|
||||
'[.[] | select(.commit.message | contains($msg))] | .[0].sha // empty')
|
||||
|
||||
# 3. If not found → no change → use HEAD
|
||||
if [ -z "$GITOPS_COMMIT" ]; then
|
||||
GITOPS_COMMIT=$(echo "$COMMITS" | jq -r '.[0].sha // empty')
|
||||
fi
|
||||
|
||||
# 4. Set commit status on caller's own commit
|
||||
PREFIX="${GITOPS_TAG_PREFIX%/}"
|
||||
if [ -n "$PREFIX" ]; then
|
||||
CONTEXT="gitops/$(basename "${GITOPS_SOURCE_REPO}")/${PREFIX}"
|
||||
DESCRIPTION="GitOps: ${PREFIX} ${GITOPS_VERSION}"
|
||||
else
|
||||
CONTEXT="gitops/$(basename "${GITOPS_SOURCE_REPO}")"
|
||||
DESCRIPTION="GitOps: ${GITOPS_VERSION}"
|
||||
fi
|
||||
STATUS_URL="${GITEA_API_URL}/api/v1/repos/${GITOPS_SOURCE_REPO}/statuses/${GITOPS_SOURCE_COMMIT}"
|
||||
STATUS_BODY=$(jq -nc \
|
||||
--arg state "success" \
|
||||
--arg description "$DESCRIPTION" \
|
||||
--arg context "$CONTEXT" \
|
||||
--arg target_url "${GITEA_API_URL}/${GITOPS_REPO}/commit/${GITOPS_COMMIT}" \
|
||||
'{state: $state, target_url: $target_url, description: $description, context: $context}')
|
||||
curl -s -X POST "$STATUS_URL" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$STATUS_BODY" || true
|
||||
|
||||
echo "GITOPS_COMMIT=$GITOPS_COMMIT" >> "$GITHUB_OUTPUT"
|
||||
echo "$GITOPS_COMMIT" > /tmp/gitops-commit
|
||||
exit 0
|
||||
else
|
||||
echo "ERROR: GitOps workflow failed with conclusion=$CONCLUSION" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
sleep "$POLL_INTERVAL"
|
||||
done
|
||||
|
||||
- name: GitOps summary
|
||||
id: summary
|
||||
if: always()
|
||||
run: |
|
||||
STATUS="failure"
|
||||
GITOPS_SHA=""
|
||||
if [ -f /tmp/gitops-commit ]; then
|
||||
STATUS="success"
|
||||
GITOPS_SHA=$(cat /tmp/gitops-commit)
|
||||
fi
|
||||
COMPONENT="${GITOPS_TAG_PREFIX:-${GITOPS_FILE}}"
|
||||
echo "GITOPS_SUMMARY=${COMPONENT}|${GITOPS_VERSION}|${STATUS}|${GITOPS_SHA}|${GITOPS_REPO}" >> "$GITHUB_OUTPUT"
|
||||
OUTPUT=$(bash .ci/scripts/gitops-dispatch.sh)
|
||||
echo "$OUTPUT"
|
||||
SUMMARY=$(awk -F= '/^GITOPS_SUMMARY=/ {print $2}' <<<"$OUTPUT")
|
||||
echo "GITOPS_SUMMARY=$SUMMARY" >> "$GITHUB_OUTPUT"
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ helm upgrade --install git-pages ./git-pages \
|
||||
|
||||
helm template git-pages ./git-pages -f "$VALUES"
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## CI-julkaisu
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "gitops-dispatch: validating env vars..."
|
||||
: "${GITOPS_FILE:?}"
|
||||
: "${GITOPS_YQ_TPL:?}"
|
||||
: "${GITOPS_VERSION:?}"
|
||||
@@ -14,7 +13,6 @@ echo "gitops-dispatch: validating env vars..."
|
||||
|
||||
TIMEOUT="${GITOPS_DISPATCH_TIMEOUT:-30}"
|
||||
|
||||
echo "gitops-dispatch: constructing inputs..."
|
||||
INPUTS=$(jq -nc \
|
||||
--arg file "$GITOPS_FILE" \
|
||||
--arg yq_tpl "$GITOPS_YQ_TPL" \
|
||||
@@ -25,7 +23,6 @@ INPUTS=$(jq -nc \
|
||||
'{file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix}')
|
||||
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
echo "gitops-dispatch: dispatching to $GITOPS_REPO/$GITOPS_WORKFLOW..."
|
||||
set +e
|
||||
OUTPUT=$(bash "$DIR/dispatch-workflow.sh" \
|
||||
"$GITOPS_REPO" "$GITOPS_WORKFLOW" "main" \
|
||||
@@ -33,9 +30,7 @@ OUTPUT=$(bash "$DIR/dispatch-workflow.sh" \
|
||||
EXIT=$?
|
||||
set -e
|
||||
|
||||
echo "=== DISPATCH OUTPUT (exit=$EXIT) ==="
|
||||
echo "$OUTPUT"
|
||||
echo "=== END DISPATCH ==="
|
||||
|
||||
STATUS="failure"
|
||||
GITOPS_SHA=""
|
||||
|
||||
Reference in New Issue
Block a user