Skip to content

Commit d7c3cb4

Browse files
add support for higher-bit HS/RS algorithms (TeslaGov#80)
* add support for higher-bit HS/RS algorithms fixes TeslaGov#77 * add Git hooks * use variable for Docker image name * cleanup
1 parent d150705 commit d7c3cb4

22 files changed

+598
-317
lines changed

.bin/git/hooks-wrapper

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Runs all executable pre-commit-* hooks and exits after,
4+
# if any of them was not successful.
5+
#
6+
# Based on
7+
# https://github.com/ELLIOTTCABLE/Paws.js/blob/Master/Scripts/git-hooks/chain-hooks.sh
8+
# http://osdir.com/ml/git/2009-01/msg00308.html
9+
#
10+
# assumes your scripts are located at <repo-root>/bin/git/hooks
11+
12+
exitcodes=()
13+
hookname=`basename $0`
14+
# our special hooks folder
15+
CUSTOM_HOOKS_DIR=$(git rev-parse --show-toplevel)/bin/git/hooks
16+
# find gits native hooks folder
17+
NATIVE_HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
18+
19+
# Run each hook, passing through STDIN and storing the exit code.
20+
# We don't want to bail at the first failure, as the user might
21+
# then bypass the hooks without knowing about additional issues.
22+
23+
for hook in ${CUSTOM_HOOKS_DIR}/$(basename $0)-*; do
24+
test -x "$hook" || continue
25+
26+
echo "Running custom hook '$hookname' ..."
27+
out=`$hook "$@"`
28+
exitcodes+=($?)
29+
echo "$out"
30+
done
31+
32+
# check if there was a local hook that was moved previously
33+
if [ -f "${NATIVE_HOOKS_DIR}/$hookname.local" ]; then
34+
echo "Running native hook '$hookname' ..."
35+
out=`${NATIVE_HOOKS_DIR}/$hookname.local "$@"`
36+
exitcodes+=($?)
37+
echo "$out"
38+
fi
39+
40+
# If any exit code isn't 0, bail.
41+
for i in "${exitcodes[@]}"; do
42+
[ "$i" == 0 ] || exit $i
43+
done
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
REPO_ROOT_DIR=$(git rev-parse --show-toplevel)
4+
CHANGE_COUNT=$(cd ${REPO_ROOT_DIR}; git diff --name-only origin/HEAD..HEAD -- resources/ src/ test/ Dockerfile scripts.sh |wc -l)
5+
6+
if [[ "0" -ne "${CHANGE_COUNT}" ]]; then
7+
(cd ${REPO_ROOT_DIR}; ./scripts.sh rebuild_nginx rebuild_test_runner test)
8+
else
9+
HOOK_NAME=$(basename $0)
10+
11+
echo "Skipping hook '${HOOK_NAME}' -- no changes detected which would require tests to be run."
12+
fi

.bin/git/init-hooks

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# based on http://stackoverflow.com/a/3464399/1383268
3+
# assumes that the hooks-wrapper script is located at <repo-root>/bin/git/hooks-wrapper
4+
5+
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc pre-push"
6+
# find git's native hooks folder
7+
REPO_ROOT_DIR=$(git rev-parse --show-toplevel)
8+
HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
9+
10+
for hook in ${HOOK_NAMES}; do
11+
# 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
14+
fi
15+
# create the symlink, overwriting the file if it exists
16+
# probably the only way this would happen is if you're using an old version of git
17+
# -- 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}
19+
done

.bin/init

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
source $(dirname $0)/git/init-hooks

Dockerfile

Lines changed: 18 additions & 17 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 \
32-
&& apt-get -y install libjansson4 libjwt0 \
33+
RUN apt-get update \
34+
&& 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/

Dockerfile-test-nginx

Lines changed: 0 additions & 10 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)