support using secret names instead of UUID #96
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: Build and test | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - "main" | |
| workflow_dispatch: | |
| inputs: | |
| push_image: | |
| description: "Push image to GitHub Container Registry (Always true on main)" | |
| required: false | |
| default: false | |
| type: boolean | |
| env: | |
| _PUSH_IMAGE: ${{ (inputs.push_image == true || github.ref == 'refs/heads/main') && 'true' || 'false' }} | |
| jobs: | |
| build-and-test: | |
| name: Build image and test | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| packages: write | |
| security-events: write | |
| id-token: write | |
| env: | |
| _IMAGE_NAME: ghcr.io/bitwarden/sm-operator | |
| steps: | |
| - name: Check out repo | |
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Test operator | |
| id: test | |
| run: | | |
| sudo apt update && sudo apt install musl-tools -y | |
| make setup | |
| make test | |
| - name: Upload to codecov.io | |
| uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 | |
| - name: Generate Docker image tag | |
| id: tag | |
| env: | |
| EVENT_TYPE: ${{ contains(github.event_name, 'pull_request') && 'pull_request' || '' }} | |
| run: | | |
| if [[ "$EVENT_TYPE" == "pull_request" ]]; then | |
| IMAGE_TAG="pr-${{ github.event.pull_request.number }}" | |
| else | |
| ref="${GITHUB_REF:11}" | |
| IMAGE_TAG="${ref//\//-}" | |
| if [[ "${IMAGE_TAG}" == "main" ]]; then | |
| IMAGE_TAG="dev" | |
| fi | |
| fi | |
| echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Generate image tag(s) | |
| id: image-tags | |
| env: | |
| IMAGE_TAG: ${{ steps.tag.outputs.image_tag }} | |
| SHA: ${{ github.sha }} | |
| run: | | |
| TAGS="$_IMAGE_NAME:$IMAGE_TAG" | |
| echo "primary_tag=$TAGS" >> "$GITHUB_OUTPUT" | |
| if [[ "$IMAGE_TAG" == "dev" ]]; then | |
| SHORT_SHA="$(git rev-parse --short "${SHA}")" | |
| TAGS="$TAGS,$TAGS-${SHORT_SHA}" | |
| fi | |
| echo "tags=$TAGS" >> "$GITHUB_OUTPUT" | |
| - name: Build Docker image | |
| id: build-docker | |
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | |
| with: | |
| file: Dockerfile | |
| platforms: ${{ env._PUSH_IMAGE == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }} # Can only do single arch when not pushing to support scan and testing locally | |
| push: ${{ env._PUSH_IMAGE == 'true' }} | |
| load: ${{ env._PUSH_IMAGE != 'true' }} | |
| tags: ${{ steps.image-tags.outputs.tags }} | |
| - name: Install Cosign | |
| if: ${{ env._PUSH_IMAGE == 'true' }} | |
| uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0 | |
| - name: Sign image with Cosign | |
| if: ${{ env._PUSH_IMAGE == 'true' }} | |
| env: | |
| DIGEST: ${{ steps.build-docker.outputs.digest }} | |
| TAGS: ${{ steps.image-tags.outputs.tags }} | |
| run: | | |
| IFS=',' read -r -a tags_array <<< "${TAGS}" | |
| images=() | |
| for tag in "${tags_array[@]}"; do | |
| images+=("${tag}@${DIGEST}") | |
| done | |
| cosign sign --yes "${images[@]}" | |
| - name: Create kind cluster | |
| uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab # v1.13.0 | |
| - name: Load image into kind | |
| if: ${{ env._PUSH_IMAGE != 'true' }} | |
| env: | |
| IMAGE: ${{ steps.image-tags.outputs.primary_tag }} | |
| run: kind load docker-image "$IMAGE" --name "$(kind get clusters)" | |
| - name: Smoke test image | |
| id: smoke-test | |
| env: | |
| IMAGE: ${{ steps.image-tags.outputs.primary_tag }} | |
| run: | | |
| make deploy IMG="$IMAGE" | |
| count=0 | |
| while [[ $(kubectl get pods -n sm-operator-system -l control-plane=controller-manager -o jsonpath="{.items[*].status.containerStatuses[*].ready}") != "true" ]]; do | |
| sleep 1; | |
| count=$count+1 | |
| if [[ count -ge 30 ]]; then | |
| break | |
| fi | |
| done | |
| #For review purposes | |
| echo "*****DEPLOYMENTS*****" | |
| kubectl get deployments -n sm-operator-system | |
| echo "*****PODS*****" | |
| pods=$(kubectl get pods -n sm-operator-system -l control-plane=controller-manager | grep 2/2) | |
| echo "$pods" | |
| if [[ -z "$pods" ]]; then | |
| echo "::error::No pods found." | |
| exit 1 | |
| fi | |
| echo "*****OPERATOR OK*****" | |
| - name: Clean up | |
| run: | | |
| make undeploy | |
| kind delete cluster | |
| - name: Log out of Docker | |
| run: docker logout ghcr.io |