Initial CI/CD Setup #6
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: K8S Build & Test | |
| on: | |
| pull_request: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - "main" | |
| tags: | |
| - "v*" | |
| permissions: {} | |
| jobs: | |
| container: | |
| name: Build & publish container | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/metadata-action@v5 | |
| id: metadata | |
| with: | |
| images: ghcr.io/esgf2-us/metadata-migrate-sync | |
| tags: | | |
| type=ref,event=pr | |
| type=ref,event=tag | |
| - uses: docker/build-push-action@v4 | |
| with: | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| file: Dockerfile | |
| push: true | |
| tags: ${{ steps.metadata.outputs.tags }} | |
| labels: ${{ steps.metadata.outputs.labels }} | |
| helm: | |
| name: Publish Helm chart | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| - name: Install jq | |
| run: | | |
| sudo apt-get install --yes jq | |
| - name: Install yq | |
| run: | | |
| pip install yq | |
| - name: Generate SemVer | |
| id: semantic-version | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| PR_NUMBER=$(echo ${GITHUB_REF} | awk -F'/' '{print $3}') | |
| CHART_VERSION=$(yq -r '.version' helm/Chart.yaml)+pr-${PR_NUMBER} | |
| yq -Y -i ".version = \"$CHART_VERSION\"" helm/Chart.yaml | |
| echo "::set-output name=generated-semver::$CHART_VERSION" | |
| - name: Chart | Push | |
| uses: appany/[email protected] | |
| with: | |
| name: esgf-migrate | |
| repository: esgf2-us | |
| tag: ${{ steps.semantic-version.outputs.generated-semver }} | |
| path: helm | |
| registry: ghcr.io | |
| registry_username: ${{ github.actor }} | |
| registry_password: ${{ secrets.GITHUB_TOKEN }} | |
| update_dependencies: "true" | |
| test: | |
| name: Test deployment | |
| runs-on: ubuntu-latest | |
| needs: [container, helm] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Start minikube | |
| uses: medyagh/setup-minikube@latest | |
| - name: Set up Helm | |
| uses: azure/[email protected] | |
| - name: Install Helm Chart | |
| working-directory: helm/ | |
| run: | | |
| PR_NUMBER=$(echo ${GITHUB_REF} | awk -F'/' '{print $3}') | |
| helm dependency build | |
| helm install test . \ | |
| --set image.tag=pr-${PR_NUMBER} \ | |
| --wait | |
| kubectl get pods |