This repository was archived by the owner on Mar 10, 2024. It is now read-only.
forked from TeslaGov/ngx-http-auth-jwt-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.sh
More file actions
executable file
·89 lines (71 loc) · 2.12 KB
/
scripts.sh
File metadata and controls
executable file
·89 lines (71 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash -eu
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
export ORG_NAME=${ORG_NAME:-teslagov}
export IMAGE_NAME=${IMAGE_NAME:-jwt-nginx}
export FULL_IMAGE_NAME=${ORG_NAME}/${IMAGE_NAME}
export CONTAINER_NAME_PREFIX=${CONTAINER_NAME_PREFIX:-jwt-nginx-test}
export NGINX_VERSION=${NGINX_VERSION:-1.22.0}
all() {
build_nginx
start_nginx
test
}
fetch_headers() {
printf "${BLUE} Fetching NGINX headers...${NC}"
local files='src/core/ngx_core.h src/http/ngx_http.h'
for f in ${files}; do
curl "https://raw.githubusercontent.com/nginx/nginx/release-${NGINX_VERSION}/${f}" -o src/lib/$(basename ${f})
done
}
build_nginx() {
local dockerArgs=${1:-}
printf "${BLUE} Building...${NC}"
docker image pull debian:bullseye-slim
docker image pull nginx:${NGINX_VERSION}
docker image build -t ${FULL_IMAGE_NAME}:latest -t ${FULL_IMAGE_NAME}:${NGINX_VERSION} --build-arg NGINX_VERSION=${NGINX_VERSION} ${dockerArgs} .
if [ "$?" -ne 0 ]; then
printf "${RED} Build failed ${NC}"
else
printf "${GREEN}✓ Successfully built NGINX module ${NC}"
fi
docker rmi -f $(docker images --filter=label=stage=builder --quiet)
}
rebuild_nginx() {
build_nginx --no-cache
}
start_nginx() {
docker run --rm --name "${IMAGE_NAME}" -d -p 8000:80 ${FULL_IMAGE_NAME}
}
stop_nginx() {
docker stop "${IMAGE_NAME}"
}
cp_bin() {
printf "${BLUE} Copying binaries...${NC}"
rm -rf bin
mkdir bin
docker exec "${IMAGE_NAME}" sh -c "tar -chf - \
/usr/lib64/nginx/modules/ngx_http_auth_jwt_module.so \
/usr/lib/x86_64-linux-gnu/libjansson.so.* \
/usr/lib/x86_64-linux-gnu/libjwt.*" 2>/dev/null | tar -xf - -C bin &>/dev/null
}
build_test_runner() {
local dockerArgs=${1:-}
printf "${BLUE} Building test runner...${NC}"
docker compose -f ./test/docker-compose-test.yml build ${dockerArgs}
}
rebuild_test_runner() {
build_test_runner --no-cache
}
test() {
printf "${BLUE} Running tests...${NC}"
docker compose -f ./test/docker-compose-test.yml up --no-start
docker start ${CONTAINER_NAME_PREFIX}
docker start -a ${CONTAINER_NAME_PREFIX}-runner
docker compose -f ./test/docker-compose-test.yml down
}
for fn in $@; do
"$fn"
done