Skip to content

Commit c2ad100

Browse files
cleanup
1 parent 5a1f6c3 commit c2ad100

File tree

9 files changed

+52
-51
lines changed

9 files changed

+52
-51
lines changed

.bin/git/hooks-wrapper

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NATIVE_HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
2020
# We don't want to bail at the first failure, as the user might
2121
# then bypass the hooks without knowing about additional issues.
2222

23-
for hook in $CUSTOM_HOOKS_DIR/$(basename $0)-*; do
23+
for hook in ${CUSTOM_HOOKS_DIR}/$(basename $0)-*; do
2424
test -x "$hook" || continue
2525

2626
echo "Running custom hook '$hookname' ..."
@@ -30,9 +30,9 @@ for hook in $CUSTOM_HOOKS_DIR/$(basename $0)-*; do
3030
done
3131

3232
# check if there was a local hook that was moved previously
33-
if [ -f "$NATIVE_HOOKS_DIR/$hookname.local" ]; then
33+
if [ -f "${NATIVE_HOOKS_DIR}/$hookname.local" ]; then
3434
echo "Running native hook '$hookname' ..."
35-
out=`$NATIVE_HOOKS_DIR/$hookname.local "$@"`
35+
out=`${NATIVE_HOOKS_DIR}/$hookname.local "$@"`
3636
exitcodes+=($?)
3737
echo "$out"
3838
fi

.bin/git/init-hooks

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-com
77
REPO_ROOT_DIR=$(git rev-parse --show-toplevel)
88
HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
99

10-
for hook in $HOOK_NAMES; do
10+
for hook in ${HOOK_NAMES}; do
1111
# If the hook already exists, is a file, and is not a symlink
12-
if [ ! -h $HOOKS_DIR/$hook ] && [ -f $HOOKS_DIR/$hook ]; then
13-
mv $HOOKS_DIR/$hook $HOOKS_DIR/$hook.local
12+
if [ ! -h ${HOOKS_DIR}/${hook} ] && [ -f ${HOOKS_DIR}/${hook} ]; then
13+
mv ${HOOKS_DIR}/${hook} ${HOOKS_DIR}/${hook}.local
1414
fi
1515
# create the symlink, overwriting the file if it exists
1616
# probably the only way this would happen is if you're using an old version of git
1717
# -- back when the sample hooks were not executable, instead of being named ____.sample
18-
ln -s -f $REPO_ROOT_DIR/bin/git/hooks-wrapper $HOOKS_DIR/$hook
18+
ln -s -f ${REPO_ROOT_DIR}/bin/git/hooks-wrapper ${HOOKS_DIR}/${hook}
1919
done

Dockerfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
ARG NGINX_VERSION=1.22.0
1+
ARG NGINX_VERSION
22

33

44
FROM debian:bullseye-slim as BASE_IMAGE
55
LABEL stage=builder
6-
RUN apt-get update \
6+
RUN apt-get update \
77
&& apt-get install -y curl build-essential
88

99

