Skip to content

Commit a18ea66

Browse files
authored
Merge pull request #38 from 3scale/rover
drop luarocks in favour of rover
2 parents 9eb3075 + 5e8b1bd commit a18ea66

File tree

9 files changed

+58
-74
lines changed

9 files changed

+58
-74
lines changed

.s2i/bin/assemble

+6-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
#
1818
if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
1919
echo "---> Restoring build artifacts..."
20-
cp -vr /tmp/artifacts/. /usr/local/openresty/luajit/
20+
cp -vr /tmp/artifacts/. .
2121
rm -rf /tmp/artifacts/
2222
fi
2323

@@ -26,14 +26,11 @@ cp -Rf /tmp/src/. ./
2626

2727
echo "---> Building application from source..."
2828

29-
cd /opt/app
29+
export PATH="/usr/local/openresty/luajit/bin/:${PATH}"
3030

31-
if compgen -G "/tmp/src/*.rockspec" > /dev/null; then
32-
cp /tmp/src/*.rockspec /opt/app/
33-
find . -name "*.rockspec" -exec luarocks ${LUAROCKS_INSTALL:-make} {} \;
31+
if [ -e "/tmp/src/Roverfile.lock" ]; then
32+
echo "---> Installing dependencies"
33+
rover install --roverfile /tmp/src/Roverfile --path .
3434
fi
3535

36-
if [ ! -e "$(pwd)/bin" ];
37-
then
38-
ln -svf "$(pwd)/bin" "${HOME}"
39-
fi
36+
ln --verbose --symbolic /etc/ssl/certs/ca-bundle.crt "$(pwd)/conf" || true

.s2i/bin/assemble-runtime

-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,3 @@ if [[ "$1" == "-h" ]]; then
1414
fi
1515

1616
echo "---> Copying runtime artifacts"
17-
18-
ln --verbose --symbolic "$(pwd)/share/lua/"* /usr/local/share/lua/
19-
cp --verbose --recursive --no-target-directory --no-clobber "$(pwd)/app" "$(pwd)/src"
20-
ln --verbose --symbolic "$(pwd)/src/bin" "$(pwd)/bin"
21-
ln --verbose --symbolic "$(pwd)/src/http.d" "$(pwd)"
22-
ln --verbose --symbolic --force /etc/ssl/certs/ca-bundle.crt "$(pwd)/src/conf"

.s2i/bin/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
if [ -f /tmp/scripts/run ]; then
44
exec /tmp/scripts/run "$@"
55
else
6-
exec openresty -p /opt/app
6+
exec openresty -c "$(pwd)/conf/nginx.conf" -g "daemon off; error_log stderr ${LOG_LEVEL:=warn};";
77
fi

.s2i/bin/save-artifacts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
99
#
1010

11-
tar -cf - --directory=/usr/local/openresty/luajit lib/luarocks lib64/luarocks share/lua/5.1
11+
tar -cf - --directory=/opt/app-root/src lua_modules

Dockerfile

+20-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ FROM openshift/base-centos7
44

55
ARG OPENRESTY_RPM_VERSION="1.11.2.5"
66
ARG LUAROCKS_VERSION="2.3.0"
7-
ENV AUTO_UPDATE_INTERVAL=0 BUILDER_VERSION=0.1
87

98
LABEL io.k8s.description="Platform for building openresty" \
109
io.k8s.display-name="s2i Openresty centos 7 - ${OPENRESTY_RPM_VERSION}" \
@@ -18,53 +17,46 @@ RUN yum clean all -y \
1817
&& yum install -y epel-release \
1918
&& yum upgrade -y \
2019
&& yum install -y \
21-
luarocks \
22-
bind-utils \
2320
perl-Test-Nginx perl-JSON-WebToken \
24-
perl-TAP-Harness-JUnit \
21+
perl-TAP-Harness-JUnit \
2522
dnsmasq \
2623
&& yum install -y \
2724
openresty-${OPENRESTY_RPM_VERSION} \
2825
openresty-resty-${OPENRESTY_RPM_VERSION} \
2926
openresty-debug-${OPENRESTY_RPM_VERSION} \
3027
openresty-openssl \
3128
&& echo "Cleaning all dependencies" \
32-
&& yum clean all -y \
33-
&& mkdir -p /opt/app/logs /opt/app/conf \
34-
&& mkdir -p /usr/local/openresty/nginx \
35-
&& ln -s /opt/app/logs /usr/local/openresty/nginx/logs \
36-
&& ln -sf /dev/stdout /opt/app/logs/access.log \
37-
&& ln -sf /dev/stderr /opt/app/logs/error.log \
38-
&& ln -s /etc/ssl/certs/ca-bundle.crt /opt/app/conf
29+
&& yum clean all -y
3930

4031
# TODO (optional): Copy the builder files into /opt/app
4132
# COPY ./<builder_folder>/ /opt/app/
4233

43-
COPY ./.s2i/bin/ /usr/libexec/s2i
4434
COPY config-*.lua /etc/luarocks/
45-
ENV LUA_PATH=";;/usr/lib64/lua/5.1/?.lua" LUAROCKS_INSTALL=make
35+
36+
RUN \
37+
yum install -y luarocks && \
38+
ln -s /usr/lib64/lua/5.1/luarocks /usr/share/lua/5.1/luarocks && \
39+
luarocks install --server=http://luarocks.org/dev lua-rover && \
40+
yum -y remove luarocks && \
41+
mv /etc/luarocks/config-5.1.lua{.rpmsave,} && \
42+
chmod g+w "${HOME}/.cache" && \
43+
rm -rf /var/cache/yum && yum clean all -y && \
44+
rm -rf "${HOME}/.cache/luarocks" ./*
4645

4746
# override entrypoint to always setup luarocks paths
48-
RUN ln -sf /usr/libexec/s2i/entrypoint /usr/local/bin/container-entrypoint \
49-
&& ln -s /usr/lib64/lua/5.1/luarocks /usr/share/lua/5.1/luarocks
47+
RUN ln -sf /usr/libexec/s2i/entrypoint /usr/local/bin/container-entrypoint && \
48+
openresty -t && openresty-debug -t && \
49+
chmod -vR g+w /usr/local/openresty{,-*}/nginx/{*_temp,logs}
5050

51-
#TODO: Drop the root user and make the content of /opt/app owned by user 1001
52-
RUN mkdir -p -v /opt/app/logs /opt/app/http.d /usr/local/openresty/luajit/lib/luarocks "${HOME}/.cache" \
53-
&& chmod -v g+w /opt/app /opt/app/* \
54-
/usr/local/openresty/luajit/share/lua/5.1 \
55-
/usr/local/openresty/luajit/lib/lua/5.1 \
56-
/usr/local/openresty/luajit \
57-
/usr/local/openresty/luajit/lib/luarocks \
58-
/usr/local/openresty/luajit/bin/ \
59-
/usr/local/openresty/nginx/ \
60-
/usr/local/openresty/nginx/logs/ \
61-
"${HOME}/.cache"
51+
COPY ./.s2i/bin/ /usr/libexec/s2i
6252

6353
# This default user is created in the openshift/base-centos7 image
6454
USER 1001
6555

66-
RUN luarocks install --server=http://luarocks.org/dev lua-rover # 1
56+
ENV PATH="./lua_modules/bin:${PATH}" \
57+
LUA_PATH="./lua_modules/share/lua/5.1/?.lua;./lua_modules/share/lua/5.1/?/init.lua;;" \
58+
LUA_CPATH="./lua_modules/lib/lua/5.1/?.so;;"
6759

68-
WORKDIR /opt/app/
60+
WORKDIR ${HOME}
6961
EXPOSE 8080
7062
CMD ["usage"]

Dockerfile.runtime

+13-26
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,33 @@ FROM centos:centos7
33

44
ARG OPENRESTY_RPM_VERSION="1.11.2.5"
55

6-
ENV \
7-
BUILDER_VERSION=0.1 \
8-
# The $HOME is not set by default, but some applications needs this variable
9-
HOME=/opt/app-root/src \
6+
ENV HOME=/opt/app-root/src \
107
PATH=/opt/app-root/src/bin:/opt/app-root/bin:$PATH
118

129
RUN mkdir -p "${HOME}" && \
1310
useradd -u 1001 -r -g 0 -d ${HOME} -s /sbin/nologin \
1411
-c "Default Application User" default && \
1512
yum-config-manager --add-repo https://openresty.org/yum/centos/OpenResty.repo && \
1613
rpmkeys --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
17-
yum install -y bind-utils tar dnsmasq && \
14+
yum install -y tar dnsmasq && \
1815
yum install -y openresty-${OPENRESTY_RPM_VERSION} \
1916
openresty-resty-${OPENRESTY_RPM_VERSION} \
2017
openresty-openssl && \
21-
yum clean all -y && \
22-
mkdir /opt/app-root/src/logs && \
23-
mkdir -p /usr/local/openresty/nginx && \
24-
ln -s /opt/app-root/src/logs /usr/local/openresty/nginx/logs && \
25-
ln -s /dev/stdout /opt/app-root/src/logs/access.log && \
26-
ln -s /dev/stderr /opt/app-root/src/logs/error.log && \
27-
mkdir -p /usr/local/share/lua/ && \
28-
chmod g+w /usr/local/share/lua/ && \
29-
chown -R 1001:0 /opt/app-root /usr/local/share/lua/ \
30-
/usr/local/openresty/nginx/ \
31-
/usr/local/openresty/nginx/logs/ && \
32-
ln -s /opt/app-root/app /opt/app
33-
34-
LABEL \
35-
# Location of the STI scripts inside the image.
36-
io.openshift.s2i.scripts-url=image:///usr/libexec/s2i \
18+
yum clean all
19+
20+
LABEL io.openshift.s2i.scripts-url=image:///usr/libexec/s2i \
3721
io.k8s.description="Platform for building openresty" \
3822
io.k8s.display-name="s2i Openresty centos 7 - ${OPENRESTY_RPM_VERSION}"\
3923
io.openshift.expose-services="8080:http" \
40-
io.openshift.s2i.assemble-input-files="/usr/local/openresty/luajit/share;/opt/app" \
24+
io.openshift.s2i.assemble-input-files="/opt/app-root/src" \
4125
io.openshift.tags="builder,s2i,openresty"
4226

4327
COPY bin/ /usr/bin/
4428
COPY ./.s2i/bin/assemble* /usr/libexec/s2i/
4529

46-
#TODO: Drop the root user and make the content of /opt/app owned by user 1001
47-
RUN mkdir -p "${HOME}/logs" "${HOME}/http.d" && \
48-
chmod g+w "${HOME}" "${HOME}"/* "${HOME}/http.d" && \
49-
ln -s /opt/app-root/scripts/run /usr/libexec/s2i/
30+
RUN ln -vs /opt/app-root/src/scripts/run /usr/libexec/s2i/ && \
31+
openresty -t && \
32+
chmod -vR g+w /usr/local/openresty/nginx/{*_temp,logs}
5033

5134
# This default user is created in the openshift/base-centos7 image
5235
USER 1001
@@ -55,5 +38,9 @@ EXPOSE 8080
5538

5639
WORKDIR /opt/app-root
5740

41+
ENV PATH="./lua_modules/bin:${PATH}" \
42+
LUA_PATH="./lua_modules/share/lua/5.1/?.lua;./lua_modules/share/lua/5.1/?/init.lua;;" \
43+
LUA_CPATH="./lua_modules/lib/lua/5.1/?.so;;"
44+
5845
ENTRYPOINT ["container-entrypoint"]
5946
CMD ["/usr/libexec/s2i/usage"]

bin/container-entrypoint

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
#!/bin/bash
2-
exec "$@"
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
# s2i sets the default command to scripts/run.
6+
# Changing a directory would break that relative path.
7+
# So lets resolve it before changing the directory and use the absolute path.
8+
9+
args=("$@")
10+
cmd="$(readlink -e "${args[0]}")" || true
11+
12+
args[0]="${cmd:-${args[0]}}"
13+
14+
cd "${HOME}" # change to home directory
15+
16+
exec "${args[@]}"

test/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ test_config() {
173173
local cid=$1
174174
echo "Testing nginx config ..."
175175

176-
test=$(docker exec $(cat ${cid}) container-entrypoint openresty -p . -t)
176+
test=$(docker exec $(cat ${cid}) container-entrypoint bin/apicast --test)
177177

178178
return $?
179179
}

test/test-app

0 commit comments

Comments
 (0)