From 03cf550a53609e92ff1476a05505ab4e8625e2d4 Mon Sep 17 00:00:00 2001 From: Anthony Rabbito Date: Tue, 1 Oct 2024 17:08:07 -0400 Subject: [PATCH] Add image build CI (#2) * feat: add image build CI Signed-off-by: Anthony Rabbito * chore: drop all upstream CI Signed-off-by: Anthony Rabbito * fix: logging into registry twice Signed-off-by: Anthony Rabbito --------- Signed-off-by: Anthony Rabbito --- .github/workflows/build.yaml | 107 ------------------------ .github/workflows/check_doc.yml | 25 ------ .github/workflows/codeql.yml | 70 ---------------- .github/workflows/documentation.yml | 52 ------------ .github/workflows/experimental.yaml | 68 --------------- .github/workflows/publish-image.yml | 55 ++++++++++++ .github/workflows/test-integration.yaml | 76 ----------------- .github/workflows/test-unit.yaml | 56 ------------- .github/workflows/validate.yaml | 68 --------------- 9 files changed, 55 insertions(+), 522 deletions(-) delete mode 100644 .github/workflows/build.yaml delete mode 100644 .github/workflows/check_doc.yml delete mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/documentation.yml delete mode 100644 .github/workflows/experimental.yaml create mode 100644 .github/workflows/publish-image.yml delete mode 100644 .github/workflows/test-integration.yaml delete mode 100644 .github/workflows/test-unit.yaml delete mode 100644 .github/workflows/validate.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 022db925ce..0000000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,107 +0,0 @@ -name: Build Binaries - -on: - pull_request: - branches: - - '*' - paths-ignore: - - 'docs/**' - - '**.md' - - 'script/gcg/**' - -env: - GO_VERSION: '1.23' - CGO_ENABLED: 0 - -jobs: - - build-webui: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version-file: webui/.nvmrc - cache: yarn - cache-dependency-path: webui/yarn.lock - - - name: Build webui - working-directory: ./webui - run: | - yarn install - yarn build - - - name: Package webui - run: | - tar czvf webui.tar.gz ./webui/static/ - - - name: Artifact webui - uses: actions/upload-artifact@v4 - with: - name: webui.tar.gz - path: webui.tar.gz - - build: - runs-on: ubuntu-latest - - strategy: - matrix: - os: [ darwin, freebsd, linux, openbsd, windows ] - arch: [ amd64, arm64 ] - include: - - os: freebsd - arch: 386 - - os: linux - arch: 386 - - os: linux - arch: arm - goarm: 6 - - os: linux - arch: arm - goarm: 7 - - os: linux - arch: ppc64le - - os: linux - arch: riscv64 - - os: linux - arch: s390x - - os: openbsd - arch: 386 - - os: windows - arch: 386 - needs: - - build-webui - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - env: - ImageOS: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.goarm }} - with: - go-version: ${{ env.GO_VERSION }} - - - name: Artifact webui - uses: actions/download-artifact@v4 - with: - name: webui.tar.gz - - - name: Untar webui - run: tar xvf webui.tar.gz - - - name: Build - env: - GOOS: ${{ matrix.os }} - GOARCH: ${{ matrix.arch }} - GOARM: ${{ matrix.goarm }} - run: make binary diff --git a/.github/workflows/check_doc.yml b/.github/workflows/check_doc.yml deleted file mode 100644 index c5fbddcec1..0000000000 --- a/.github/workflows/check_doc.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Check Documentation - -on: - pull_request: - branches: - - '*' - -jobs: - - docs: - name: Check, verify and build documentation - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Check documentation - run: make docs-pull-images docs - env: - # These variables are not passed to workflows that are triggered by a pull request from a fork. - DOCS_VERIFY_SKIP: ${{ vars.DOCS_VERIFY_SKIP }} - DOCS_LINT_SKIP: ${{ vars.DOCS_LINT_SKIP }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index f921d77893..0000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: - - master - - v* - schedule: - - cron: '11 22 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript', 'go' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Use only 'java' to analyze code written in Java, Kotlin or both - # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: setup go - uses: actions/setup-go@v5 - if: ${{ matrix.language == 'go' }} - with: - go-version-file: 'go.mod' - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml deleted file mode 100644 index c278889e4f..0000000000 --- a/.github/workflows/documentation.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build and Publish Documentation - -on: - push: - branches: - - master - - v* - -env: - STRUCTOR_VERSION: v1.13.2 - MIXTUS_VERSION: v0.4.1 - -jobs: - - docs: - name: Doc Process - runs-on: ubuntu-latest - if: github.repository == 'traefik/traefik' - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Install Structor ${{ env.STRUCTOR_VERSION }} - run: curl -sSfL https://raw.githubusercontent.com/traefik/structor/master/godownloader.sh | sh -s -- -b $HOME/bin ${STRUCTOR_VERSION} - - - name: Install Seo-doc - run: curl -sSfL https://raw.githubusercontent.com/traefik/seo-doc/master/godownloader.sh | sh -s -- -b "${HOME}/bin" - - - name: Install Mixtus ${{ env.MIXTUS_VERSION }} - run: curl -sSfL https://raw.githubusercontent.com/traefik/mixtus/master/godownloader.sh | sh -s -- -b $HOME/bin ${MIXTUS_VERSION} - - - name: Build documentation - run: $HOME/bin/structor -o traefik -r traefik --dockerfile-url="https://raw.githubusercontent.com/traefik/traefik/v1.7/docs.Dockerfile" --menu.js-url="https://raw.githubusercontent.com/traefik/structor/master/traefik-menu.js.gotmpl" --rqts-url="https://raw.githubusercontent.com/traefik/structor/master/requirements-override.txt" --force-edit-url --exp-branch=master --debug - env: - STRUCTOR_LATEST_TAG: ${{ vars.STRUCTOR_LATEST_TAG }} - - - name: Apply seo - run: $HOME/bin/seo -path=./site -product=traefik - - - name: Publish documentation - run: $HOME/bin/mixtus --dst-doc-path="./traefik" --dst-owner=traefik --dst-repo-name=doc --git-user-email="30906710+traefiker@users.noreply.github.com" --git-user-name=traefiker --src-doc-path="./site" --src-owner=containous --src-repo-name=traefik - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} diff --git a/.github/workflows/experimental.yaml b/.github/workflows/experimental.yaml deleted file mode 100644 index aadce96a80..0000000000 --- a/.github/workflows/experimental.yaml +++ /dev/null @@ -1,68 +0,0 @@ -name: Build experimental image on branch - -on: - push: - branches: - - master - - v* - -env: - GO_VERSION: '1.23' - CGO_ENABLED: 0 - -jobs: - - experimental: - if: github.repository == 'traefik/traefik' - name: Build experimental image on branch - runs-on: ubuntu-latest - - steps: - - # https://github.com/marketplace/actions/checkout - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version-file: webui/.nvmrc - cache: yarn - cache-dependency-path: webui/yarn.lock - - - name: Build webui - working-directory: ./webui - run: | - yarn install - yarn build - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Build - run: make generate binary - - - name: Branch name - run: echo ${GITHUB_REF##*/} - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build docker experimental image - env: - DOCKER_BUILDX_ARGS: "--push" - run: | - make multi-arch-image-experimental-${GITHUB_REF##*/} diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000000..b722288bea --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,55 @@ +--- + # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + name: "Container: Image Build" + on: + workflow_dispatch: + inputs: + version: + description: Version to tag the container with + required: true + type: string + publish: + description: Publish the container to the registry + required: true + type: boolean + default: false + + jobs: + publish-images: + name: Publish Image + permissions: + contents: write + packages: write + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log into registry ghcr.io + uses: docker/login-action@v3.3.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.6.1 + + - name: Build and publish image + env: + DOCKER_BUILDX_ARGS: "--load --cache-from type=gha --cache-to type=gha,mode=max" + run: | + make build-webui-image + make build-image-dirty + + - name: Push image + if: ${{inputs.publish}} + run: | + docker tag traefik/traefik ghcr.io/${{ github.repository }}:${{ inputs.version }}-${GITHUB_SHA::7} + docker push ghcr.io/${{ github.repository }}:${{ inputs.version }}-${GITHUB_SHA::7} diff --git a/.github/workflows/test-integration.yaml b/.github/workflows/test-integration.yaml deleted file mode 100644 index 10fe2ca44a..0000000000 --- a/.github/workflows/test-integration.yaml +++ /dev/null @@ -1,76 +0,0 @@ -name: Test Integration - -on: - pull_request: - branches: - - '*' - paths-ignore: - - 'docs/**' - - '**.md' - - 'script/gcg/**' - -env: - GO_VERSION: '1.23' - CGO_ENABLED: 0 - -jobs: - - build: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Avoid generating webui - run: touch webui/static/index.html - - - name: Build binary - run: make binary - - test-integration: - runs-on: ubuntu-latest - needs: - - build - strategy: - fail-fast: true - matrix: - parallel: [12] - index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Avoid generating webui - run: touch webui/static/index.html - - - name: Build binary - run: make binary - - - name: Generate go test Slice - id: test_split - uses: hashicorp-forge/go-test-split-action@v2.0.0 - with: - packages: ./integration - total: ${{ matrix.parallel }} - index: ${{ matrix.index }} - - - name: Run Integration tests - run: | - TESTS=$(echo "${{ steps.test_split.outputs.run}}" | sed 's/\$/\$\$/g') - TESTFLAGS="-run \"${TESTS}\"" make test-integration diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml deleted file mode 100644 index 5550ec1cd1..0000000000 --- a/.github/workflows/test-unit.yaml +++ /dev/null @@ -1,56 +0,0 @@ -name: Test Unit - -on: - pull_request: - branches: - - '*' - paths-ignore: - - 'docs/**' - - '**.md' - - 'script/gcg/**' - -env: - GO_VERSION: '1.23' - -jobs: - - test-unit: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Avoid generating webui - run: touch webui/static/index.html - - - name: Tests - run: make test-unit - - test-ui-unit: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@v4 - with: - node-version-file: webui/.nvmrc - cache: 'yarn' - cache-dependency-path: webui/yarn.lock - - - name: UI unit tests - run: | - yarn --cwd webui install - yarn --cwd webui test:unit:ci diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml deleted file mode 100644 index b7195defaa..0000000000 --- a/.github/workflows/validate.yaml +++ /dev/null @@ -1,68 +0,0 @@ -name: Validate - -on: - pull_request: - branches: - - '*' - -env: - GO_VERSION: '1.23' - GOLANGCI_LINT_VERSION: v1.60.3 - MISSPELL_VERSION: v0.6.0 - -jobs: - - validate: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} - - - name: Install misspell ${{ env.MISSPELL_VERSION }} - run: curl -sfL https://raw.githubusercontent.com/golangci/misspell/master/install-misspell.sh | sh -s -- -b $(go env GOPATH)/bin ${MISSPELL_VERSION} - - - name: Avoid generating webui - run: touch webui/static/index.html - - - name: Validate - run: make validate - - validate-generate: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go ${{ env.GO_VERSION }} - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: go generate - run: | - make generate - git diff --exit-code - - - name: go mod tidy - run: | - go mod tidy - git diff --exit-code - - - name: make generate-crd - run: | - make generate-crd - git diff --exit-code