|
| 1 | +--- |
| 2 | +name: Pull Request CI |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - master |
| 9 | + workflow_call: |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: "pr-ci-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-and-test: |
| 18 | + name: Build and Test |
| 19 | + runs-on: ubuntu-latest |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + shell: nix develop --command bash {0} |
| 23 | + steps: |
| 24 | + - name: Check out the repo |
| 25 | + uses: actions/checkout@v5 |
| 26 | + |
| 27 | + - name: Install Nix |
| 28 | + # Pinned to v21 commit SHA for supply-chain safety. |
| 29 | + # To update: git ls-remote https://github.com/DeterminateSystems/nix-installer-action.git <tag> |
| 30 | + uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21 |
| 31 | + |
| 32 | + - name: Enable Nix cache |
| 33 | + # Pinned to v13 commit SHA for supply-chain safety. |
| 34 | + # To update: git ls-remote https://github.com/DeterminateSystems/magic-nix-cache-action.git <tag> |
| 35 | + uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13 |
| 36 | + with: |
| 37 | + use-flakehub: false |
| 38 | + |
| 39 | + - name: Build |
| 40 | + run: go build ./... |
| 41 | + |
| 42 | + - name: Run Checks |
| 43 | + run: just check |
| 44 | + env: |
| 45 | + SYSDIG_MCP_API_HOST: ${{ vars.SYSDIG_MCP_API_HOST }} |
| 46 | + SYSDIG_MCP_API_TOKEN: ${{ secrets.SYSDIG_MCP_API_SECURE_TOKEN }} |
| 47 | + |
| 48 | + test-image: |
| 49 | + name: Test Image (${{ matrix.arch }}) |
| 50 | + runs-on: ubuntu-latest |
| 51 | + needs: [build-and-test] |
| 52 | + defaults: |
| 53 | + run: |
| 54 | + shell: nix develop --command bash {0} |
| 55 | + permissions: |
| 56 | + contents: read # required for actions/checkout |
| 57 | + packages: write # required for pushing to GHCR |
| 58 | + strategy: |
| 59 | + max-parallel: 1 |
| 60 | + matrix: |
| 61 | + include: |
| 62 | + - arch: amd64 |
| 63 | + platform: linux/amd64 |
| 64 | + nix_package: sysdig-mcp-server-image-amd64 |
| 65 | + - arch: arm64 |
| 66 | + platform: linux/arm64 |
| 67 | + nix_package: sysdig-mcp-server-image-aarch64 |
| 68 | + steps: |
| 69 | + - name: Check out the repo |
| 70 | + uses: actions/checkout@v5 |
| 71 | + with: |
| 72 | + ref: ${{ github.sha }} |
| 73 | + fetch-depth: "0" |
| 74 | + |
| 75 | + - name: Install Nix |
| 76 | + # Pinned to v21 commit SHA for supply-chain safety. |
| 77 | + # To update: git ls-remote https://github.com/DeterminateSystems/nix-installer-action.git <tag> |
| 78 | + uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21 |
| 79 | + |
| 80 | + - name: Enable Nix cache |
| 81 | + # Pinned to v13 commit SHA for supply-chain safety. |
| 82 | + # To update: git ls-remote https://github.com/DeterminateSystems/magic-nix-cache-action.git <tag> |
| 83 | + uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13 |
| 84 | + with: |
| 85 | + use-flakehub: false |
| 86 | + |
| 87 | + - name: Build image |
| 88 | + run: nix build .#${{ matrix.nix_package }} -o result |
| 89 | + |
| 90 | + - name: Load image |
| 91 | + id: load |
| 92 | + run: | |
| 93 | + IMAGE_TAG=$(docker load < result | sed -n 's/Loaded image: //p') |
| 94 | + echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT |
| 95 | +
|
| 96 | + - name: Test image |
| 97 | + if: matrix.arch == 'amd64' |
| 98 | + run: docker run --rm "${{ steps.load.outputs.image_tag }}" --help | grep "Sysdig MCP Server" |
| 99 | + |
| 100 | + - name: Scan Docker image |
| 101 | + uses: sysdiglabs/scan-action@v6 |
| 102 | + with: |
| 103 | + image-tag: ${{ steps.load.outputs.image_tag }} |
| 104 | + sysdig-secure-token: ${{ secrets.SECURE_ENV_MON_API_KEY }} |
| 105 | + sysdig-secure-url: ${{ secrets.SECURE_ENV_MON_ENDPOINT }} |
| 106 | + stop-on-failed-policy-eval: true |
| 107 | + stop-on-processing-error: true |
| 108 | + |
| 109 | + - name: Convert to OCI layout |
| 110 | + run: | |
| 111 | + skopeo copy docker-archive:result oci:/tmp/oci-image:latest |
| 112 | + echo "FROM base" > /tmp/Dockerfile.push |
| 113 | +
|
| 114 | + - name: Set up Docker Buildx |
| 115 | + uses: docker/setup-buildx-action@v3 |
| 116 | + |
| 117 | + - name: Log in to GitHub Container Registry |
| 118 | + uses: docker/login-action@v3 |
| 119 | + with: |
| 120 | + registry: ghcr.io |
| 121 | + username: ${{ github.actor }} |
| 122 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + |
| 124 | + - name: Push image by digest |
| 125 | + id: push |
| 126 | + uses: docker/build-push-action@v6 |
| 127 | + with: |
| 128 | + file: /tmp/Dockerfile.push |
| 129 | + build-contexts: | |
| 130 | + base=oci-layout:///tmp/oci-image |
| 131 | + platforms: ${{ matrix.platform }} |
| 132 | + provenance: false |
| 133 | + outputs: type=image,name=ghcr.io/sysdiglabs/sysdig-mcp-server,push-by-digest=true,name-canonical=true,push=true |
| 134 | + |
| 135 | + - name: Export digest |
| 136 | + run: | |
| 137 | + mkdir -p /tmp/digests |
| 138 | + digest="${{ steps.push.outputs.digest }}" |
| 139 | + touch "/tmp/digests/${digest#sha256:}" |
| 140 | +
|
| 141 | + - name: Upload digest |
| 142 | + uses: actions/upload-artifact@v5 |
| 143 | + with: |
| 144 | + name: digests-${{ matrix.arch }} |
| 145 | + path: /tmp/digests/* |
| 146 | + if-no-files-found: error |
| 147 | + retention-days: 1 |
| 148 | + |
| 149 | + push-pr-image: |
| 150 | + name: Push PR image to GitHub Packages |
| 151 | + runs-on: ubuntu-latest |
| 152 | + needs: [test-image] |
| 153 | + if: github.event_name == 'pull_request' |
| 154 | + permissions: |
| 155 | + contents: read |
| 156 | + packages: write |
| 157 | + env: |
| 158 | + REGISTRY: ghcr.io/sysdiglabs/sysdig-mcp-server |
| 159 | + steps: |
| 160 | + - name: Download digests |
| 161 | + uses: actions/download-artifact@v6 |
| 162 | + with: |
| 163 | + path: /tmp/digests |
| 164 | + pattern: digests-* |
| 165 | + merge-multiple: true |
| 166 | + |
| 167 | + - name: Set up Docker Buildx |
| 168 | + uses: docker/setup-buildx-action@v3 |
| 169 | + |
| 170 | + - name: Log in to GitHub Container Registry |
| 171 | + uses: docker/login-action@v3 |
| 172 | + with: |
| 173 | + registry: ghcr.io |
| 174 | + username: ${{ github.actor }} |
| 175 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 176 | + |
| 177 | + - name: Create manifest list and push |
| 178 | + env: |
| 179 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 180 | + working-directory: /tmp/digests |
| 181 | + run: | |
| 182 | + docker buildx imagetools create --tag $REGISTRY:pr-${PR_NUMBER} \ |
| 183 | + $(printf "$REGISTRY@sha256:%s " *) |
| 184 | +
|
| 185 | + - name: Inspect image |
| 186 | + env: |
| 187 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 188 | + run: docker buildx imagetools inspect $REGISTRY:pr-${PR_NUMBER} |
0 commit comments