From 7adfdca12f1984b36ec6786948256c33cb11c7ae Mon Sep 17 00:00:00 2001 From: Gromit Date: Thu, 18 Jul 2024 16:45:18 +0000 Subject: [PATCH] Auto generated from templates by gromit --- .github/workflows/release.yml | 177 +++++++++++----------------------- 1 file changed, 57 insertions(+), 120 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d67c5ca94e47..1b3e30516112 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -138,7 +138,7 @@ jobs: type=semver,pattern={{version}},prefix=v - name: push image to CI if: ${{ matrix.golang_cross == '1.21-bullseye' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: "dist" platforms: linux/amd64,linux/arm64 @@ -167,7 +167,7 @@ jobs: labels: "org.opencontainers.image.title=tyk-gateway \norg.opencontainers.image.description=Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols\norg.opencontainers.image.vendor=tyk.io\norg.opencontainers.image.version=${{ github.ref_name }}\n" - name: build multiarch image if: ${{ matrix.golang_cross == '1.21-bullseye' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: "dist" platforms: linux/amd64,linux/arm64 @@ -196,7 +196,8 @@ jobs: dist/*.rpm !dist/*PAYG*.rpm test-controller-api: - needs: goreleaser + needs: + - goreleaser runs-on: ubuntu-latest outputs: envfiles: ${{ steps.params.outputs.envfiles }} @@ -207,28 +208,19 @@ jobs: id: params shell: bash env: - # Cover pull_request_target too + # startsWith covers pull_request_target too BASE_REF: ${{startsWith(github.event_name, 'pull_request') && github.base_ref || github.ref_name}} + VARIATION: test run: | set -eo pipefail - endpoint="http://tui.internal.dev.tyk.technology/api/tyk/$BASE_REF/${{ github.event_name}}/api" - curl="curl -s --retry 5 --retry-delay 10 --fail-with-body --retry-all-errors" - echo "pump<versions.env - echo '# alfa and beta have to come after the override - tyk_alfa_image=$tyk_image - tyk_beta_image=$tyk_image - ECR=${{steps.ecr.outputs.registry}} - tyk_pump_image=${{matrix.pump}} - tyk_sink_image=${{matrix.sink}} - confs_dir=./pro-ha - env_file=local-${{ matrix.envfiles.db }}.env' >> versions.env - echo "::group::versions" - cat versions.env - echo "::endgroup::" - # Add Tyk component config variations to $env_file - cat confs/${{ matrix.envfiles.config }}.env >> local-${{ matrix.envfiles.db }}.env - # bring up env, the project name is important - docker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile master-datacenter up --quiet-pull -d - ./dash-bootstrap.sh http://localhost:3000 - docker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile slave-datacenter up --quiet-pull -d - - name: Run tests - working-directory: auto + run: "match_tag=${{steps.ecr.outputs.registry}}/tyk:$BASE_REF\ntags=(${{ needs.goreleaser.outputs.tags }}) \ndocker run -q --rm -v ~/.docker/config.json:/root/.docker/config.json tykio/gromit policy match ${tags[0]} ${match_tag} 2>versions.env\necho '# alfa and beta have to come after the override\ntyk_alfa_image=$tyk_image\ntyk_beta_image=$tyk_image\nECR=${{steps.ecr.outputs.registry}}\ntyk_pump_image=${{matrix.pump}}\ntyk_sink_image=${{matrix.sink}}\nconfs_dir=./pro-ha\nenv_file=local.env' >> versions.env\necho \"::group::versions\"\ncat versions.env\necho \"::endgroup::\"\n# Add Tyk component config variations to $env_file\ncat confs/${{ matrix.envfiles.config }}.env >> local.env\n# bring up env, the project name is important\ndocker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile master-datacenter up --quiet-pull -d\n./dash-bootstrap.sh http://localhost:3000\ndocker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile slave-datacenter up --quiet-pull -d \n" + - name: Run API tests id: test_execution env: # Cover pull_request_target too BASE_REF: ${{startsWith(github.event_name, 'pull_request') && github.base_ref || github.ref_name }} - run: | - # Generate report id - echo "id=$(date +%s%N)" >> $GITHUB_OUTPUT - # Run tests - set -o pipefail - echo "### API tests ${{ matrix.envfiles.db }} ${{ matrix.envfiles.conf }}" >> $GITHUB_STEP_SUMMARY - if docker run --rm --network auto_default --env-file pytest.env -v ${{ github.workspace }}/reports:/app/reports \ - ${{ steps.ecr.outputs.registry }}/tyk-automated-tests:$BASE_REF \ - pytest -c pytest_ci.ini --junitxml=./${XUNIT_REPORT_PATH#"${{ github.workspace }}"} --ci -m "not local and not dind ${{ matrix.markers }}" | tee tests.out; then - echo "All tests passed!" >> $GITHUB_STEP_SUMMARY - else - echo "::error title=API tests ${{ matrix.envfiles.db }} ${{ matrix.envfiles.conf }}::Test execution failed" - cat tests.out >> $GITHUB_STEP_SUMMARY - exit 1 - fi - - name: Generate metadata + run: "# Generate report id\necho \"id=$(date +%s%N)\" >> $GITHUB_OUTPUT\ncommon_cmd=\"\"\ncmd=\"docker run --rm --network auto_default --env-file pytest.env -v ${{ github.workspace }}/reports:/app/reports\n ${{ steps.ecr.outputs.registry }}/tyk-automated-tests:$BASE_REF\n pytest -c pytest_ci.ini --junitxml=./${XUNIT_REPORT_PATH --ci -m ${{ matrix.envfiles.apimarkers }} | tee tests.out\" \n# Run tests\nset -o pipefail\necho \"### API tests ${{ matrix.envfiles.db }} ${{ matrix.envfiles.conf }}\" >> $GITHUB_STEP_SUMMARY\nif $cmd; then\n echo \"All tests passed!\" >> $GITHUB_STEP_SUMMARY\nelse\n echo \"::error title=API tests ${{ matrix.envfiles.db }} ${{ matrix.envfiles.conf }}::Test execution failed\"\n cat tests.out >> $GITHUB_STEP_SUMMARY\n exit 1\nfi \n" + - name: Generate metadata and upload test reports if: always() && steps.test_execution.outcome != 'skipped' id: metadata_report env: BASE_REF: ${{startsWith(github.event_name, 'pull_request') && github.base_ref || github.ref}} REPORT_NAME: ${{ github.repository }}_${{ github.run_id }}_${{ github.run_attempt }}-${{steps.test_execution.outputs.id}} + METADATA_REPORT_PATH: /tmp/metadata.toml run: | # Generate metadata report echo "[metadata] @@ -364,11 +319,11 @@ jobs: TYK_MDCB_LICENSE: ${{ secrets.MDCB_LICENSE }} ECR: ${{ steps.ecr.outputs.registry }} run: | - docker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile all logs | sort > ${{ github.workspace }}/docker-compose.log + docker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile all logs | sort > ${{ github.workspace }}/docker-compose.log echo "::group::DockerLogs" cat ${{ github.workspace }}/docker-compose.log echo "::endgroup::" - - name: Upload Artifact + - name: Upload compose logs uses: actions/upload-artifact@v4 if: failure() && (steps.test_execution.outcome != 'success' || steps.env_up.outcome != 'success') with: @@ -376,33 +331,39 @@ jobs: path: ${{ github.workspace }}/docker-compose.log retention-days: 3 overwrite: true - - name: Archive Integration tests report - if: always() - uses: actions/upload-artifact@v4 - with: - name: api-test-report-${{ matrix.envfiles.db }}-${{ matrix.envfiles.conf }}-${{ github.run_id }} - retention-days: 3 - path: ${{ github.workspace }}/reports - overwrite: true + test-controller-distros: + needs: + - goreleaser + runs-on: ubuntu-latest + outputs: + deb: ${{ steps.params.outputs.deb }} + rpm: ${{ steps.params.outputs.rpm }} + steps: + - name: set params + id: params + shell: bash + env: + # startsWith covers pull_request_target too + BASE_REF: ${{startsWith(github.event_name, 'pull_request') && github.base_ref || github.ref_name}} + VARIATION: test + run: | + set -eo pipefail + curl -s --retry 5 --retry-delay 10 --fail-with-body "http://tui.internal.dev.tyk.technology/v2/$VARIATION/tyk/$BASE_REF/${{ github.event_name}}/api/Distros.gho" | tee -a "$GITHUB_OUTPUT" + [[ $VARIATION =~ test ]] && echo "::warning file=release.yml,line=100,col=5,endColumn=7::Using test variation" upgrade-deb: services: httpbin.org: image: kennethreitz/httpbin runs-on: ubuntu-latest - needs: goreleaser + needs: + - test-controller-distros strategy: - fail-fast: false + fail-fast: true matrix: arch: - amd64 - arm64 - distro: - - ubuntu:xenial - - ubuntu:bionic - - ubuntu:focal - - ubuntu:jammy - - debian:bullseye - - debian:bookworm + distro: ${{ fromJson(needs.test-controller-distros.outputs.deb) }} steps: - uses: actions/checkout@v4 with: @@ -413,19 +374,9 @@ jobs: - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - name: generate dockerfile - run: | - echo 'FROM ${{ matrix.distro }} - ARG TARGETARCH - COPY tyk-gateway*_${TARGETARCH}.deb /tyk-gateway.deb - RUN apt-get update && apt-get install -y curl - RUN curl -fsSL https://packagecloud.io/install/repositories/tyk/tyk-gateway/script.deb.sh | bash && apt-get install -y tyk-gateway=3.0.8 - RUN dpkg -i tyk-gateway.deb - RUN /opt/tyk-gateway/install/setup.sh --listenport=8080 --redishost=localhost --redisport=6379 --domain="" - COPY ci/tests/api-functionality/data/api.json /opt/tyk-gateway/apps/ - CMD ["/opt/tyk-gateway/tyk", "--conf", "/opt/tyk-gateway/tyk.conf"] - ' > Dockerfile + run: "echo 'FROM ${{ matrix.distro }}\nARG TARGETARCH\nCOPY tyk-gateway*_${TARGETARCH}.deb /tyk-gateway.deb\nRUN apt-get update && apt-get install -y curl\nRUN curl -fsSL https://packagecloud.io/install/repositories/tyk/tyk-gateway/script.deb.sh | bash && apt-get install -y tyk-gateway=3.0.8\nRUN dpkg -i tyk-gateway.deb \nRUN /opt/tyk-gateway/install/setup.sh --listenport=8080 --redishost=localhost --redisport=6379 --domain=\"\"\nCOPY ci/tests/api-functionality/data/api.json /opt/tyk-gateway/apps/\nCMD [\"/opt/tyk-gateway/tyk\", \"--conf\", \"/opt/tyk-gateway/tyk.conf\"]\n' > Dockerfile\n" - name: install on ${{ matrix.distro }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: "." platforms: linux/${{ matrix.arch }} @@ -442,52 +393,38 @@ jobs: services: httpbin.org: image: kennethreitz/httpbin - needs: goreleaser runs-on: ubuntu-latest + needs: + - test-controller-distros strategy: - fail-fast: false + fail-fast: true matrix: - distro: - - amazonlinux:2023 - - registry.access.redhat.com/ubi8/ubi - - registry.access.redhat.com/ubi9/ubi - - amazonlinux:2 - - registry.access.redhat.com/ubi7/ubi + arch: + - amd64 + - arm64 + distro: ${{ fromJson(needs.test-controller-distros.outputs.rpm) }} steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - uses: actions/download-artifact@v4 with: - name: rpm + name: deb + - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - name: generate dockerfile - run: | - echo 'FROM ${{ matrix.distro }} - COPY tyk-gateway*.x86_64.rpm /tyk-gateway.rpm - RUN command -v curl || yum install -y curl - RUN command -v useradd || yum install -y shadow-utils - RUN curl -fsSL https://packagecloud.io/install/repositories/tyk/tyk-gateway/script.rpm.sh | bash && yum install -y tyk-gateway-3.0.8-1 - RUN curl https://keyserver.tyk.io/tyk.io.rpm.signing.key.2020 -o tyk-gateway.key && rpm --import tyk-gateway.key - RUN rpm --checksig tyk-gateway.rpm - RUN rpm -Uvh --force tyk-gateway.rpm - RUN /opt/tyk-gateway/install/setup.sh --listenport=8080 --redishost=localhost --redisport=6379 --domain="" - COPY ci/tests/api-functionality/data/api.json /opt/tyk-gateway/apps/ - CMD ["/opt/tyk-gateway/tyk", "--conf", "/opt/tyk-gateway/tyk.conf"] - ' > Dockerfile + run: "echo 'FROM ${{ matrix.distro }}\nCOPY tyk-gateway*.x86_64.rpm /tyk-gateway.rpm\nRUN command -v curl || yum install -y curl\nRUN command -v useradd || yum install -y shadow-utils\nRUN curl -fsSL https://packagecloud.io/install/repositories/tyk/tyk-gateway/script.rpm.sh | bash && yum install -y tyk-gateway-3.0.8-1\nRUN curl https://keyserver.tyk.io/tyk.io.rpm.signing.key.2020 -o tyk-gateway.key && rpm --import tyk-gateway.key\nRUN rpm --checksig tyk-gateway.rpm\nRUN rpm -Uvh --force tyk-gateway.rpm \nRUN /opt/tyk-gateway/install/setup.sh --listenport=8080 --redishost=localhost --redisport=6379 --domain=\"\"\nCOPY ci/tests/api-functionality/data/api.json /opt/tyk-gateway/apps/\nCMD [\"/opt/tyk-gateway/tyk\", \"--conf\", \"/opt/tyk-gateway/tyk.conf\"]\n' > Dockerfile\n" - name: install on ${{ matrix.distro }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: "." + platforms: linux/${{ matrix.arch }} file: Dockerfile push: false - tags: test # matrix.distro for ubi has invalid chars for a tag + tags: test-${{ matrix.distro }}-${{ matrix.arch }} load: true - name: Test the built container image with api functionality test. - run: | - docker run -d -p8080:8080 --network ${{ job.container.network }} --rm test - sleep 2 - ./ci/tests/api-functionality/api_test.sh + run: "docker run -d -p8080:8080 --network ${{ job.container.network }} --rm test-${{ matrix.distro }}-${{ matrix.arch }}\nsleep 2\n./ci/tests/api-functionality/api_test.sh \n" release-tests: needs: - goreleaser