Skip to content

Commit acbb12e

Browse files
update redirect URL to include port (#146)
1 parent c38ae69 commit acbb12e

8 files changed

+159
-84
lines changed

README.md

+23-18
Original file line numberDiff line numberDiff line change
@@ -192,41 +192,43 @@ Once you save your changes to `.vscode/c_cpp_properties.json`, you should see th
192192

193193
### Building and Testing
194194

195-
The `./scripts.sh` file contains multiple commands to make things easy:
195+
The `./scripts` file contains multiple commands to make things easy:
196196

197197
| Command | Description |
198198
| --------------------- | ----------------------------------------------------------------- |
199199
| `build_module` | Builds the NGINX image. |
200200
| `rebuild_module` | Re-builds the NGINX image. |
201-
| `start_nginx` | Starts the NGINX container. |
202-
| `stop_nginx` | Stops the NGINX container. |
201+
| `start` | Starts the NGINX container. |
202+
| `stop` | Stops the NGINX container. |
203203
| `cp_bin` | Copies the compiled binaries out of the NGINX container. |
204-
| `build_test_runner` | Builds the images used by the test stack (uses Docker compose). |
205-
| `rebuild_test_runner` | Re-builds the images used by the test stack. |
206-
| `test` | Runs `test.sh` against the NGINX container (uses Docker compose). |
204+
| `build_test` | Builds the images used by the test stack. |
205+
| `rebuild_test` | Re-builds the images used by the test stack. |
206+
| `test` | Runs `test.sh` against the NGINX container. |
207207
| `test_now` | Runs `test.sh` without rebuilding. |
208208

209209
You can run multiple commands in sequence by separating them with a space, e.g.:
210210

211211
```shell
212-
./scripts.sh build_module test
212+
./scripts build_module
213+
./scripts test
213214
```
214215

215-
To build the Docker images, module, start NGINX, and run the tests against, you can simply do:
216+
To build the Docker images, module, start NGINX, and run the tests against it for all versions, you can simply do:
216217

217218
```shell
218-
./scripts.sh all
219+
./scripts all
219220
```
220221

221-
When you make a change to the module run `./scripts.sh build_module test` to build a fresh module and run the tests. Note that `rebuild_module` is not often needed as `build_module` hashes the module's source files which will cause a cache miss while building the container, causing the module to be rebuilt.
222+
When you make a change to the module, running `./scripts test` should build a fresh module and run the tests. Note that `rebuild_module` is not often needed as Docker will automatically rebuild the image if the source files have
223+
changed.
222224

223-
When you make a change to the test NGINX config or `test.sh`, run `./scripts.sh test` to run the tests. Similar to above, the test sources are hashed and the containers will be rebuilt as needed.
225+
When you make a change to the test NGINX config or `test.sh`, run `./scripts test` to run the tests.
224226

225-
The image produced with `./scripts.sh build_module` only differs from the official NGINX image in two ways:
227+
The image produced with `./scripts build_module` only differs from the official NGINX image in two ways:
226228
- the JWT module itself, and
227229
- the `nginx.conf` file is overwritten with our own.
228230

229-
The tests use a customized NGINX image, distinct from the main image, as well as a test runner image. By running `./scripts.sh test`, the two test containers will be stood up via Docker compose, then they'll be started, and the tests will run. At the end of the test run, both containers will be automatically stopped and destroyed. See below to learn how to trace test failures across runs.
231+
The tests use a customized NGINX image, distinct from the main image, as well as a test runner image. By running `./scripts test`, the two test containers will be stood up via Docker Compose, then they'll be started, and the tests will run. At the end of the test run, both containers will be automatically stopped and destroyed. See below to learn how to trace test failures across runs.
230232

231233
#### Tracing Test Failures
232234

@@ -236,20 +238,23 @@ If you'd like to persist logs across test runs, you can configure the log driver
236238

237239
```shell
238240
# need to rebuild the test runner with the proper log driver
239-
LOG_DRIVER=journald ./scripts.sh rebuild_test_runner
241+
export LOG_DRIVER=journald
242+
243+
# rebuild the test images
244+
./scripts rebuild_test
240245

241246
# run the tests
242-
./scripts.sh test
247+
./scripts test
243248

244-
# check the logs
245-
journalctl -eu docker CONTAINER_NAME=jwt-nginx-test
249+
# check the logs -- adjust the container name as needed
250+
journalctl -eu docker CONTAINER_NAME=nginx-auth-jwt-test-nginx
246251
```
247252

248253
Now you'll be able to see logs from previous test runs. The best way to make use of this is to open two terminals, one where you run the tests, and one where you follow the logs:
249254

250255
```shell
251256
# terminal 1
252-
./scripts.sh test
257+
./scripts test
253258

254259
# terminal 2
255260
journalctl -fu docker CONTAINER_NAME=jwt-nginx-test

scripts

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ IMAGE_NAME=${IMAGE_NAME:-nginx-auth-jwt}
3131
FULL_IMAGE_NAME=${ORG_NAME:-teslagov}/${IMAGE_NAME}
3232

3333
TEST_CONTAINER_NAME_PREFIX="${IMAGE_NAME}-test"
34+
TEST_COMPOSE_FILE='test/docker-compose-test.yml'
3435

3536
all() {
3637
build_module
@@ -162,7 +163,8 @@ build_test() {
162163
printf "${MAGENTA}Building test NGINX & runner using port ${port}...${NC}\n"
163164
docker compose \
164165
-p ${TEST_CONTAINER_NAME_PREFIX} \
165-
-f ./test/docker-compose-test.yml build \
166+
-f ${TEST_COMPOSE_FILE} \
167+
build \
166168
--build-arg RUNNER_BASE_IMAGE=${runnerBaseImage} \
167169
--build-arg PORT=${port} \
168170
--build-arg SSL_PORT=${sslPort} \
@@ -188,12 +190,11 @@ test() {
188190
printf "${MAGENTA}Running tests...${NC}\n"
189191
docker compose \
190192
-p ${TEST_CONTAINER_NAME_PREFIX} \
191-
-f ./test/docker-compose-test.yml up \
193+
-f ${TEST_COMPOSE_FILE} up \
192194
--no-start
193195

194-
195-
trap 'docker compose -f ./test/docker-compose-test.yml down' 0
196-
196+
trap test_cleanup 0
197+
197198
test_now
198199
}
199200

@@ -218,6 +219,12 @@ test_now() {
218219
echo " NGINX Version: ${NGINX_VERSION}"
219220
}
220221

222+
test_cleanup() {
223+
docker compose \
224+
-p ${TEST_CONTAINER_NAME_PREFIX} \
225+
-f ${TEST_COMPOSE_FILE} down
226+
}
227+
221228
get_port() {
222229
startPort=${1:-8000}
223230
endPort=$((startPort + 100))

0 commit comments

Comments
 (0)