Skip to content

Commit 539fe7b

Browse files
authored
Merge pull request TeslaGov#6 from TeslaGov/joefitz/docker-build
Joefitz/docker build
2 parents 6a48f05 + bf13ba5 commit 539fe7b

File tree

7 files changed

+133
-51
lines changed

7 files changed

+133
-51
lines changed

Dockerfile

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,50 @@
11
FROM centos:7
22

3-
MAINTAINER Tesla Government email: [email protected]
3+
LABEL maintainer="TeslaGov" email="[email protected]"
44

5-
RUN yum -y update
5+
ENV LD_LIBRARY_PATH=/usr/local/lib
66

7-
RUN yum -y groupinstall 'Development Tools'
8-
RUN yum -y install pcre-devel pcre
9-
RUN yum -y install zlib-devel openssl-devel
10-
RUN yum -y install wget
11-
RUN yum -y install cmake
12-
RUN yum -y install check-devel check
13-
# RUN yum -y install subunit-devel subunit libsubunit
7+
RUN yum -y update && \
8+
yum -y groupinstall 'Development Tools' && \
9+
yum -y install pcre-devel pcre zlib-devel openssl-devel wget cmake check-devel check
1410

1511
RUN mkdir -p /root/dl
12+
WORKDIR /root/dl
1613

1714
# get our JWT module
18-
WORKDIR /root/dl
1915
# change this to get a specific version?
20-
RUN wget https://github.com/TeslaGov/ngx-http-auth-jwt-module/archive/master.zip
21-
RUN unzip master.zip
22-
RUN rm master.zip
23-
RUN ln -sf ngx-http-auth-jwt-module-master ngx-http-auth-jwt-module
16+
RUN wget https://github.com/TeslaGov/ngx-http-auth-jwt-module/archive/master.zip && \
17+
unzip master.zip && \
18+
rm master.zip && \
19+
ln -sf ngx-http-auth-jwt-module-master ngx-http-auth-jwt-module
2420

2521
# build jansson
26-
WORKDIR /root/dl
27-
RUN wget https://github.com/akheron/jansson/archive/v2.10.zip
28-
RUN unzip v2.10.zip
29-
RUN rm v2.10.zip
30-
RUN ln -sf jansson-2.10 jansson
31-
WORKDIR /root/dl/jansson
32-
RUN cmake .
33-
RUN make
34-
RUN make check
35-
RUN make install
22+
RUN wget https://github.com/akheron/jansson/archive/v2.10.zip && \
23+
unzip v2.10.zip && \
24+
rm v2.10.zip && \
25+
ln -sf jansson-2.10 jansson && \
26+
cd /root/dl/jansson && \
27+
cmake . -DJANSSON_BUILD_SHARED_LIBS=1 -DJANSSON_BUILD_DOCS=OFF && \
28+
make && \
29+
make check && \
30+
make install
3631

3732
# build libjwt
38-
WORKDIR /root/dl
39-
RUN wget https://github.com/benmcollins/libjwt/archive/v1.8.0.zip
40-
RUN unzip v1.8.0.zip
41-
RUN rm v1.8.0.zip
42-
RUN ln -sf libjwt-1.8.0 libjwt
43-
WORKDIR /root/dl/libjwt
44-
RUN autoreconf -i
45-
RUN ./configure JANSSON_CFLAGS=/usr/local/include JANSSON_LIBS=/usr/local/lib
46-
RUN make all
47-
# this does not work because it can't find JANSSON
48-
# RUN make check
49-
RUN make install
50-
51-
WORKDIR /root/dl
52-
RUN wget http://nginx.org/download/nginx-1.12.0.tar.gz
53-
RUN tar -xzf nginx-1.12.0.tar.gz
54-
RUN rm nginx-1.12.0.tar.gz
55-
RUN ln -sf nginx-1.12.0 nginx
56-
WORKDIR /root/dl/nginx
57-
RUN ./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module --with-cc-opt='-std=gnu99'
58-
RUN make modules
59-
60-
61-
EXPOSE 80
62-
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]
63-
WORKDIR /etc/nginx
64-
33+
RUN wget https://github.com/benmcollins/libjwt/archive/v1.8.0.zip && \
34+
unzip v1.8.0.zip && \
35+
rm v1.8.0.zip && \
36+
ln -sf libjwt-1.8.0 libjwt && \
37+
cd /root/dl/libjwt && \
38+
autoreconf -i && \
39+
./configure JANSSON_CFLAGS=/usr/local/include JANSSON_LIBS=/usr/local/lib && \
40+
make all && \
41+
make install
42+
43+
# build nginx module against nginx sources
44+
RUN wget http://nginx.org/download/nginx-1.12.0.tar.gz && \
45+
tar -xzf nginx-1.12.0.tar.gz && \
46+
rm nginx-1.12.0.tar.gz && \
47+
ln -sf nginx-1.12.0 nginx && \
48+
cd /root/dl/nginx && \
49+
./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module --with-cc-opt='-std=gnu99' && \
50+
make modules

