Helm deploy and minikube test #52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Helm Chart CI/CD | |
| on: | |
| push: | |
| branches: [ helm-deploy ] | |
| pull_request: | |
| branches: | |
| - helm-deploy | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build-docker-images: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| service: | |
| - name: db | |
| context: ./opensampl/db | |
| - name: backend | |
| context: ./opensampl/backend | |
| - name: grafana | |
| context: ./opensampl/server/grafana | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set image tags | |
| id: tags | |
| run: | | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| PR_NUMBER=$(echo ${{ github.ref }} | awk -F'/' '{print $3}') | |
| echo "tag=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push ${{ matrix.service.name }} image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.service.context }} | |
| push: true | |
| tags: ghcr.io/ornl/opensampl-${{ matrix.service.name }}:${{ steps.tags.outputs.tag }} | |
| cache-from: type=gha,scope=${{ matrix.service.name }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.service.name }} | |
| test-helm-chart: | |
| name: Test Helm Chart Deployment | |
| runs-on: ubuntu-latest | |
| needs: build-docker-images | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Start minikube | |
| uses: medyagh/setup-minikube@latest | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4 | |
| - name: Install Helm Chart | |
| working-directory: helm/ | |
| run: | | |
| PR_NUMBER=$(echo ${GITHUB_REF} | awk -F'/' '{print $3}') | |
| helm install test-opensampl . \ | |
| --set db.image.tag=pr-${PR_NUMBER} \ | |
| --set backend.image.tag=pr-${PR_NUMBER} \ | |
| --set grafana.image.tag=pr-${PR_NUMBER} \ | |
| --set migrations.enabled=false \ | |
| --wait \ | |
| --timeout 5m | |
| - name: Verify Deployment | |
| run: | | |
| kubectl get pods | |
| kubectl get services | |
| kubectl get pvc | |
| - name: Show Pod Logs on Failure | |
| if: failure() | |
| run: | | |
| echo "=== Pod Status ===" | |
| kubectl get pods | |
| echo "=== Pod Descriptions ===" | |
| kubectl describe pods | |
| echo "=== Pod Logs ===" | |
| for pod in $(kubectl get pods -o name); do | |
| echo "Logs for $pod:" | |
| kubectl logs $pod --all-containers=true || true | |
| done | |
| helm-package: | |
| name: Package and Push Helm Chart | |
| runs-on: ubuntu-latest | |
| needs: build-docker-images | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Helm | |
| uses: azure/setup-helm@v4 | |
| with: | |
| version: v3.14.0 | |
| - name: Helm Lint | |
| run: helm lint ./helm | |
| - name: Package Chart | |
| run: helm package ./helm | |
| - name: Push to GHCR | |
| env: | |
| CR_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| helm registry login ghcr.io -u $GITHUB_ACTOR -p $CR_PAT | |
| helm push opensampl-*.tgz oci://ghcr.io/ornl/charts |