diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index bb28ded6..15eac57d 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -31,4 +31,4 @@ jobs: brew install boost boost-python3 help2man - name: Build and check - run: make distcheck CMAKE='cmake -DPython3_EXECUTABLE=/opt/homebrew/bin/python3.12' + run: make distcheck CMAKE="cmake -DPython3_EXECUTABLE=/opt/homebrew/bin/$(brew info boost-python3 | grep -oE 'python@3.\d+' | tr -d @)" diff --git a/src/cstrans-df-run.cc b/src/cstrans-df-run.cc index 66b7c8d4..6d6778ec 100644 --- a/src/cstrans-df-run.cc +++ b/src/cstrans-df-run.cc @@ -33,11 +33,31 @@ typedef std::vector TStringList; const char *prog_name; +/// read non-empty list from value map "vm" with key "key" and store to "dst" +template +bool readListFromValMap(TDst *pDst, const TMap &vm, const char *key) +{ + if (!vm.count(key)) + // "key" not found in "vm" + return false; + + // store the list to "*pDst" and return "true" if the list is not empty + TDst &dst = *pDst; + dst = vm[key].template as(); + return !dst.empty(); +} + +/// transformation properties set on cmd-line +struct TransformerProps { + TStringList prefixCmd; ///< cmd-line operands + bool shellForm; ///< if true, write shell form of RUN lines + bool verbose; ///< if true, print in/out of each transformation +}; + class DockerFileTransformer { public: - DockerFileTransformer(const TStringList &prefixCmd, const bool verbose): - prefixCmd_(prefixCmd), - verbose_(verbose), + DockerFileTransformer(const TransformerProps &tp): + tp_(tp), lineNum_(0) { } @@ -46,9 +66,8 @@ class DockerFileTransformer { bool transform(std::istream &in, std::ostream &out); private: - const TStringList prefixCmd_; ///< cmd-line operands - const bool verbose_; ///< --verbose on cmd-line - int lineNum_; ///< line number being read + const TransformerProps tp_; ///< props set on cmd-line + int lineNum_; ///< line number being read void transformRunLine(std::string *); @@ -66,6 +85,9 @@ class DockerFileTransformer { /// match in-line comments const RE reComment_ = RE("^\\s*#.*$"); + + /// construct transformed RUN command from execList + std::string runCmdFromExecList(const TStringList &execList); }; /// parse serialized list in the form: "item1", "item2", ... @@ -141,19 +163,51 @@ void appendShellExec(TStringList *pExecList, const std::string &str) pExecList->push_back(str); } -/// precede each back-slash and each quote by back-slash -std::string runQuoteArg(std::string arg) +/// precede selected special chars by back-slash +std::string runQuoteArg(std::string arg, const bool escapeTick=false) { boost::algorithm::replace_all(arg, "\\", "\\\\"); boost::algorithm::replace_all(arg, "\"", "\\\""); boost::algorithm::replace_all(arg, "\n", "\\n"); boost::algorithm::replace_all(arg, "\t", "\\t"); + + if (escapeTick) + boost::algorithm::replace_all(arg, "'", "\\'"); + return arg; } -std::string runCmdFromExecList(const TStringList &execList) +/// construct "'cmd' 'arg1' 'arg2' ..." from execList +std::string runShellCmdFromExecList(const TStringList &execList) +{ + std::string cmd; + + int i = 0; + for (const std::string &arg : execList) { + if (i++) + // space-separator + cmd += " "; + + const std::string quoted = runQuoteArg(arg, /* escapeTick */ true); + if (quoted != arg) + // construct $'...' + cmd += "$"; + + // append the quoted arg + cmd += "'" + quoted + "'"; + } + + return cmd; +} + +/// construct transformed RUN command from execList +std::string DockerFileTransformer::runCmdFromExecList( + const TStringList &execList) { - // construct RUN ["cmd", "arg1", "arg2", ...] from execList + if (this->tp_.shellForm) + return runShellCmdFromExecList(execList); + + // construct ["cmd", "arg1", "arg2", ...] from execList std::string runLine = "["; int i = 0; for (const std::string &arg : execList) { @@ -178,7 +232,7 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine) const std::string cmd = sm[2]; // start with the prefix specified on cmd-line - TStringList execList = prefixCmd_; + TStringList execList = tp_.prefixCmd; if (boost::regex_match(cmd, sm, reLineRunExec_)) // ["cmd", "arg1", "arg2", ...] @@ -187,8 +241,8 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine) // arbitrary shell code... appendShellExec(&execList, cmd); - newRunLine += runCmdFromExecList(execList); - if (verbose_) { + newRunLine += this->runCmdFromExecList(execList); + if (tp_.verbose) { // diagnostic output printed with --verbose std::cerr << prog_name << " <<< " << *pRunLine << std::endl; std::cerr << prog_name << " >>> " << newRunLine << std::endl; @@ -314,6 +368,8 @@ int main(int argc, char *argv[]) desc.add_options() ("in-place,i", po::value(), "modify the specified file in-place") + ("shell-form", "write transformed RUN lines using the shell form" + " (rather than exec form, which is the default format)") ("verbose", "print transformations to standard error output"); desc.add_options() @@ -351,21 +407,19 @@ int main(int argc, char *argv[]) return 0; } - const bool verbose = !!vm.count("verbose"); - - if (!vm.count("prefix-cmd")) { - desc.print(std::cerr); - return 1; - } + // read cmd-line flags + TransformerProps tp; + tp.shellForm = !!vm.count("shell-form"); + tp.verbose = !!vm.count("verbose"); - const TStringList &prefixCmd = vm["prefix-cmd"].as(); - if (prefixCmd.empty()) { + // read the prefix command + if (!readListFromValMap(&tp.prefixCmd, vm, "prefix-cmd")) { desc.print(std::cerr); return 1; } - // pass cmd-line args to DockerFileTransformer - DockerFileTransformer dft(prefixCmd, verbose); + // create the transformer object + DockerFileTransformer dft(tp); if (vm.count("in-place")) // transform Dockerfile in-place diff --git a/tests/cstrans-df-run/0001-sf-stdout.txt b/tests/cstrans-df-run/0001-sf-stdout.txt new file mode 100644 index 00000000..06ead6fb --- /dev/null +++ b/tests/cstrans-df-run/0001-sf-stdout.txt @@ -0,0 +1,38 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +ARG ALERTMANAGER_GOPATH=/go/src/github.com/prometheus/alertmanager +ARG BUILD_PROMU=false +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'cd ${ALERTMANAGER_GOPATH} && yum install -y prometheus-promu && make build && yum clean all' + +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +ARG ALERTMANAGER_GOPATH=/go/src/github.com/prometheus/alertmanager +COPY --from=builder ${ALERTMANAGER_GOPATH}/amtool /bin/amtool +COPY --from=builder ${ALERTMANAGER_GOPATH}/alertmanager /bin/alertmanager +COPY --from=builder ${ALERTMANAGER_GOPATH}/examples/ha/alertmanager.yml /etc/alertmanager/alertmanager.yml + +EXPOSE 9093 +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'mkdir -p /alertmanager' +VOLUME [ "/alertmanager" ] +WORKDIR /etc/alertmanager +ENTRYPOINT [ "/bin/alertmanager" ] +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " \ + name="openshift/ose-prometheus-alertmanager" \ + License="ASL 2.0" \ + io.k8s.display-name="Prometheus Alert Manager" \ + io.openshift.build.source-location="https://github.com/openshift/prometheus-alertmanager" \ + io.openshift.build.commit.url="https://github.com/openshift/prometheus-alertmanager/commit/39c2c111ea818cd16dbd11e31cc682cf2b4042d3" \ + version="v4.1.0" \ + io.openshift.build.commit.id="39c2c111ea818cd16dbd11e31cc682cf2b4042d3" \ + release="201905191700" \ + vendor="Red Hat" \ + io.openshift.tags="openshift,prometheus" + diff --git a/tests/cstrans-df-run/0002-sf-stdout.txt b/tests/cstrans-df-run/0002-sf-stdout.txt new file mode 100644 index 00000000..c72c78fd --- /dev/null +++ b/tests/cstrans-df-run/0002-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'cd ${ALERTMANAGER_GOPATH} && yum install -y prometheus-promu && make build && yum clean all' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0003-sf-stdout.txt b/tests/cstrans-df-run/0003-sf-stdout.txt new file mode 100644 index 00000000..c8773311 --- /dev/null +++ b/tests/cstrans-df-run/0003-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'make' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0004-sf-stdout.txt b/tests/cstrans-df-run/0004-sf-stdout.txt new file mode 100644 index 00000000..26f84bbc --- /dev/null +++ b/tests/cstrans-df-run/0004-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'go' 'build' '--verbose' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0005-sf-stdout.txt b/tests/cstrans-df-run/0005-sf-stdout.txt new file mode 100644 index 00000000..2d81fd0f --- /dev/null +++ b/tests/cstrans-df-run/0005-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'echo \"OK\"' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0006-sf-stdout.txt b/tests/cstrans-df-run/0006-sf-stdout.txt new file mode 100644 index 00000000..2d81fd0f --- /dev/null +++ b/tests/cstrans-df-run/0006-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'echo \"OK\"' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0007-sf-stdout.txt b/tests/cstrans-df-run/0007-sf-stdout.txt new file mode 100644 index 00000000..198dacd5 --- /dev/null +++ b/tests/cstrans-df-run/0007-sf-stdout.txt @@ -0,0 +1,79 @@ +# +# This is the OpenShift ovn overlay network image. +# it provides an overlay network using ovs/ovn/ovn-kube +# +# The standard name for this image is ovn-kube + +# Notes: +# This is for a build where the ovn-kubernetes utilities +# are built in this Dockerfile and included in the image (instead of the rpm) +# + +FROM openshift/golang-builder:1.10 AS builder +ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b + +WORKDIR /go-controller +COPY go-controller/ . + +# build the binaries +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'make' + +FROM openshift/ose-cli:v4.1.0-201905191700 AS cli +ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b + +FROM openshift/ose-base:v4.1.0-201905191700 +ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b + +USER root + +ENV PYTHONDONTWRITEBYTECODE yes + +# install needed rpms - openvswitch must be 2.9.2 or higher +# install selinux-policy first to avoid a race +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'yum install -y \tselinux-policy && \tyum clean all' + +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'yum install -y \tPyYAML bind-utils \topenssl \tnumactl-libs \tfirewalld-filesystem \tlibpcap \thostname \t\"openvswitch2.11\" \t\"openvswitch2.11-ovn-common\" \t\"openvswitch2.11-ovn-central\" \t\"openvswitch2.11-ovn-host\" \t\"openvswitch2.11-ovn-vtep\" \t\"openvswitch2.11-devel\" \tcontainernetworking-plugins \tiproute strace socat && \tyum clean all' + +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'rm -rf /var/cache/yum' + +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'mkdir -p /var/run/openvswitch && mkdir -p /etc/cni/net.d && mkdir -p /opt/cni/bin && mkdir -p /usr/libexec/cni/' + +COPY --from=builder /go-controller/_output/go/bin/ovnkube /usr/bin/ +COPY --from=builder /go-controller/_output/go/bin/ovn-kube-util /usr/bin/ +COPY --from=builder /go-controller/_output/go/bin/ovn-k8s-cni-overlay /usr/libexec/cni/ovn-k8s-cni-overlay + +COPY --from=cli /usr/bin/oc /usr/bin +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'ln -s /usr/bin/oc /usr/bin/kubectl' + +# copy git commit number into image +COPY .git/HEAD /root/.git/HEAD +COPY .git/refs/heads/ /root/.git/refs/heads/ + +# ovnkube.sh is the entry point. This script examines environment +# variables to direct operation and configure ovn +COPY dist/images/ovnkube.sh /root/ +COPY dist/images/ovn-debug.sh /root/ +# override the rpm's ovn_k8s.conf with this local copy +COPY dist/images/ovn_k8s.conf /etc/openvswitch/ovn_k8s.conf + + + +WORKDIR /root +ENTRYPOINT /root/ovnkube.sh + +LABEL \ + io.k8s.description="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \ + com.redhat.component="ose-ovn-kubernetes-container" \ + maintainer="Phil Cameron " \ + name="openshift/ose-ovn-kubernetes" \ + License="GPLv2+" \ + io.k8s.display-name="ovn kubernetes" \ + io.openshift.build.source-location="https://github.com/openshift/ovn-kubernetes" \ + summary="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \ + io.openshift.build.commit.url="https://github.com/openshift/ovn-kubernetes/commit/674977b1fdf0f966970179b9fae338f8347b2dfe" \ + version="v4.1.0" \ + io.openshift.build.commit.id="674977b1fdf0f966970179b9fae338f8347b2dfe" \ + release="201905231545" \ + vendor="Red Hat" \ + io.openshift.tags="openshift" + diff --git a/tests/cstrans-df-run/0008-sf-stdout.txt b/tests/cstrans-df-run/0008-sf-stdout.txt new file mode 100644 index 00000000..fa6c67d8 --- /dev/null +++ b/tests/cstrans-df-run/0008-sf-stdout.txt @@ -0,0 +1,13 @@ +FROM openshift/golang-builder:1.11 AS builder +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 +COPY . ${ALERTMANAGER_GOPATH} +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'echo \tOK\n' +FROM ubi7:7.6-159 +ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11 + +CMD [ "--storage.path=/alertmanager" ] + +LABEL \ + io.k8s.description="This is the Prometheus Alert Manager image." \ + com.redhat.component="golang-github-prometheus-alertmanager-container" \ + maintainer="OpenShift Development " diff --git a/tests/cstrans-df-run/0009-sf-stdout.txt b/tests/cstrans-df-run/0009-sf-stdout.txt new file mode 100644 index 00000000..8bf1f3b3 --- /dev/null +++ b/tests/cstrans-df-run/0009-sf-stdout.txt @@ -0,0 +1,61 @@ +FROM ubi8/s2i-core:rhel8.1 + +# RHSCL rh-nginx114 image. + +EXPOSE 8080 +EXPOSE 8443 + +ENV NAME=nginx \ + NGINX_VERSION=1.14 \ + NGINX_SHORT_VER=114 \ + VERSION=0 + +ENV SUMMARY="Platform for running nginx $NGINX_VERSION or building nginx-based application" \ + DESCRIPTION="Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP \ +protocols, with a strong focus on high concurrency, performance and low memory usage. The container \ +image provides a containerized packaging of the nginx $NGINX_VERSION daemon. The image can be used \ +as a base image for other applications based on nginx $NGINX_VERSION web server. \ +Nginx server image can be extended using source-to-image tool." + +LABEL summary="${SUMMARY}" \ + description="${DESCRIPTION}" \ + io.k8s.description="${DESCRIPTION}" \ + io.k8s.display-name="Nginx ${NGINX_VERSION}" \ + io.openshift.expose-services="8080:http" \ + io.openshift.expose-services="8443:https" \ + io.openshift.tags="builder,${NAME},${NAME}-${NGINX_SHORT_VER}" \ + com.redhat.component="${NAME}-${NGINX_SHORT_VER}-container" \ + name="rhel8/${NAME}-${NGINX_SHORT_VER}" \ + version="1" \ + maintainer="SoftwareCollections.org " \ + help="For more information visit https://github.com/sclorg/${NAME}-container" \ + usage="s2i build rhel8/${NAME}-${NGINX_SHORT_VER}:latest " + +ENV NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \ + NGINX_CONF_PATH=/etc/nginx/nginx.conf \ + NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \ + NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \ + NGINX_APP_ROOT=${APP_ROOT} \ + NGINX_LOG_PATH=/var/log/nginx + +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' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH + +# Copy extra files to the image. +COPY ./root/ / + +# In order to drop the root user, we have to make some directories world +# writeable as OpenShift default security model is to run the container under +# random UID. +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' + +USER 1001 + +# Not using VOLUME statement since it's not working in OpenShift Online: +# https://github.com/sclorg/httpd-container/issues/30 +# VOLUME ["/usr/share/nginx/html"] +# VOLUME ["/var/log/nginx/"] + +CMD $STI_SCRIPTS_PATH/usage diff --git a/tests/cstrans-df-run/0010-sf-stdout.txt b/tests/cstrans-df-run/0010-sf-stdout.txt new file mode 100644 index 00000000..d6b7934e --- /dev/null +++ b/tests/cstrans-df-run/0010-sf-stdout.txt @@ -0,0 +1,38 @@ +#@follow_tag(registry-proxy.engineering.redhat.com/rh-osbs/openshift-golang-builder:v1.19.10-202306161322.el8.g42c8e14) +FROM registry-proxy.engineering.redhat.com/rh-osbs/openshift-golang-builder:v1.19.10-202306161322.el8.g42c8e14 AS builder + +COPY $REMOTE_SOURCE $REMOTE_SOURCE_DIR +WORKDIR $REMOTE_SOURCE_DIR/app +USER root +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'dnf install -y --setopt=tsflags=nodocs git' +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'sed -i \'s/CGO_ENABLED=0 //;s/containers_image_openpgp/& strictfipsruntime/\' Makefile' +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'go mod vendor && GOEXPERIMENT=strictfipsruntime make build VERSION=${CI_CONTAINER_VERSION}' + +#@follow_tag(registry.redhat.io/ubi8/podman) +FROM registry.redhat.io/ubi8/podman:8.8-14.1697647490 + +LABEL com.redhat.component="quay-builder-container" +LABEL name="quay/quay-builder-rhel8" +LABEL version=${CI_CONTAINER_VERSION} +LABEL io.k8s.display-name="Red Hat Quay - Builder" +LABEL io.k8s.description="Red Hat Quay image builder" +LABEL summary="Red Hat Quay image builder" +LABEL maintainer "hgovinda@redhat.com" + +COPY --from=builder $REMOTE_SOURCE_DIR/app/bin/quay-builder /usr/local/bin/quay-builder +COPY --from=builder $REMOTE_SOURCE_DIR/app/buildpack/ssh-git.sh /ssh-git.sh +COPY --from=builder $REMOTE_SOURCE_DIR/app/entrypoint.sh /home/podman/entrypoint.sh + +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'set -ex\t; dnf install -y --setopt=tsflags=nodocs --setopt=skip_missing_names_on_install=False git wget \t; dnf -y update && dnf -y -q clean all' + +# Rootless/unprivileged buildah configurations +# https://github.com/containers/buildah/blob/main/docs/tutorials/05-openshift-rootless-build.md +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' $'touch /etc/subgid /etc/subuid && chmod g=u /etc/subgid /etc/subuid /etc/passwd && echo \'podman:100000:65536\' > /etc/subuid && echo \'podman:100000:65536\' > /etc/subgid && \tmkdir -p /home/podman/.config/containers && (echo \'[storage]\';echo \'driver = \"vfs\"\') > /home/podman/.config/containers/storage.conf && sed -i \'s/short-name-mode=\"enforcing\"/short-name-mode=\"permissive\"/g\' /etc/containers/registries.conf && \tmkdir /certs /home/podman/.config/cni && chown podman:podman /certs /home/podman/.config/cni' + +VOLUME ["/tmp", "/certs"] + +WORKDIR /home/podman + +USER podman + +ENTRYPOINT ["sh", "/home/podman/entrypoint.sh"] diff --git a/tests/cstrans-df-run/0011-sf-stdout.txt b/tests/cstrans-df-run/0011-sf-stdout.txt new file mode 100644 index 00000000..06a457a0 --- /dev/null +++ b/tests/cstrans-df-run/0011-sf-stdout.txt @@ -0,0 +1,24 @@ +## Python cuda base ################################################################# +FROM cuda-base AS python-cuda-base + +ENV VIRTUAL_ENV=/opt/vllm +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# install cuda and common dependencies +RUN --mount=type=cache,target=/root/.cache/pip --mount=type=bind,source=requirements-common.txt,target=requirements-common.txt --mount=type=bind,source=requirements-cuda.txt,target=requirements-cuda.txt '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'pip install -r requirements-cuda.txt' + +## Development ################################################################# +FROM python-cuda-base AS dev + +# install build and runtime dependencies +RUN --mount=type=cache,target=/root/.cache/pip --mount=type=bind,source=requirements-common.txt,target=requirements-common.txt --mount=type=bind,source=requirements-cuda.txt,target=requirements-cuda.txt --mount=type=bind,source=requirements-dev.txt,target=requirements-dev.txt --mount=type=bind,source=requirements-lint.txt,target=requirements-lint.txt --mount=type=bind,source=requirements-test.txt,target=requirements-test.txt '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'pip3 install -r requirements-cuda.txt -r requirements-dev.txt' + +## Builder ##################################################################### +FROM dev AS build + +# install build dependencies +RUN --mount=type=cache,target=/root/.cache/pip --mount=type=bind,source=requirements-build.txt,target=requirements-build.txt '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'pip install -r requirements-build.txt' + +# install compiler cache to speed up compilation leveraging local or remote caching +# git is required for the cutlass kernels +RUN '/opt/cov-sa-2019.09/bin/cov-build' '--dir=/cov' '--append-log' 'sh' '-c' 'rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && rpm -ql epel-release && microdnf install -y git ccache && microdnf clean all' diff --git a/tests/cstrans-df-run/CMakeLists.txt b/tests/cstrans-df-run/CMakeLists.txt index b5b13fc6..8ef4c395 100644 --- a/tests/cstrans-df-run/CMakeLists.txt +++ b/tests/cstrans-df-run/CMakeLists.txt @@ -16,24 +16,32 @@ # along with csdiff. If not, see . # a generic template for cstrans-df-run tests -macro(tests_cstrans_df_run tst) +macro(test_cstrans_df_run_core tst opt tag) set(test_data_prefix "${CMAKE_CURRENT_SOURCE_DIR}/${tst}") set(cmd "${CMAKE_BINARY_DIR}/src/cstrans-df-run") - set(cmd "${cmd} -- /opt/cov-sa-2019.09/bin/cov-build --dir=/cov --append-log") + set(cmd "${cmd} ${opt} -- /opt/cov-sa-2019.09/bin/cov-build --dir=/cov --append-log") set(cmd "${cmd} <${test_data_prefix}-stdin.txt") - set(cmd "${cmd} | ${diffcmd} ${test_data_prefix}-stdout.txt -") + set(cmd "${cmd} | ${diffcmd} ${test_data_prefix}${tag}-stdout.txt -") add_test_wrap("cstrans-df-run-${tst}" "${cmd}") endmacro() +macro(test_cstrans_df_run tst) + # add default test using exec form + test_cstrans_df_run_core(${tst} "" "") + + # add another test using shell form + test_cstrans_df_run_core(${tst} "--shell-form" "-sf") +endmacro() + # cstrans-df-run tests -tests_cstrans_df_run(0001) -tests_cstrans_df_run(0002) -tests_cstrans_df_run(0003) -tests_cstrans_df_run(0004) -tests_cstrans_df_run(0005) -tests_cstrans_df_run(0006) -tests_cstrans_df_run(0007) -tests_cstrans_df_run(0008) -tests_cstrans_df_run(0009) -tests_cstrans_df_run(0010) -tests_cstrans_df_run(0011) +test_cstrans_df_run(0001) +test_cstrans_df_run(0002) +test_cstrans_df_run(0003) +test_cstrans_df_run(0004) +test_cstrans_df_run(0005) +test_cstrans_df_run(0006) +test_cstrans_df_run(0007) +test_cstrans_df_run(0008) +test_cstrans_df_run(0009) +test_cstrans_df_run(0010) +test_cstrans_df_run(0011) diff --git a/tests/cstrans-df-run/sync.zsh b/tests/cstrans-df-run/sync.zsh index ae57d797..dcbe28bf 100755 --- a/tests/cstrans-df-run/sync.zsh +++ b/tests/cstrans-df-run/sync.zsh @@ -12,10 +12,15 @@ else tests=( "$@" ) fi +TEST_BIN=${PROJECT_ROOT}/csdiff_build/src/cstrans-df-run + for tst in "${tests[@]}"; do tst=${tst%-stdin.txt} - ${PROJECT_ROOT}/csdiff_build/src/cstrans-df-run \ - ${TEST_ARGS[@]} \ + ${TEST_BIN} ${TEST_ARGS[@]} \ < ${tst}-stdin.txt \ > ${tst}-stdout.txt + + ${TEST_BIN} --shell-form ${TEST_ARGS[@]} \ + < ${tst}-stdin.txt \ + > ${tst}-sf-stdout.txt done