github.com/nginxinc/kubernetes-ingress@v1.12.5/.github/workflows/nightly.yml (about)

     1  name: Nightly
     2  
     3  on:
     4    schedule:
     5      - cron:  '0 4 * * *'
     6  
     7  defaults:
     8    run:
     9      shell: bash
    10  
    11  env:
    12    DOCKER_BUILDKIT: 1
    13    K8S_TIMEOUT: 90s
    14    HELM_CHART_DIR: deployments/helm-chart
    15    HELM_CHART_VERSION: 0.0.0-edge
    16    VERSION: nightly
    17  
    18  jobs:
    19  
    20    binary:
    21      name: Build Binary
    22      runs-on: ubuntu-20.04
    23      steps:
    24        - name: Checkout Repository
    25          uses: actions/checkout@v2
    26          with:
    27            fetch-depth: 0
    28        - name: Output Variables
    29          id: commit
    30          run: |
    31            echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
    32        - name: Determine Go version from go.mod
    33          run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
    34        - name: Setup Golang Environment
    35          uses: actions/setup-go@v2
    36          with:
    37            go-version: ${{ env.GO_VERSION }}
    38        - name: Determine GOPATH
    39          run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
    40        - name: Check if CRDs changed
    41          run: |
    42            make update-crds && git diff --name-only --exit-code deployments/common/crds* deployments/helm-chart/crds*
    43        - name: Check if Codegen changed
    44          run: |
    45            make update-codegen && git diff --name-only --exit-code pkg/**/zz_generated.deepcopy.go
    46        - name: Build binaries
    47          uses: goreleaser/goreleaser-action@v2
    48          with:
    49            version: latest
    50            args: --rm-dist --debug --skip-publish --snapshot
    51          env:
    52            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    53            GOPATH: ${{ env.GOPATH }}
    54        - name: Store Artifacts in Cache
    55          uses: actions/cache@v2
    56          with:
    57            path: ${{ github.workspace }}/dist
    58            key: nginx-ingress-${{ github.run_id }}-${{ github.run_number }}
    59  
    60    unit-tests:
    61      name: Unit Tests
    62      runs-on: ubuntu-20.04
    63      steps:
    64        - name: Checkout Repository
    65          uses: actions/checkout@v2
    66        - name: Determine Go version from go.mod
    67          run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
    68        - name: Setup Golang Environment
    69          uses: actions/setup-go@v2
    70          with:
    71            go-version: ${{ env.GO_VERSION }}
    72        - name: Run Tests
    73          run: go test ./...
    74  
    75    build:
    76      name: Build Docker Images
    77      runs-on: ubuntu-20.04
    78      needs: [binary, unit-tests]
    79      strategy:
    80        matrix:
    81          image: [debian, alpine, opentracing, ubi]
    82      steps:
    83        - name: Checkout Repository
    84          uses: actions/checkout@v2
    85        - name: Output Variables
    86          id: commit
    87          run: |
    88            echo "::set-output name=nginx_version::$(cat build/Dockerfile | grep -m1 "FROM nginx:" | cut -d":" -f2 | cut -d" " -f1)"
    89        - name: Fetch Cached Artifacts
    90          uses: actions/cache@v2
    91          with:
    92            path: ${{ github.workspace }}/dist
    93            key: nginx-ingress-${{ github.run_id }}-${{ github.run_number }}
    94        - name: Docker Buildx
    95          uses: docker/setup-buildx-action@v1
    96          with:
    97            driver-opts: network=host
    98        - name: Cache Docker layers
    99          uses: actions/cache@v2
   100          with:
   101            path: /tmp/.buildx-cache
   102            key: ${{ runner.os }}-buildx-${{ github.sha }}
   103            restore-keys: |
   104              ${{ runner.os }}-buildx-
   105        - name: Build Docker Image ${{ matrix.image }}
   106          uses: docker/build-push-action@v2
   107          with:
   108            file: build/Dockerfile
   109            context: .
   110            cache-from: type=local,src=/tmp/.buildx-cache
   111            cache-to: type=local,dest=/tmp/.buildx-cache
   112            target: goreleaser
   113            tags: ${{ matrix.image }}:${{ github.sha }}
   114            build-args: |
   115              BUILD_OS=${{ matrix.image }}
   116              NGINX_VERSION=${{ steps.commit.outputs.nginx_version }}
   117  
   118    smoke-tests:
   119      name: Nightly Smoke Tests
   120      runs-on: ubuntu-20.04
   121      needs: [build, binary, unit-tests]
   122      strategy:
   123        matrix:
   124          k8s: [1.20.2, 1.19.1, 1.18.8, 1.17.11, 1.16.15]
   125      steps:
   126        - name: Checkout Repository
   127          uses: actions/checkout@v2
   128        - name: Fetch Cached Artifacts
   129          uses: actions/cache@v2
   130          with:
   131            path: ${{ github.workspace }}/dist
   132            key: nginx-ingress-${{ github.run_id }}-${{ github.run_number }}
   133        - name: Docker Buildx
   134          uses: docker/setup-buildx-action@v1
   135          with:
   136            driver-opts: network=host
   137        - name: Cache Docker layers
   138          uses: actions/cache@v2
   139          with:
   140            path: /tmp/.buildx-cache
   141            key: ${{ runner.os }}-buildx-${{ github.sha }}
   142            restore-keys: |
   143              ${{ runner.os }}-buildx-
   144        - name: Build debian Container
   145          uses: docker/build-push-action@v2
   146          with:
   147            file: build/Dockerfile
   148            context: '.'
   149            cache-from: type=local,src=/tmp/.buildx-cache
   150            cache-to: type=local,dest=/tmp/.buildx-cache
   151            target: goreleaser
   152            tags: nginx-ingress:${{ github.sha }}
   153            load: true
   154            build-args: |
   155              BUILD_OS=debian
   156        - name: Build Test-Runner Container
   157          uses: docker/build-push-action@v2
   158          with:
   159            file: tests/docker/Dockerfile
   160            context: '.'
   161            cache-from: type=local,src=/tmp/.buildx-cache
   162            cache-to: type=local,dest=/tmp/.buildx-cache
   163            tags: test-runner:${{ github.sha }}
   164            load: true
   165        - name: Deploy Kubernetes
   166          id: k8s
   167          run: |
   168            kind create cluster --name ${{ github.run_id }} --image=kindest/node:v${{ matrix.k8s }} --config ${{ github.workspace }}/tests/ci-files/ci-kind-config.yaml --kubeconfig kube-${{ github.run_id }} --wait ${{ env.K8S_TIMEOUT }}
   169            kind load docker-image nginx-ingress:${{ github.sha }} --name ${{ github.run_id }}
   170            echo ::set-output name=cluster_ip::$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${{ github.run_id }}-control-plane)
   171            echo ::set-output name=cluster::$(echo 'nginx-oss')
   172        - name: Setup Kubeconfig
   173          run: |
   174            sed -i 's|server:.*|server: https://${{ steps.k8s.outputs.cluster_ip }}:6443|' kube-${{ github.run_id }}
   175        - name: Run Smoke Tests
   176          run: |
   177            touch tests-${{ steps.k8s.outputs.cluster }}.html
   178            docker run --rm \
   179            --name test-runner-${{ github.run_id }} \
   180            --network=kind \
   181            -v ${{ github.workspace }}/tests/tests-${{ steps.k8s.outputs.cluster }}.html:/workspace/tests/tests-${{ steps.k8s.outputs.cluster }}.html \
   182            -v ${{ github.workspace }}/kube-${{ github.run_id }}:/root/.kube/config test-runner:${{ github.sha }} \
   183            --context=kind-${{ github.run_id }} \
   184            --image=nginx-ingress:${{ github.sha }} \
   185            --image-pull-policy=Never \
   186            --ic-type=nginx-ingress \
   187            --service=nodeport --node-ip=${{ steps.k8s.outputs.cluster_ip }} \
   188            --html=tests-${{ steps.k8s.outputs.cluster }}.html \
   189            --self-contained-html
   190          working-directory: ./tests
   191        - name: Upload Test Results
   192          uses: actions/upload-artifact@v2
   193          with:
   194            name: test-results-${{ steps.k8s.outputs.cluster }}-${{ matrix.k8s }}
   195            path: ${{ github.workspace }}/tests/tests-${{ steps.k8s.outputs.cluster }}.html
   196          if: always()
   197  
   198    helm-tests:
   199      name: Helm Tests
   200      runs-on: ubuntu-20.04
   201      needs: [binary, build, unit-tests]
   202      env:
   203        NGINX_HTTP_PORT: 8080
   204        NGINX_HTTPS_PORT: 8443
   205        HELM_TEST_RETRIES: 5
   206        HELM_HTTP_POSTFIX: s
   207      steps:
   208        - name: Checkout Repository
   209          uses: actions/checkout@v2
   210        - name: Fetch Cached Artifacts
   211          uses: actions/cache@v2
   212          with:
   213            path: ${{ github.workspace }}/dist
   214            key: nginx-ingress-${{ github.run_id }}-${{ github.run_number }}
   215        - name: Docker Buildx
   216          uses: docker/setup-buildx-action@v1
   217          with:
   218            driver-opts: network=host
   219        - name: Docker build cache
   220          uses: actions/cache@v2
   221          with:
   222            path: /tmp/.buildx-cache
   223            key: ${{ runner.os }}-buildx-${{ github.sha }}
   224            restore-keys: |
   225              ${{ runner.os }}-buildx-
   226        - name: Build Docker Image nginx-ingress
   227          uses: docker/build-push-action@v2
   228          with:
   229            file: build/Dockerfile
   230            context: '.'
   231            cache-from: type=local,src=/tmp/.buildx-cache
   232            cache-to: type=local,dest=/tmp/.buildx-cache
   233            target: goreleaser
   234            tags: nginx-ingress:${{ github.sha }}
   235            load: true
   236            build-args: |
   237              BUILD_OS=debian
   238        - name: Deploy Kubernetes
   239          id: k8s
   240          run: |
   241            kind create cluster --name ${{ github.run_id }} --wait ${{ env.K8S_TIMEOUT }}
   242            kind load docker-image nginx-ingress:${{ github.sha }} --name ${{ github.run_id }}
   243        - name: Install Chart
   244          run: >
   245            helm install
   246            oss
   247            .
   248            --set controller.image.repository=nginx-ingress
   249            --set controller.image.tag=${{ github.sha }}
   250            --set controller.service.type=NodePort
   251            --set controller.nginxplus=false
   252            --wait
   253          working-directory: ${{ github.workspace }}/deployments/helm-chart
   254        - name: Expose Test Ingresses
   255          run: |
   256            kubectl port-forward service/oss-nginx-ingress ${{ env.NGINX_HTTP_PORT }}:80 &
   257            kubectl port-forward service/oss-nginx-ingress ${{ env.NGINX_HTTPS_PORT }}:443 &
   258        - name: Test HTTP
   259          run: |
   260            . tests/ci-files/helm-http-test.sh ${{ env.HELM_TEST_RETRIES }} ${{ env.NGINX_HTTP_PORT }}
   261        - name: Test HTTPS
   262          run: |
   263            . tests/ci-files/helm-http-test.sh ${{ env.HELM_TEST_RETRIES }} ${{ env.NGINX_HTTPS_PORT }} ${{ env.HELM_HTTP_POSTFIX }}
   264  
   265    notify:
   266      name: Notify
   267      runs-on: ubuntu-20.04
   268      needs: [helm-tests, smoke-tests]
   269      if: always() && github.ref == 'refs/heads/master'
   270      steps:
   271        - name: Workflow Status
   272          id: check
   273          uses: martialonline/workflow-status@v2
   274        - name: Output Variables
   275          id: commit
   276          run: |
   277            echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
   278            echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
   279        - name: Send Notification
   280          uses: 8398a7/action-slack@v3
   281          if:
   282            steps.check.outputs.status == 'failure' ||
   283            steps.check.outputs.status == 'cancelled'
   284          with:
   285            status: custom
   286            custom_payload: |
   287              {
   288                username: 'Github',
   289                icon_emoji: ':octocat:',
   290                mention: 'channel',
   291                attachments: [{
   292                  title: '[${{ steps.commit.outputs.repo }}] ${{ github.workflow }} pipeline has failed',
   293                  color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
   294                  fields: [{
   295                    title: 'Commit Hash',
   296                    value: '${{ steps.commit.outputs.sha }}',
   297                    short: true
   298                  },
   299                  {
   300                    title: 'Author',
   301                    value: '${{ github.actor }}',
   302                    short: true
   303                  },
   304                  {
   305                    title: 'Pipeline URL',
   306                    value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
   307                    short: false
   308                  }]
   309                }]
   310              }
   311          env:
   312            GITHUB_TOKEN: ${{ github.token }}
   313            SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}