Skip to content

Commit 1755cbd

Browse files
committed
cstrans-df-run: skip in-line comments in multi-line RUN
Needed for build of nginx-114-container-1-62.
1 parent 4bdab71 commit 1755cbd

File tree

4 files changed

+152
-2
lines changed

4 files changed

+152
-2
lines changed

cstrans-df-run.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class DockerFileTransformer {
4242
reLineRun_("^RUN (.*)$"),
4343
reLineRunExec_("^RUN *\\[(.*)\\] *$"),
4444
reLineCont_("(^.*[^\\\\])\\\\$"),
45+
reComment_("^ *#.*$"),
4546
lineNum_(0)
4647
{
4748
}
@@ -55,6 +56,7 @@ class DockerFileTransformer {
5556
const boost::regex reLineRun_; ///< match ... in RUN ...
5657
const boost::regex reLineRunExec_; ///< match ... in RUN [...]
5758
const boost::regex reLineCont_; ///< match ... in ... BS-NL
59+
const boost::regex reComment_; ///< match in-line comments
5860
int lineNum_; ///< line number being read
5961

6062
bool transformRunLine(std::string *);
@@ -190,7 +192,7 @@ bool DockerFileTransformer::transformRunLine(std::string *pRunLine)
190192
std::cerr << prog_name << " >>> " << newRunLine << std::endl;
191193
}
192194

193-
// return the result of a successful tranformation
195+
// return the result of a successful transformation
194196
*pRunLine = newRunLine;
195197
return true;
196198
}
@@ -208,7 +210,12 @@ bool DockerFileTransformer::transform(std::istream &in, std::ostream &out)
208210
while (std::getline(in, line)) {
209211
lineNum_++;
210212

211-
if (!readingRunLine && !boost::regex_match(line, reLineRun_)) {
213+
if (readingRunLine) {
214+
// check for comment because it does not need to end with back-slash
215+
if (boost::regex_match(line, reComment_))
216+
continue;
217+
}
218+
else if (!boost::regex_match(line, reLineRun_)) {
212219
// pass unrelated contents of Dockerfile unchanged
213220
out << line << std::endl;
214221
continue;

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,4 @@ tests_cstrans_df_run(0005)
213213
tests_cstrans_df_run(0006)
214214
tests_cstrans_df_run(0007)
215215
tests_cstrans_df_run(0008)
216+
tests_cstrans_df_run(0009)

tests/cstrans-df-run/0009-stdin.txt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
FROM ubi8/s2i-core:rhel8.1
2+
3+
# RHSCL rh-nginx114 image.
4+
5+
EXPOSE 8080
6+
EXPOSE 8443
7+
8+
ENV NAME=nginx \
9+
NGINX_VERSION=1.14 \
10+
NGINX_SHORT_VER=114 \
11+
VERSION=0
12+
13+
ENV SUMMARY="Platform for running nginx $NGINX_VERSION or building nginx-based application" \
14+
DESCRIPTION="Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP \
15+
protocols, with a strong focus on high concurrency, performance and low memory usage. The container \
16+
image provides a containerized packaging of the nginx $NGINX_VERSION daemon. The image can be used \
17+
as a base image for other applications based on nginx $NGINX_VERSION web server. \
18+
Nginx server image can be extended using source-to-image tool."
19+
20+
LABEL summary="${SUMMARY}" \
21+
description="${DESCRIPTION}" \
22+
io.k8s.description="${DESCRIPTION}" \
23+
io.k8s.display-name="Nginx ${NGINX_VERSION}" \
24+
io.openshift.expose-services="8080:http" \
25+
io.openshift.expose-services="8443:https" \
26+
io.openshift.tags="builder,${NAME},${NAME}-${NGINX_SHORT_VER}" \
27+
com.redhat.component="${NAME}-${NGINX_SHORT_VER}-container" \
28+
name="rhel8/${NAME}-${NGINX_SHORT_VER}" \
29+
version="1" \
30+
maintainer="SoftwareCollections.org <[email protected]>" \
31+
help="For more information visit https://github.com/sclorg/${NAME}-container" \
32+
usage="s2i build <SOURCE-REPOSITORY> rhel8/${NAME}-${NGINX_SHORT_VER}:latest <APP-NAME>"
33+
34+
ENV NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
35+
NGINX_CONF_PATH=/etc/nginx/nginx.conf \
36+
NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \
37+
NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \
38+
NGINX_APP_ROOT=${APP_ROOT} \
39+
NGINX_LOG_PATH=/var/log/nginx
40+
41+
RUN yum -y module enable nginx:$NGINX_VERSION && \
42+
INSTALL_PKGS="nss_wrapper bind-utils gettext hostname nginx" && \
43+
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
44+
rpm -V $INSTALL_PKGS && \
45+
yum clean all
46+
47+
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
48+
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
49+
50+
# Copy extra files to the image.
51+
COPY ./root/ /
52+
53+
# In order to drop the root user, we have to make some directories world
54+
# writeable as OpenShift default security model is to run the container under
55+
# random UID.
56+
RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf-fed.sed ${NGINX_CONF_PATH} && \
57+
chmod a+rwx ${NGINX_CONF_PATH} && \
58+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/ && \
59+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/ && \
60+
mkdir -p ${NGINX_APP_ROOT}/src/nginx-start/ && \
61+
mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
62+
mkdir -p ${NGINX_LOG_PATH} && \
63+
chmod -R a+rwx ${NGINX_APP_ROOT}/etc && \
64+
chmod -R a+rwx /var/lib/nginx && \
65+
chmod -R a+rwx ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
66+
chown -R 1001:0 ${NGINX_APP_ROOT} && \
67+
chown -R 1001:0 /var/lib/nginx && \
68+
chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
69+
# FIXME: Not sure if this is safe to do, just a hack to make the image work
70+
chmod -R a+rwx /var/run && \
71+
chown -R 1001:0 /var/run && \
72+
rpm-file-permissions
73+
74+
USER 1001
75+
76+
# Not using VOLUME statement since it's not working in OpenShift Online:
77+
# https://github.com/sclorg/httpd-container/issues/30
78+
# VOLUME ["/usr/share/nginx/html"]
79+
# VOLUME ["/var/log/nginx/"]
80+
81+
CMD $STI_SCRIPTS_PATH/usage

tests/cstrans-df-run/0009-stdout.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM ubi8/s2i-core:rhel8.1
2+
3+
# RHSCL rh-nginx114 image.
4+
5+
EXPOSE 8080
6+
EXPOSE 8443
7+
8+
ENV NAME=nginx \
9+
NGINX_VERSION=1.14 \
10+
NGINX_SHORT_VER=114 \
11+
VERSION=0
12+
13+
ENV SUMMARY="Platform for running nginx $NGINX_VERSION or building nginx-based application" \
14+
DESCRIPTION="Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP \
15+
protocols, with a strong focus on high concurrency, performance and low memory usage. The container \
16+
image provides a containerized packaging of the nginx $NGINX_VERSION daemon. The image can be used \
17+
as a base image for other applications based on nginx $NGINX_VERSION web server. \
18+
Nginx server image can be extended using source-to-image tool."
19+
20+
LABEL summary="${SUMMARY}" \
21+
description="${DESCRIPTION}" \
22+
io.k8s.description="${DESCRIPTION}" \
23+
io.k8s.display-name="Nginx ${NGINX_VERSION}" \
24+
io.openshift.expose-services="8080:http" \
25+
io.openshift.expose-services="8443:https" \
26+
io.openshift.tags="builder,${NAME},${NAME}-${NGINX_SHORT_VER}" \
27+
com.redhat.component="${NAME}-${NGINX_SHORT_VER}-container" \
28+
name="rhel8/${NAME}-${NGINX_SHORT_VER}" \
29+
version="1" \
30+
maintainer="SoftwareCollections.org <[email protected]>" \
31+
help="For more information visit https://github.com/sclorg/${NAME}-container" \
32+
usage="s2i build <SOURCE-REPOSITORY> rhel8/${NAME}-${NGINX_SHORT_VER}:latest <APP-NAME>"
33+
34+
ENV NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
35+
NGINX_CONF_PATH=/etc/nginx/nginx.conf \
36+
NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \
37+
NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \
38+
NGINX_APP_ROOT=${APP_ROOT} \
39+
NGINX_LOG_PATH=/var/log/nginx
40+
41+
RUN ["/opt/cov-sa-2019.09/bin/cov-build", "--dir=/cov", "--append-log", "sh", "-c", "yum -y module enable nginx:$NGINX_VERSION && INSTALL_PKGS=\"nss_wrapper bind-utils gettext hostname nginx\" && yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && rpm -V $INSTALL_PKGS && yum clean all"]
42+
43+
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
44+
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
45+
46+
# Copy extra files to the image.
47+
COPY ./root/ /
48+
49+
# In order to drop the root user, we have to make some directories world
50+
# writeable as OpenShift default security model is to run the container under
51+
# random UID.
52+
RUN ["/opt/cov-sa-2019.09/bin/cov-build", "--dir=/cov", "--append-log", "sh", "-c", "sed -i -f ${NGINX_APP_ROOT}/nginxconf-fed.sed ${NGINX_CONF_PATH} && chmod a+rwx ${NGINX_CONF_PATH} && mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/ && mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/ && mkdir -p ${NGINX_APP_ROOT}/src/nginx-start/ && mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && mkdir -p ${NGINX_LOG_PATH} && chmod -R a+rwx ${NGINX_APP_ROOT}/etc && chmod -R a+rwx /var/lib/nginx && chmod -R a+rwx ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && chown -R 1001:0 ${NGINX_APP_ROOT} && chown -R 1001:0 /var/lib/nginx && chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && chmod -R a+rwx /var/run && chown -R 1001:0 /var/run && rpm-file-permissions"]
53+
54+
USER 1001
55+
56+
# Not using VOLUME statement since it's not working in OpenShift Online:
57+
# https://github.com/sclorg/httpd-container/issues/30
58+
# VOLUME ["/usr/share/nginx/html"]
59+
# VOLUME ["/var/log/nginx/"]
60+
61+
CMD $STI_SCRIPTS_PATH/usage

0 commit comments

Comments
 (0)