Skip to content

Commit ac147ef

Browse files
update Dockerfile; update scripts.sh (TeslaGov#88)
1 parent 583fffe commit ac147ef

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

Dockerfile

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,44 @@ ARG SOURCE_HASH
44

55
FROM debian:bullseye-slim as ngx_http_auth_jwt_builder_base
66
LABEL stage=ngx_http_auth_jwt_builder
7-
RUN apt-get update &&\
8-
apt-get install -y curl build-essential
9-
10-
7+
RUN <<`
8+
apt-get update
9+
apt-get install -y curl build-essential
10+
`
1111
FROM ngx_http_auth_jwt_builder_base as ngx_http_auth_jwt_builder_module
1212
LABEL stage=ngx_http_auth_jwt_builder
1313
ENV LD_LIBRARY_PATH=/usr/local/lib
1414
ARG NGINX_VERSION
15-
RUN set -x &&\
16-
apt-get install -y libjwt-dev libjwt0 libjansson-dev libjansson4 libpcre2-dev zlib1g-dev libpcre3-dev &&\
17-
mkdir -p /root/build/ngx-http-auth-jwt-module
15+
RUN <<`
16+
apt-get install -y libjwt-dev libjwt0 libjansson-dev libjansson4 libpcre2-dev zlib1g-dev libpcre3-dev
17+
mkdir -p /root/build/ngx-http-auth-jwt-module
18+
`
1819
WORKDIR /root/build/ngx-http-auth-jwt-module
1920
ARG SOURCE_HASH
2021
RUN echo "Source Hash: ${SOURCE_HASH}"
2122
ADD config ./
2223
ADD src/*.h src/*.c ./src/
2324
WORKDIR /root/build
24-
RUN set -x &&\
25-
mkdir nginx &&\
26-
curl -O http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz &&\
27-
tar -xzf nginx-${NGINX_VERSION}.tar.gz --strip-components 1 -C nginx
25+
RUN <<`
26+
mkdir nginx
27+
curl -O http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
28+
tar -xzf nginx-${NGINX_VERSION}.tar.gz --strip-components 1 -C nginx
29+
`
2830
WORKDIR /root/build/nginx
29-
RUN ./configure --with-debug --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module &&\
30-
make modules
31+
RUN <<`
32+
./configure --with-debug --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module
33+
make modules
34+
`
3135

3236

3337
FROM nginx:${NGINX_VERSION} AS ngx_http_auth_jwt_builder_nginx
3438
LABEL stage=
3539
RUN rm /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh /etc/nginx/conf.d/default.conf
36-
RUN apt-get update &&\
37-
apt-get -y install libjansson4 libjwt0 &&\
38-
cd /etc/nginx &&\
39-
sed -ri '/pid\s+\/var\/run\/nginx\.pid;$/a load_module \/usr\/lib64\/nginx\/modules\/ngx_http_auth_jwt_module\.so;' nginx.conf
40+
RUN <<`
41+
apt-get update
42+
apt-get -y install libjansson4 libjwt0
43+
cd /etc/nginx
44+
sed -ri '/pid\s+\/var\/run\/nginx\.pid;$/a load_module \/usr\/lib64\/nginx\/modules\/ngx_http_auth_jwt_module\.so;' nginx.conf
45+
`
4046
LABEL maintainer="TeslaGov" email="[email protected]"
4147
COPY --from=ngx_http_auth_jwt_builder_module /root/build/nginx/objs/ngx_http_auth_jwt_module.so /usr/lib64/nginx/modules/

scripts.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,54 @@ build_module() {
2828
printf "${BLUE}Building module...${NC}\n"
2929
docker image build -t ${FULL_IMAGE_NAME}:latest -t ${FULL_IMAGE_NAME}:${NGINX_VERSION} ${dockerArgs} \
3030
--build-arg NGINX_VERSION=${NGINX_VERSION} \
31-
--build-arg SOURCE_HASH=${sourceHash} \.
31+
--build-arg SOURCE_HASH=${sourceHash} .
3232

3333
if [ "$?" -ne 0 ]; then
3434
printf "${RED}✘ Build failed ${NC}\n"
3535
else
3636
printf "${GREEN}✔ Successfully built NGINX module ${NC}\n"
3737
fi
38-
39-
docker rmi -f $(docker images --filter=label=stage=ngx_http_auth_jwt_builder --quiet) 2> /dev/null || true
4038
}
4139

4240
rebuild_module() {
41+
clean_module
4342
build_module --no-cache
4443
}
4544

45+
clean_module() {
46+
docker rmi -f $(docker images --filter=label=stage=ngx_http_auth_jwt_builder --quiet) 2> /dev/null || true
47+
}
48+
4649
start_nginx() {
47-
printf "${BLUE}Starting NGINX...${NC}\n"
48-
docker run --rm --name "${IMAGE_NAME}" -d -p 8000:80 ${FULL_IMAGE_NAME}
50+
printf "${BLUE}Starting NGINX container (${IMAGE_NAME})...${NC}\n"
51+
docker run --rm --name "${IMAGE_NAME}" -d -p 8000:80 ${FULL_IMAGE_NAME} >/dev/null
4952
}
5053

5154
stop_nginx() {
52-
docker stop "${IMAGE_NAME}"
55+
docker stop "${IMAGE_NAME}" >/dev/null
5356
}
5457

5558
cp_bin() {
56-
if [ "$(docker container inspect -f '{{.State.Running}}' ${IMAGE_NAME})" != "true" ]; then
59+
local destDir=bin
60+
local stopContainer=0;
61+
62+
if [ "$(docker container inspect -f '{{.State.Running}}' ${IMAGE_NAME} | true)" != "true" ]; then
5763
start_nginx
64+
stopContainer=1
5865
fi
5966

60-
printf "${BLUE}Copying binaries...${NC}\n"
61-
rm -rf bin
62-
mkdir bin
67+
printf "${BLUE}Copying binaries to: ${destDir}${NC}\n"
68+
rm -rf ${destDir}/*
69+
mkdir -p ${destDir}
6370
docker exec "${IMAGE_NAME}" sh -c "cd /; tar -chf - \
6471
usr/lib64/nginx/modules/ngx_http_auth_jwt_module.so \
6572
usr/lib/x86_64-linux-gnu/libjansson.so.* \
66-
usr/lib/x86_64-linux-gnu/libjwt.*" | tar -xf - -C bin &>/dev/null
73+
usr/lib/x86_64-linux-gnu/libjwt.*" | tar -xf - -C ${destDir} &>/dev/null
74+
75+
if [ $stopContainer ]; then
76+
printf "${BLUE}Stopping NGINX container (${IMAGE_NAME})...${NC}\n"
77+
stop_nginx
78+
fi
6779
}
6880

6981
build_test_runner() {

0 commit comments

Comments
 (0)