diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..4fff7bfb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: Continuous Integration + +on: + push: + branches: + - '**' + pull_request: + branches: + - master + schedule: + - cron: '* 5 * * *' + +env: + DOCKER_BUILDKIT: 1 + DOCKER_NETWORK: ${{ github.run_id }} + DOCKER_NETWORK_ALIAS: nginx-plus-test + DOCKER_NGINX_PLUS: nginx-plus-${{ github.run_id }} + DOCKER_NGINX_PLUS_HELPER: nginx-plus-helper-${{ github.run_id }} + +jobs: + + build: + name: Build Go Client + runs-on: ubuntu-18.04 + if: (github.repository == 'nginxinc/nginx-plus-go-client') + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Fetch Certificates + env: + CRT: ${{ secrets.NGINX_CRT }} + KEY: ${{ secrets.NGINX_KEY }} + run: | + echo "${CRT}" | base64 --decode > docker/nginx-repo.crt + echo "${KEY}" | base64 --decode > docker/nginx-repo.key + - name: Build & Test Client + if: (github.event_name != 'schedule') + run: make test + - name: Switch Repository (Nightly) + if: (github.event_name == 'schedule') + run: | + sed -i 's|plus-pkgs|pkgs-test|g' docker/Dockerfile + sed -i '20,31d' docker/Dockerfile + sed -i 's|deb https|deb [trusted=yes] https|g' docker/Dockerfile + sed -i 's|nginx-plus=\${NGINX_PLUS_VERSION}|nginx-plus|g' docker/Dockerfile + - name: Build & Test Client (Nightly) + if: (github.event_name == 'schedule') + run: make test + env: + NGINX_PLUS_VERSION: nightly diff --git a/Makefile b/Makefile index 6cb531db..e8817084 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,56 @@ NGINX_PLUS_VERSION=19-1 NGINX_IMAGE=nginxplus:$(NGINX_PLUS_VERSION) DOCKER_NETWORK?=test +DOCKER_NETWORK_ALIAS=nginx-plus-test DOCKER_NGINX_PLUS?=nginx-plus DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper -export TEST_API_ENDPOINT=http://127.0.0.1:8080/api -export TEST_API_ENDPOINT_OF_HELPER=http://127.0.0.1:8090/api -export TEST_UNAVAILABLE_STREAM_ADDRESS=127.0.0.1:8081 +GOLANG_CONTAINER=golang:1.14 +GOLANGCI_CONTAINER=golangci/golangci-lint:v1.27-alpine + +export TEST_API_ENDPOINT=http://$(DOCKER_NGINX_PLUS):8080/api +export TEST_API_ENDPOINT_OF_HELPER=http://$(DOCKER_NGINX_PLUS_HELPER):8080/api +export TEST_UNAVAILABLE_STREAM_ADDRESS=$(DOCKER_NGINX_PLUS):8081 test: docker-build run-nginx-plus test-run configure-no-stream-block test-run-no-stream-block clean lint: - golangci-lint run + docker run --rm \ + -v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \ + -w /go/src/github.com/nginxinc/nginx-plus-go-client \ + $(GOLANGCI_CONTAINER) golangci-lint run docker-build: docker build --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION)~stretch -t $(NGINX_IMAGE) docker run-nginx-plus: docker network create --driver bridge $(DOCKER_NETWORK) - docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS) --network-alias=nginx-plus-test --rm -p 8080:8080 -p 8081:8081 $(NGINX_IMAGE) - docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS_HELPER) --network-alias=nginx-plus-test --rm -p 8090:8080 -p 8091:8081 $(NGINX_IMAGE) + docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8080:8080 -p 8081:8081 $(NGINX_IMAGE) + docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS_HELPER) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8090:8080 -p 8091:8081 $(NGINX_IMAGE) test-run: - go test client/* - go clean -testcache - go test tests/client_test.go + docker run --rm \ + --network=$(DOCKER_NETWORK) \ + -e TEST_API_ENDPOINT \ + -e TEST_API_ENDPOINT_OF_HELPER \ + -e TEST_UNAVAILABLE_STREAM_ADDRESS \ + -v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \ + -w /go/src/github.com/nginxinc/nginx-plus-go-client \ + $(GOLANG_CONTAINER) /bin/sh -c "go test client/*; go clean -testcache; go test tests/client_test.go" configure-no-stream-block: docker cp docker/nginx_no_stream.conf $(DOCKER_NGINX_PLUS):/etc/nginx/nginx.conf docker exec $(DOCKER_NGINX_PLUS) nginx -s reload -test-run-no-stream-block: - go clean -testcache - go test tests/client_no_stream_test.go +test-run-no-stream-block: configure-no-stream-block + docker run --rm \ + --network=$(DOCKER_NETWORK) \ + -e TEST_API_ENDPOINT \ + -e TEST_API_ENDPOINT_OF_HELPER \ + -e TEST_UNAVAILABLE_STREAM_ADDRESS \ + -v $(shell pwd):/go/src/github.com/nginxinc/nginx-plus-go-client \ + -w /go/src/github.com/nginxinc/nginx-plus-go-client \ + $(GOLANG_CONTAINER) /bin/sh -c "go clean -testcache; go test tests/client_no_stream_test.go" clean: -docker kill $(DOCKER_NGINX_PLUS) diff --git a/build/ci/Jenkinsfile b/build/ci/Jenkinsfile deleted file mode 100644 index 29045a62..00000000 --- a/build/ci/Jenkinsfile +++ /dev/null @@ -1,7 +0,0 @@ -node { - git( - url: "${libsLocation}", - credentialsId: "${githubCreds}" - ) - load 'nginx-plus-go-client/Jenkinsfile' -} \ No newline at end of file