From d818ee6600391800416bd80ea76b1a9ff7ccfc63 Mon Sep 17 00:00:00 2001 From: "d.viti" Date: Fri, 3 Oct 2025 01:56:36 +0200 Subject: [PATCH] Add Helm chart build and publishing to Gitea workflows - Added Helm chart build job to main CI/CD workflow - Created dedicated helm-release workflow for version tags - Integrated Helm packaging with Gitea package registry - Added automatic chart versioning and publishing - Updated README with Helm deployment instructions - Configured chart linting and validation steps - Added release automation for tagged versions --- .gitea/workflows/build.yml | 64 +++++++++++++ .gitea/workflows/helm-release.yml | 147 ++++++++++++++++++++++++++++++ README.md | 66 +++++++++++++- 3 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 .gitea/workflows/helm-release.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index cb63af4..9dc04c9 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -79,3 +79,67 @@ jobs: labels: ${{ steps.meta-api.outputs.labels }} cache-from: type=registry,ref=${{ vars.PACKAGES_REGISTRY || gitea.server_url }}/${{ gitea.repository }}/api:buildcache cache-to: type=registry,ref=${{ vars.PACKAGES_REGISTRY || gitea.server_url }}/${{ gitea.repository }}/api:buildcache,mode=max + + build-helm: + runs-on: ubuntu-latest + needs: [build-web, build-api] + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for proper versioning + + - name: Install Helm + uses: azure/setup-helm@v3 + with: + version: 'latest' + + - name: Update Chart dependencies + run: | + cd helm/api7ee + helm dependency update + + - name: Lint Helm chart + run: | + helm lint helm/api7ee/ + + - name: Package Helm chart + run: | + # Get version from Chart.yaml + CHART_VERSION=$(grep '^version:' helm/api7ee/Chart.yaml | awk '{print $2}') + + # Update image registry in values.yaml to match Gitea registry + sed -i "s|registry: gitea.server_url|registry: ${{ gitea.server_url }}|g" helm/api7ee/values.yaml + + # Package the chart + helm package helm/api7ee/ --version ${CHART_VERSION} + + # Store chart filename for later use + echo "CHART_FILE=api7ee-${CHART_VERSION}.tgz" >> $GITHUB_ENV + + - name: Push Helm chart to Gitea Package Registry + run: | + # Upload Helm chart to Gitea package registry + # Format: https://{gitea-server}/api/packages/{owner}/helm/api/charts + curl --fail-with-body \ + -H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \ + -X POST \ + -F "chart=@${CHART_FILE}" \ + https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm/api/charts + + echo "✅ Helm chart pushed successfully to Gitea Package Registry" + echo "📦 Chart: ${CHART_FILE}" + echo "🔗 Registry URL: https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" + + - name: Create Helm index + if: success() + run: | + # Create or update the Helm repository index + echo "📝 Helm chart repository information:" + echo "To add this repository:" + echo " helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" + echo " helm repo update" + echo "" + echo "To install the chart:" + echo " helm install my-api7ee api7ee/api7ee" diff --git a/.gitea/workflows/helm-release.yml b/.gitea/workflows/helm-release.yml new file mode 100644 index 0000000..b9ebd18 --- /dev/null +++ b/.gitea/workflows/helm-release.yml @@ -0,0 +1,147 @@ +name: Helm Chart Release + +on: + push: + tags: + - 'v*.*.*' # Trigger on version tags like v1.0.0 + workflow_dispatch: + inputs: + version: + description: 'Chart version to release (e.g., 1.0.1)' + required: true + type: string + +jobs: + release-helm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Helm + uses: azure/setup-helm@v3 + with: + version: 'latest' + + - name: Determine version + id: version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + VERSION="${{ github.event.inputs.version }}" + else + # Extract version from tag (remove 'v' prefix) + VERSION=${GITHUB_REF#refs/tags/v} + fi + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + echo "📌 Chart version: ${VERSION}" + + - name: Update Chart version + run: | + # Update Chart.yaml with the new version + sed -i "s/^version:.*/version: ${{ steps.version.outputs.VERSION }}/" helm/api7ee/Chart.yaml + + # Update appVersion to match + sed -i "s/^appVersion:.*/appVersion: \"${{ steps.version.outputs.VERSION }}\"/" helm/api7ee/Chart.yaml + + # Update image tags in values.yaml to use this version + sed -i "s|tag: \"main\"|tag: \"v${{ steps.version.outputs.VERSION }}\"|g" helm/api7ee/values.yaml + + # Update registry to Gitea URL + sed -i "s|registry: gitea.server_url|registry: ${{ gitea.server_url }}|g" helm/api7ee/values.yaml + + echo "📝 Updated Chart.yaml and values.yaml with version ${{ steps.version.outputs.VERSION }}" + + - name: Lint Helm chart + run: | + helm lint helm/api7ee/ + + - name: Package Helm chart + run: | + helm package helm/api7ee/ --version ${{ steps.version.outputs.VERSION }} + echo "CHART_FILE=api7ee-${{ steps.version.outputs.VERSION }}.tgz" >> $GITHUB_ENV + + # Generate chart README with installation instructions + cat > CHART_README.md << EOF + # API7 Enterprise Edition Helm Chart v${{ steps.version.outputs.VERSION }} + + ## Installation + + \`\`\`bash + # Add the Helm repository + helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm + helm repo update + + # Install the chart + helm install my-api7ee api7ee/api7ee --version ${{ steps.version.outputs.VERSION }} + + # Install with custom values + helm install my-api7ee api7ee/api7ee --version ${{ steps.version.outputs.VERSION }} -f values.yaml + \`\`\` + + ## Upgrade + + \`\`\`bash + helm upgrade my-api7ee api7ee/api7ee --version ${{ steps.version.outputs.VERSION }} + \`\`\` + + ## Docker Images + + This chart uses the following Docker images: + - Web: \`${{ gitea.server_url }}/${{ gitea.repository }}/web:v${{ steps.version.outputs.VERSION }}\` + - API: \`${{ gitea.server_url }}/${{ gitea.repository }}/api:v${{ steps.version.outputs.VERSION }}\` + EOF + + - name: Push Helm chart to Gitea Package Registry + run: | + # Upload versioned Helm chart + curl --fail-with-body \ + -H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \ + -X POST \ + -F "chart=@${CHART_FILE}" \ + https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm/api/charts + + echo "✅ Helm chart v${{ steps.version.outputs.VERSION }} pushed to Gitea Package Registry" + + - name: Create Release + uses: softprops/action-gh-release@v1 + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + with: + files: | + ${{ env.CHART_FILE }} + CHART_README.md + generate_release_notes: true + body: | + ## Helm Chart Release v${{ steps.version.outputs.VERSION }} + + ### Installation + ```bash + helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm + helm repo update + helm install my-api7ee api7ee/api7ee --version ${{ steps.version.outputs.VERSION }} + ``` + + ### Docker Images + - Web: `${{ gitea.server_url }}/${{ gitea.repository }}/web:v${{ steps.version.outputs.VERSION }}` + - API: `${{ gitea.server_url }}/${{ gitea.repository }}/api:v${{ steps.version.outputs.VERSION }}` + + ### Changes + See the full changelog below. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Summary + run: | + echo "## 🎉 Helm Chart Release Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **Version:** v${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY + echo "- **Chart:** ${CHART_FILE}" >> $GITHUB_STEP_SUMMARY + echo "- **Registry:** https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### Installation Commands" >> $GITHUB_STEP_SUMMARY + echo '```bash' >> $GITHUB_STEP_SUMMARY + echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" >> $GITHUB_STEP_SUMMARY + echo "helm repo update" >> $GITHUB_STEP_SUMMARY + echo "helm install my-api7ee api7ee/api7ee --version ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/README.md b/README.md index a08e695..418cc66 100644 --- a/README.md +++ b/README.md @@ -93,18 +93,24 @@ The `.gitea/workflows/build.yml` pipeline automatically: 1. Builds Docker images for both applications 2. Pushes to Gitea container registry 3. Tags images with branch name -4. Implements layer caching for faster builds +4. Packages and publishes Helm chart +5. Implements layer caching for faster builds **Triggers:** -- Any branch push +- Any branch push (Docker images) +- Push to main branch (Helm chart) +- Version tags (Helm releases) - Manual dispatch **Registry:** `git.commandware.com/demos/api7-demo` -**Images:** +**Docker Images:** - `git.commandware.com/demos/api7-demo/web:` - `git.commandware.com/demos/api7-demo/api:` +**Helm Repository:** +- `https://git.commandware.com/api/packages/$OWNER/helm` + ### Setup 1. **Create `GITEA_TOKEN` secret:** @@ -123,10 +129,62 @@ The `.gitea/workflows/build.yml` pipeline automatically: ### Prerequisites - Kubernetes cluster (v1.19+) +- Helm 3.8.0+ - API7 Enterprise Gateway installed - Namespace: `api7ee` -### Deployment Manifest +### Deploy with Helm + +The project includes a complete Helm chart for easy deployment of both web and API components. + +#### Add Helm Repository + +```bash +# Add the Gitea Helm repository +helm repo add api7ee https://git.commandware.com/api/packages/$OWNER/helm +helm repo update +``` + +#### Install the Chart + +```bash +# Install with default values +helm install my-api7ee api7ee/api7ee --namespace api7ee --create-namespace + +# Install with custom values +helm install my-api7ee api7ee/api7ee -f custom-values.yaml --namespace api7ee + +# Install with specific image tags +helm install my-api7ee api7ee/api7ee \ + --set web.image.tag=v1.0.0 \ + --set api.image.tag=v1.0.0 \ + --namespace api7ee +``` + +#### Configuration Options + +Key Helm values: + +| Parameter | Description | Default | +|-----------|-------------|---------| +| `web.enabled` | Enable Web component | `true` | +| `web.replicaCount` | Number of Web replicas | `2` | +| `api.enabled` | Enable API component | `true` | +| `api.replicaCount` | Number of API replicas | `3` | +| `ingress.enabled` | Enable ingress | `true` | +| `ingress.hosts[0].host` | Ingress hostname | `demo.commandware.it` | + +#### Upgrade/Uninstall + +```bash +# Upgrade the release +helm upgrade my-api7ee api7ee/api7ee --namespace api7ee + +# Uninstall +helm uninstall my-api7ee --namespace api7ee +``` + +### Manual Deployment (Alternative) **k8s-deployments.yaml:** ```yaml