|
| 1 | +name: "Test and Publish BeeGFS CSI Driver" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "master" |
| 8 | + tags: |
| 9 | + - "v*" |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - "master" |
| 13 | + |
| 14 | +env: |
| 15 | + # Container image registry to publish images to: |
| 16 | + REGISTRY: ghcr.io |
| 17 | + # Where to push an image of the CSI driver that will be retained (for master builds or releases) without a specific tag: |
| 18 | + IMAGE_NAME: ghcr.io/thinkparq/beegfs-csi-driver |
| 19 | + # Where to push an image of the CSI driver for testing (including the operator) without a specific tag: |
| 20 | + TEST_IMAGE_NAME: ghcr.io/thinkparq/test-beegfs-csi-driver |
| 21 | + |
| 22 | + # Note for all test images the github.sha will be used as the tag. |
| 23 | + |
| 24 | +jobs: |
| 25 | + build-and-unit-test: |
| 26 | + runs-on: ubuntu-22.04 |
| 27 | + timeout-minutes: 5 |
| 28 | + permissions: |
| 29 | + packages: write |
| 30 | + contents: read |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v3 |
| 33 | + with: |
| 34 | + # Work around for how release-tools verify-subtree.sh verifies release-tools has not been modified. |
| 35 | + fetch-depth: "0" |
| 36 | + |
| 37 | + - name: Set up Go |
| 38 | + uses: actions/setup-go@v4 |
| 39 | + with: |
| 40 | + go-version: 1.20.4 |
| 41 | + # Dependencies are cached by default: https://github.com/actions/setup-go#v4 |
| 42 | + # This can be explicitly disabled if it ever causes problems. |
| 43 | + |
| 44 | + - name: Build the container image |
| 45 | + run: | |
| 46 | + export SHELL=/bin/bash |
| 47 | + make container |
| 48 | + echo -n "verifying images:" |
| 49 | + docker images |
| 50 | +
|
| 51 | + - name: Install test dependencies |
| 52 | + run: | |
| 53 | + go install github.com/onsi/ginkgo/v2/[email protected] |
| 54 | + timeout-minutes: 5 |
| 55 | + |
| 56 | + - name: Run unit tests |
| 57 | + run: | |
| 58 | + ACK_GINKGO_DEPRECATIONS=1.16.5 TESTARGS="-v -ginkgo.v" make test |
| 59 | + # TODO: Consider if we should write the results to a file and keep it as an artifact. |
| 60 | + # For example using: https://github.com/marketplace/actions/junit-report-action |
| 61 | + # TODO: Can we cache anything here? test-vendor downloads a lot of stuff. |
| 62 | + # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go#caching-dependencies |
| 63 | + |
| 64 | + - name: Log into the GitHub Container Registry |
| 65 | + uses: docker/login-action@v2 |
| 66 | + with: |
| 67 | + registry: ${{ env.REGISTRY }} |
| 68 | + username: ${{ github.actor }} |
| 69 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + # Push the image for reuse in subsequent steps, jobs, and workflows. |
| 72 | + # For now just tag with the commit ID to ensure subsequent jobs in this workflow run use the correct image. |
| 73 | + - name: Tag and push the CSI driver as a test package |
| 74 | + run: | |
| 75 | + docker tag beegfs-csi-driver:latest ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }} |
| 76 | + docker push ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }} |
| 77 | +
|
| 78 | + e2e-tests: |
| 79 | + runs-on: ubuntu-22.04 |
| 80 | + timeout-minutes: 10 |
| 81 | + needs: build-and-unit-test |
| 82 | + strategy: |
| 83 | + fail-fast: true |
| 84 | + matrix: |
| 85 | + k8s-version: [1.24.15, 1.25.11, 1.26.3, 1.27.3] |
| 86 | + beegfs-version: [7.3.4] |
| 87 | + permissions: |
| 88 | + packages: read |
| 89 | + contents: read |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v3 |
| 92 | + |
| 93 | + - name: Set up Docker Buildx |
| 94 | + uses: docker/setup-buildx-action@v2 |
| 95 | + |
| 96 | + - name: Deploy Kubernetes ${{ matrix.k8s-version }} using Minikube |
| 97 | + uses: medyagh/setup-minikube@latest |
| 98 | + with: |
| 99 | + driver: none |
| 100 | + kubernetes-version: ${{ matrix.k8s-version }} |
| 101 | + |
| 102 | + - name: Deploy BeeGFS ${{ matrix.beegfs-version }} for testing |
| 103 | + run: | |
| 104 | + export BEEGFS_VERSION=$(echo ${{ matrix.beegfs-version }}) |
| 105 | + export BEEGFS_SECRET=$(echo ${{ secrets.CONN_AUTH_SECRET }}) |
| 106 | + envsubst < test/env/beegfs-ubuntu/beegfs-fs-1.yaml | kubectl apply -f - |
| 107 | + kubectl get pods -A |
| 108 | +
|
| 109 | + # TODO: Cache BeeGFS packages https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows |
| 110 | + # https://stackoverflow.com/questions/59269850/caching-apt-packages-in-github-actions-workflow |
| 111 | + - name: Install the BeeGFS ${{ matrix.beegfs-version }} DKMS client |
| 112 | + run: | |
| 113 | + sudo wget -P /etc/apt/sources.list.d/. https://www.beegfs.io/release/beegfs_${{ matrix.beegfs-version }}/dists/beegfs-focal.list |
| 114 | + sudo wget -q https://www.beegfs.io/release/beegfs_${{ matrix.beegfs-version }}/gpg/GPG-KEY-beegfs -O- | sudo apt-key add - |
| 115 | + sudo apt-get update && sudo apt-get install beegfs-client-dkms beegfs-helperd beegfs-utils -y |
| 116 | + sudo sed -i 's/connDisableAuthentication = false/connDisableAuthentication = true/' /etc/beegfs/beegfs-helperd.conf |
| 117 | + sudo systemctl start beegfs-helperd && sudo systemctl enable beegfs-helperd |
| 118 | +
|
| 119 | + - name: Deploy the BeeGFS CSI driver |
| 120 | + run: | |
| 121 | + export BEEGFS_SECRET=$(echo ${{ secrets.CONN_AUTH_SECRET }}) |
| 122 | + envsubst < test/env/beegfs-ubuntu/csi-beegfs-connauth.yaml > deploy/k8s/overlays/default/csi-beegfs-connauth.yaml |
| 123 | + # TODO: Enable once the K8s versions in the matrix are added to versions/ |
| 124 | + # sed -i 's?/versions/latest?/versions/v${{ matrix.k8s-version }}?g' deploy/k8s/overlays/default/kustomization.yaml |
| 125 | + echo -e "\nimages:\n - name: ${{ env.IMAGE_NAME }}\n newName: ${{ env.TEST_IMAGE_NAME }}\n newTag: ${{ github.sha }}" >> deploy/k8s/overlays/default/kustomization.yaml |
| 126 | + kubectl apply -k deploy/k8s/overlays/default |
| 127 | +
|
| 128 | + # TODO (BCSI-7): Actually run e2e tests using Ginko with an appropriate timeout. |
| 129 | + |
| 130 | + - name: Deploy all examples to verify the driver is available |
| 131 | + run: | |
| 132 | + echo "${{ secrets.CONN_AUTH_SECRET }}" | sudo tee /etc/beegfs/connAuth |
| 133 | + sudo sed -i '0,/connAuthFile[[:space:]]*=[[:space:]]*/s//connAuthFile = \/etc\/beegfs\/connAuth/' /etc/beegfs/beegfs-client.conf |
| 134 | + sudo sed -i '0,/sysMgmtdHost[[:space:]]*=[[:space:]]*/s//sysMgmtdHost = localhost/' /etc/beegfs/beegfs-client.conf |
| 135 | + sudo beegfs-ctl --cfgFile=/etc/beegfs/beegfs-client.conf --unmounted --createdir /k8s |
| 136 | + sudo beegfs-ctl --cfgFile=/etc/beegfs/beegfs-client.conf --unmounted --createdir /k8s/all |
| 137 | + sudo beegfs-ctl --cfgFile=/etc/beegfs/beegfs-client.conf --unmounted --createdir /k8s/all/static |
| 138 | + sudo beegfs-ctl --cfgFile=/etc/beegfs/beegfs-client.conf --unmounted --createdir /k8s/all/static-ro |
| 139 | + kubectl apply -f examples/k8s/all |
| 140 | +
|
| 141 | + # If the controller or node service failed to start, our test pod would still be in phase pending. |
| 142 | + # We'll check periodically if the pod has started and if we reach the max number of attempts fail with debug output. |
| 143 | + - name: Wait and verify the test pod is running |
| 144 | + run: | |
| 145 | + MAX_ATTEMPTS=36 |
| 146 | + SLEEP_TIME=5 |
| 147 | + COUNTER=0 |
| 148 | +
|
| 149 | + while [ $COUNTER -lt $MAX_ATTEMPTS ]; do |
| 150 | + POD_STATUS=$(kubectl get pods csi-beegfs-all-app -o jsonpath='{.status.phase}') |
| 151 | + echo "Pod status: ${POD_STATUS}" |
| 152 | + if [ "${POD_STATUS}" == "Running" ]; then |
| 153 | + echo "Verified test pod is running." |
| 154 | + break |
| 155 | + else |
| 156 | + echo "Pod is not running, waiting for ${SLEEP_TIME} seconds..." |
| 157 | + sleep ${SLEEP_TIME} |
| 158 | + COUNTER=$((COUNTER+1)) |
| 159 | + fi |
| 160 | + done |
| 161 | +
|
| 162 | + if [ $COUNTER -eq $MAX_ATTEMPTS ]; then |
| 163 | + echo "Test pod did not reach 'Running' status within the maximum allowed time. Outputting debug information and exiting with error..." |
| 164 | + kubectl get pods -A |
| 165 | + kubectl describe pod -n beegfs-csi csi-beegfs-controller-0 |
| 166 | + POD_NAME=$(kubectl get pods -n beegfs-csi -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep 'csi-beegfs-node-') |
| 167 | + kubectl describe pod -n beegfs-csi $POD_NAME |
| 168 | + kubectl describe pod csi-beegfs-all-app |
| 169 | + docker images |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | +
|
| 173 | + publish-images: |
| 174 | + runs-on: ubuntu-22.04 |
| 175 | + timeout-minutes: 5 |
| 176 | + needs: e2e-tests |
| 177 | + if: github.event_name != 'pull_request' |
| 178 | + permissions: |
| 179 | + packages: write |
| 180 | + contents: read |
| 181 | + steps: |
| 182 | + - uses: actions/checkout@v3 |
| 183 | + |
| 184 | + - name: Set up Docker Buildx |
| 185 | + uses: docker/setup-buildx-action@v2 |
| 186 | + |
| 187 | + - name: Install Cosign |
| 188 | + |
| 189 | + with: |
| 190 | + cosign-release: "v2.1.1" |
| 191 | + |
| 192 | + - name: Pull tested CSI driver image from ghcr.io |
| 193 | + run: | |
| 194 | + docker pull ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }} |
| 195 | +
|
| 196 | + - name: Log in to the GitHub Container Registry |
| 197 | + uses: docker/login-action@v2 |
| 198 | + with: |
| 199 | + registry: ${{ env.REGISTRY }} |
| 200 | + username: ${{ github.actor }} |
| 201 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 202 | + |
| 203 | + # This uses the semantic versioning option for https://github.com/docker/metadata-action#semver |
| 204 | + - name: Extract metadata for container image |
| 205 | + id: meta |
| 206 | + uses: docker/metadata-action@v4 |
| 207 | + with: |
| 208 | + images: | |
| 209 | + ${{ env.IMAGE_NAME }} |
| 210 | + tags: | |
| 211 | + type=ref,event=branch |
| 212 | + type=ref,event=pr |
| 213 | + type=semver,pattern={{version}},prefix=v |
| 214 | + type=semver,pattern={{major}}.{{minor}},prefix=v |
| 215 | +
|
| 216 | + # TODO: Consider adding labels available as steps.meta.output.labels. |
| 217 | + - name: Tag and push the image to GitHub Container Registry |
| 218 | + run: | |
| 219 | + tags=$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' ') |
| 220 | + for tag in $tags; do |
| 221 | + docker tag ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }} $tag |
| 222 | + docker push $tag |
| 223 | + done |
| 224 | +
|
| 225 | + # Adapted from: |
| 226 | + # https://github.blog/2021-12-06-safeguard-container-signing-capability-actions/ |
| 227 | + # https://github.com/sigstore/cosign-installer#usage |
| 228 | + - name: Sign image with Cosign |
| 229 | + run: | |
| 230 | + tags=$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' ') |
| 231 | + for tag in $tags; do |
| 232 | + DIGEST=$(docker image inspect $tag --format '{{index .RepoDigests 0}}') |
| 233 | + cosign sign --yes --key env://COSIGN_PRIVATE_KEY \ |
| 234 | + -a "repo=${{ github.repository }}" \ |
| 235 | + -a "run=${{ github.run_id }}" \ |
| 236 | + -a "ref=${{ github.sha }}" \ |
| 237 | + $DIGEST |
| 238 | + done |
| 239 | + env: |
| 240 | + COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} |
| 241 | + COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} |
| 242 | + |
| 243 | + # We'll keep around a few old test packages to (a) avoid deleting image for workflows running in parallel, |
| 244 | + # and (b) it may be useful to pull a package to troubleshoot workflow failures. |
| 245 | + cleanup-test-images: |
| 246 | + runs-on: ubuntu-22.04 |
| 247 | + timeout-minutes: 3 |
| 248 | + needs: publish-images |
| 249 | + if: always() |
| 250 | + steps: |
| 251 | + - name: Extract package names |
| 252 | + run: | |
| 253 | + test_image_name="${{ env.TEST_IMAGE_NAME }}" |
| 254 | + test_image_pkg=${test_image_name##*/} |
| 255 | + echo "TEST_IMAGE_PKG=$test_image_pkg" >> $GITHUB_ENV |
| 256 | +
|
| 257 | + - name: Cleanup old ${{ env.TEST_IMAGE_PKG }} packages |
| 258 | + uses: actions/delete-package-versions@v4 |
| 259 | + with: |
| 260 | + package-name: "${{ env.TEST_IMAGE_PKG }}" |
| 261 | + package-type: "container" |
| 262 | + min-versions-to-keep: 5 |
0 commit comments