Skip to content

Commit

Permalink
User Docker Build action in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Jul 13, 2021
1 parent 0d3cf39 commit 810e9dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,31 @@ jobs:
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: Determine NGINX Plus version
run: echo "NGINX_PLUS_VERSION=$(cat Makefile | grep -m1 NGINX_PLUS_VERSION | cut -d "=" -f2)" >> $GITHUB_ENV
- name: Switch Repository (Nightly)
if: (github.event_name == 'schedule')
run: |
sed -i 's|pkgs.nginx.com|pkgs-test.nginx.com|g' docker/Dockerfile
sed -i '15d' 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)
sed -i 's|nginx-plus-\${{ env.NGINX_PLUS_VERSION }}|nginx-plus|g' docker/Dockerfile
- name: Build Plus Docker Image
uses: docker/build-push-action@v2
with:
file: docker/Dockerfile
context: 'docker'
tags: nginx-plus:${{ env.NGINX_PLUS_VERSION }}
load: true
secrets: |
"nginx-repo.crt=${{ secrets.NGINX_CRT }}"
"nginx-repo.key=${{ secrets.NGINX_KEY }}"
build-args:
NGINX_PLUS_VERSION=${{ env.NGINX_PLUS_VERSION }}
- name: Test Client
if: (github.event_name != 'schedule')
run: make test
- name: Test Client (Nightly)
if: (github.event_name == 'schedule')
run: make test
env:
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
NGINX_PLUS_VERSION=r24
NGINX_IMAGE=nginxplus:$(NGINX_PLUS_VERSION)
DOCKER_NETWORK?=test
DOCKER_NETWORK_ALIAS=nginx-plus-test
DOCKER_NGINX_PLUS?=nginx-plus
Expand All @@ -11,18 +10,18 @@ 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
test: run-nginx-plus test-run configure-no-stream-block test-run-no-stream-block clean

lint:
docker run --pull always --rm -v $(shell pwd):/nginx-plus-go-client -w /nginx-plus-go-client -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run

docker-build:
docker build --secret id=nginx-repo.crt,src=docker/nginx-repo.crt --secret id=nginx-repo.key,src=docker/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) -t $(NGINX_IMAGE) docker
docker build --secret id=nginx-repo.crt,src=docker/nginx-repo.crt --secret id=nginx-repo.key,src=docker/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) -t nginx-plus:$(NGINX_PLUS_VERSION) docker

run-nginx-plus:
docker network create --driver bridge $(DOCKER_NETWORK)
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)
docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8080:8080 -p 8081:8081 nginx-plus:$(NGINX_PLUS_VERSION)
docker run --network=$(DOCKER_NETWORK) -d --name $(DOCKER_NGINX_PLUS_HELPER) --network-alias=$(DOCKER_NETWORK_ALIAS) --rm -p 8090:8080 -p 8091:8081 nginx-plus:$(NGINX_PLUS_VERSION)

test-run:
docker run --rm \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This Client works against version 5 of NGINX Plus API. Version 5 was introduced
## Using the Client

1. Import `github.com/nginxinc/nginx-plus-go-client/client` into your go project.
2. Use your favourite vendor tool to add this to your `/vendor` directory in your project.
2. Use your favorite vendor tool to add this to your `/vendor` directory in your project.

## Testing

Expand All @@ -37,7 +37,7 @@ Prerequisites:
Run Tests:

```
$ make test
$ make docker-build && make test
```

This will build and run two NGINX Plus containers and create one docker network of type bridge, execute the client tests against both NGINX Plus APIs, and then clean up. If it fails and you want to clean up (i.e. stop the running containers and remove the docker network), please use `$ make clean`
Expand Down

0 comments on commit 810e9dd

Please sign in to comment.