build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# build
4+
DOCKER_IMAGE_NAME=jwt-nginx
5+
docker build -t ${DOCKER_IMAGE_NAME} .
6+
CONTAINER_ID=$(docker run -itd ${DOCKER_IMAGE_NAME} sh)
7+
8+
# setup test
9+
rm -rf ./lib
10+
rm -rf ./modules
11+
mkdir modules
12+
DOCKER_TEST_IMAGE_NAME=jwt-nginx-test
13+
docker build -t ${DOCKER_TEST_IMAGE_NAME} test/.
14+
CONTAINER_TEST_ID=$(docker run -p 8000:8000 -itd ${DOCKER_TEST_IMAGE_NAME} sh)
15+
docker cp ${CONTAINER_ID}:/usr/local/lib .
16+
docker cp lib ${CONTAINER_TEST_ID}:/usr/local
17+
docker cp ${CONTAINER_ID}:/root/dl/nginx/objs/ngx_http_auth_jwt_module.so modules/.
18+
docker cp modules/ngx_http_auth_jwt_module.so ${CONTAINER_TEST_ID}:/usr/lib64/nginx/modules/.
19+
docker cp resources/test-jwt-nginx.conf ${CONTAINER_TEST_ID}:/etc/nginx/conf.d/test-jwt-nginx.conf
20+
docker cp resources/nginx.conf ${CONTAINER_TEST_ID}:/etc/nginx/.
21+
22+
docker exec -d ${CONTAINER_TEST_ID} /bin/bash -c "export LD_LIBRARY_PATH=/usr/local/lib && nginx"
23+
24+
25+
26+

config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ ngx_addon_name=ngx_http_auth_jwt_module
33
ngx_module_type=HTTP
44
ngx_module_name=ngx_http_auth_jwt_module
55
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_auth_jwt_module.c"
6+
ngx_module_libs="-ljansson -ljwt"
67

78
. auto/module

resources/nginx.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
user nginx;
3+
worker_processes 1;
4+
5+
error_log /var/log/nginx/error.log warn;
6+
pid /var/run/nginx.pid;
7+
8+
load_module modules/ngx_http_auth_jwt_module.so;
9+
10+
events {
11+
worker_connections 1024;
12+
}
13+
14+
15+
http {
16+
include /etc/nginx/mime.types;
17+
default_type application/octet-stream;
18+
19+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
20+
'$status $body_bytes_sent "$http_referer" '
21+
'"$http_user_agent" "$http_x_forwarded_for"';
22+
23+
access_log /var/log/nginx/access.log main;
24+
25+
sendfile on;
26+
#tcp_nopush on;
27+
28+
keepalive_timeout 65;
29+
30+
#gzip on;
31+
32+
include /etc/nginx/conf.d/*.conf;
33+
}
34+

resources/test-jwt-nginx.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server {
2+
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF";
3+
auth_jwt_loginurl "https://teslagov.com";
4+
auth_jwt_enabled off;
5+
6+
listen 8000;
7+
server_name localhost;
8+
9+
___location ~ ^/secure/ {
10+
auth_jwt_enabled on;
11+
root /usr/share/nginx;
12+
index index.html index.htm;
13+
}
14+
15+
___location / {
16+
root /usr/share/nginx/html;
17+
index index.html index.htm;
18+
}
19+
}
20+

test/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM centos:7
2+
3+
LABEL maintainer="TeslaGov" email="[email protected]"
4+
5+
ENV LD_LIBRARY_PATH=/usr/local/lib
6+
7+
COPY nginx.repo /etc/yum.repos.d/nginx.repo
8+
9+
# setup a test for the new module
10+
# download and run nginx binary
11+
RUN yum -y update && \
12+
yum -y install nginx-1.12.0 && \
13+
cp -r /usr/share/nginx/html /usr/share/nginx/secure
14+
15+
EXPOSE 8000
File renamed without changes.

0 commit comments

Comments
 (0)