1010
FROM BASE_IMAGE as BUILD_IMAGE
1111
LABEL stage=builder
1212
ENV LD_LIBRARY_PATH=/usr/local/lib
1313
ARG NGINX_VERSION
14-
ADD . /root/dl/ngx-http-auth-jwt-module
15-
RUN set -x \
14+
RUN set -x \
1615
&& apt-get install -y libjwt-dev libjwt0 libjansson-dev libjansson4 libpcre2-dev zlib1g-dev libpcre3-dev \
17-
&& mkdir -p /root/dl
18-
WORKDIR /root/dl
19-
RUN set -x \
20-
&& curl -O http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz \
21-
&& tar -xzf nginx-$NGINX_VERSION.tar.gz \
22-
&& rm nginx-$NGINX_VERSION.tar.gz \
23-
&& ln -sf nginx-$NGINX_VERSION nginx \
24-
&& cd /root/dl/nginx \
25-
&& ./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module \
16+
&& mkdir -p /root/build/ngx-http-auth-jwt-module
17+
WORKDIR /root/build/ngx-http-auth-jwt-module
18+
ADD config ./
19+
ADD src/*.h src/*.c ./src/
20+
WORKDIR /root/build
21+
RUN set -x \
22+
&& mkdir nginx \
23+
&& curl -O http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
24+
&& tar -xzf nginx-${NGINX_VERSION}.tar.gz --strip-components 1 -C nginx \
25+
&& rm nginx-${NGINX_VERSION}.tar.gz
26+
WORKDIR /root/build/nginx
27+
RUN ./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module \
2628
&& make modules
2729

2830

2931
FROM nginx:${NGINX_VERSION}
3032
LABEL stage=builder
31-
RUN apt-get update \
33+
RUN apt-get update \
3234
&& apt-get -y install libjansson4 libjwt0 \
3335
&& cd /etc/nginx \
34-
&& cp nginx.conf nginx.conf.orig \
3536
&& sed -ri '/pid\s+\/var\/run\/nginx\.pid;$/a load_module \/usr\/lib64\/nginx\/modules\/ngx_http_auth_jwt_module\.so;' nginx.conf
3637

3738

3839
LABEL stage=
3940
LABEL maintainer="TeslaGov" email="[email protected]"
40-
COPY --from=BUILD_IMAGE /root/dl/nginx/objs/ngx_http_auth_jwt_module.so /usr/lib64/nginx/modules/
41+
COPY --from=BUILD_IMAGE /root/build/nginx/objs/ngx_http_auth_jwt_module.so /usr/lib64/nginx/modules/

config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
ngx_addon_name=ngx_http_auth_jwt_module
2-
31
ngx_module_type=HTTP
4-
ngx_module_name=ngx_http_auth_jwt_module
5-
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_auth_jwt_binary_converters.c $ngx_addon_dir/src/ngx_http_auth_jwt_header_processing.c $ngx_addon_dir/src/ngx_http_auth_jwt_string.c $ngx_addon_dir/src/ngx_http_auth_jwt_module.c"
2+
ngx_addon_name=ngx_http_auth_jwt_module
3+
ngx_module_name=$ngx_addon_name
4+
ngx_module_srcs="${ngx_addon_dir}/src/ngx_http_auth_jwt_binary_converters.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_header_processing.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_string.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_module.c"
65
ngx_module_libs="-ljansson -ljwt"
76

87
. auto/module

scripts.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@ GREEN='\033[0;32m'
55
RED='\033[0;31m'
66
NC='\033[0m'
77

8-
DOCKER_ORG_NAME=${DOCKER_ORG_NAME:-teslagov}
9-
DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-jwt-nginx}
10-
DOCKER_FULL_IMAGE_NAME=${DOCKER_ORG_NAME}/${DOCKER_IMAGE_NAME}
11-
CONTAINER_NAME_PREFIX=${CONTAINER_NAME_PREFIX:-jwt-nginx-test}
12-
NGINX_VERSION=${NGINX_VERSION:-1.22.0}
8+
export ORG_NAME=${ORG_NAME:-teslagov}
9+
export IMAGE_NAME=${IMAGE_NAME:-jwt-nginx}
10+
export FULL_IMAGE_NAME=${ORG_NAME}/${IMAGE_NAME}
11+
export CONTAINER_NAME_PREFIX=${CONTAINER_NAME_PREFIX:-jwt-nginx-test}
12+
export NGINX_VERSION=${NGINX_VERSION:-1.22.0}
1313

1414
all() {
1515
build_nginx
1616
start_nginx
1717
test
1818
}
1919

20+
fetch_headers() {
21+
printf "${BLUE} Fetching NGINX headers...${NC}"
22+
local files='src/core/ngx_core.h src/http/ngx_http.h'
23+
24+
for f in ${files}; do
25+
curl "https://raw.githubusercontent.com/nginx/nginx/release-${NGINX_VERSION}/${f}" -o src/lib/$(basename ${f})
26+
done
27+
}
28+
2029
build_nginx() {
21-
DOCKER_ARGS=${1:-}
30+
local dockerArgs=${1:-}
2231

2332
printf "${BLUE} Building...${NC}"
2433
docker image pull debian:bullseye-slim
2534
docker image pull nginx:${NGINX_VERSION}
26-
docker image build -t ${DOCKER_FULL_IMAGE_NAME}:latest -t ${DOCKER_FULL_IMAGE_NAME}:${NGINX_VERSION} --build-arg NGINX_VERSION=${NGINX_VERSION} ${DOCKER_ARGS} .
35+
docker image build -t ${FULL_IMAGE_NAME}:latest -t ${FULL_IMAGE_NAME}:${NGINX_VERSION} --build-arg NGINX_VERSION=${NGINX_VERSION} ${dockerArgs} .
2736

2837
if [ "$?" -ne 0 ]; then
2938
printf "${RED} Build failed ${NC}"
@@ -39,43 +48,35 @@ rebuild_nginx() {
3948
}
4049

4150
start_nginx() {
42-
docker run --rm --name "${DOCKER_IMAGE_NAME}" -d -p 8000:80 ${DOCKER_FULL_IMAGE_NAME}
51+
docker run --rm --name "${IMAGE_NAME}" -d -p 8000:80 ${FULL_IMAGE_NAME}
4352
}
4453

4554
stop_nginx() {
46-
docker stop "${DOCKER_IMAGE_NAME}"
55+
docker stop "${IMAGE_NAME}"
4756
}
4857

4958
cp_bin() {
5059
printf "${BLUE} Copying binaries...${NC}"
5160
rm -rf bin
5261
mkdir bin
53-
docker exec "${DOCKER_IMAGE_NAME}" sh -c "tar -chf - \
62+
docker exec "${IMAGE_NAME}" sh -c "tar -chf - \
5463
/usr/lib64/nginx/modules/ngx_http_auth_jwt_module.so \
5564
/usr/lib/x86_64-linux-gnu/libjansson.so.* \
5665
/usr/lib/x86_64-linux-gnu/libjwt.*" 2>/dev/null | tar -xf - -C bin &>/dev/null
5766
}
5867

5968
build_test_runner() {
60-
DOCKER_ARGS=${1:-}
61-
62-
export CONTAINER_NAME_PREFIX
63-
export IMAGE_NAME=${IMAGE_NAME:-${DOCKER_FULL_IMAGE_NAME}}
64-
export IMAGE_VERSION=${NGINX_VERSION}
69+
local dockerArgs=${1:-}
6570

6671
printf "${BLUE} Building test runner...${NC}"
67-
docker compose -f ./test/docker-compose-test.yml build ${DOCKER_ARGS}
72+
docker compose -f ./test/docker-compose-test.yml build ${dockerArgs}
6873
}
6974

7075
rebuild_test_runner() {
7176
build_test_runner --no-cache
7277
}
7378

7479
test() {
75-
export CONTAINER_NAME_PREFIX
76-
export IMAGE_NAME=${IMAGE_NAME:-${DOCKER_FULL_IMAGE_NAME}}
77-
export IMAGE_VERSION=${NGINX_VERSION}
78-
7980
printf "${BLUE} Running tests...${NC}"
8081
docker compose -f ./test/docker-compose-test.yml up --no-start
8182
docker start ${CONTAINER_NAME_PREFIX}

test/Dockerfile-test-nginx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG BASE_IMAGE
22

33
FROM ${BASE_IMAGE} as NGINX
4-
COPY test-jwt-nginx.conf /etc/nginx/conf.d/test-jwt-nginx.conf
4+
COPY test.conf /etc/nginx/conf.d/test.conf
55
COPY rsa_key_2048-pub.pem /etc/nginx/rsa-key.conf

test/docker-compose-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
context: .
99
dockerfile: Dockerfile-test-nginx
1010
args:
11-
BASE_IMAGE: ${IMAGE_NAME}:${IMAGE_VERSION:-latest}
11+
BASE_IMAGE: ${FULL_IMAGE_NAME}:${NGINX_VERSION:-latest}
1212
logging:
1313
driver: ${LOG_DRIVER:-journald}
1414

@@ -18,7 +18,7 @@ services:
1818
context: .
1919
dockerfile: Dockerfile-test-runner
2020
environment:
21-
BASE_IMAGE: ${IMAGE_NAME}:${IMAGE_VERSION:-latest}
21+
BASE_IMAGE: ${FULL_IMAGE_NAME}:${NGINX_VERSION:-latest}
2222

2323
depends_on:
2424
- nginx
File renamed without changes.

test/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ run_test () {
1010
local expect=$3
1111
local extra=$4
1212

13-
cmd="curl -X GET -o /dev/null --silent --head --write-out '%{http_code}' http://nginx:8000$path -H 'cache-control: no-cache' $extra"
13+
cmd="curl -X GET -o /dev/null --silent --head --write-out '%{http_code}' http://nginx:8000${path} -H 'cache-control: no-cache' $extra"
1414
result=$(eval ${cmd})
1515

1616
if [ "${result}" -eq "${expect}" ]; then

0 commit comments

Comments
 (0)