Build Webhooks image #207
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 Webhooks image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| push_mage: | |
| description: 'Push images' | |
| required: false | |
| type: boolean | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - "webhooks/**" | |
| - ".github/workflows/webhooks.yml" | |
| - "!**/*.md" | |
| - "!**/*.yaml" | |
| pull_request: | |
| branches: [ "*" ] | |
| paths: | |
| - "webhooks/**" | |
| - ".github/workflows/webhooks.yml" | |
| - "!**/*.md" | |
| - "!**/*.yaml" | |
| env: | |
| # Common versions | |
| GO_VERSION: "1.22" | |
| DEFAULT_OWNER: "labring" | |
| jobs: | |
| resolve-modules: | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Resolve Modules | |
| id: set-matrix | |
| run: bash ./scripts/resolve-modules.sh ./webhooks | |
| golangci-lint: | |
| needs: [ resolve-modules ] | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Golang with cache | |
| uses: magnetikonline/action-golang-cache@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Install Dependencies | |
| run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev | |
| - name: Run Linter | |
| uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: v1.64.5 | |
| working-directory: ${{ matrix.workdir }} | |
| args: "--out-${NO_FUTURE}format colored-line-number" | |
| image-build: | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| module: [ admission ] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Golang with cache | |
| uses: magnetikonline/action-golang-cache@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Install Dependencies | |
| run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev | |
| - name: Build ${{ matrix.module }} amd64 | |
| working-directory: webhooks/${{ matrix.module }} | |
| env: | |
| MODULE: ${{ matrix.module }} | |
| run: | | |
| GOARCH=amd64 make build | |
| mv bin/manager "bin/webhook-${MODULE}-amd64" | |
| chmod +x "bin/webhook-${MODULE}-amd64" | |
| - name: Build ${{ matrix.module }} arm64 | |
| working-directory: webhooks/${{ matrix.module }} | |
| env: | |
| MODULE: ${{ matrix.module }} | |
| run: | | |
| GOARCH=arm64 make build | |
| mv bin/manager "bin/webhook-${MODULE}-arm64" | |
| chmod +x "bin/webhook-${MODULE}-arm64" | |
| - name: Prepare | |
| id: prepare | |
| run: | | |
| TAG=latest | |
| echo tag_name=${TAG} >> $GITHUB_OUTPUT | |
| - # Add support for more platforms with QEMU (optional) | |
| # https://github.com/docker/setup-qemu-action | |
| name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver-opts: network=host | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| if: ${{ (github.event_name == 'push') || (inputs.push_mage == true) }} | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: build (and publish) ${{ matrix.module }} main image | |
| if: ${{ (github.event_name == 'push') || (inputs.push_mage == true) }} | |
| env: | |
| MODULE: ${{ matrix.module }} | |
| REPOSITORY_OWNER: ${{ github.repository_owner }} | |
| DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module }}-webhook | |
| TAG_NAME: ${{ steps.prepare.outputs.tag_name }} | |
| working-directory: webhooks/${{ matrix.module }} | |
| run: | | |
| docker buildx build \ | |
| --platform linux/amd64,linux/arm64 \ | |
| --label "org.opencontainers.image.source=https://github.com/${REPOSITORY_OWNER}/sealos" \ | |
| --label "org.opencontainers.image.description=sealos-${MODULE}-webhook container image" \ | |
| --label "org.opencontainers.image.licenses=MIT" \ | |
| --push \ | |
| -t "${DOCKER_REPO}:${TAG_NAME}" \ | |
| -f Dockerfile \ | |
| . | |
| - name: build ${{ matrix.module }} image | |
| if: ${{ github.event_name == 'pull_request' }} | |
| env: | |
| MODULE: ${{ matrix.module }} | |
| REPOSITORY_OWNER: ${{ github.repository_owner }} | |
| DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module }}-webhook | |
| TAG_NAME: ${{ steps.prepare.outputs.tag_name }} | |
| working-directory: webhooks/${{ matrix.module }} | |
| run: | | |
| docker buildx build \ | |
| --platform linux/amd64,linux/arm64 \ | |
| --label "org.opencontainers.image.source=https://github.com/${REPOSITORY_OWNER}/sealos" \ | |
| --label "org.opencontainers.image.description=sealos-${MODULE}-webhook container image" \ | |
| --label "org.opencontainers.image.licenses=MIT" \ | |
| -t "${DOCKER_REPO}:${TAG_NAME}" \ | |
| -f Dockerfile \ | |
| . |