From: W. Trevor King Date: Sat, 28 Dec 2013 22:49:15 +0000 (-0800) Subject: Use envsubst instead of sed to parse Dockerfile.template X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a8fd8873eb81dac280dfea14aacd983e5465f2e7;p=dockerfile.git Use envsubst instead of sed to parse Dockerfile.template Convert everything in one pass, instead of taking a separate pass for each variable. Thanks to aluedeke for mentioning envsubst on #docker; I hadn't heard of it before. It's distributed as part of gettext [1], and not in POSIX [2], so it may be slightly less portable. However, envsubst and gettext are in Gentoo's x86 and amd64 stage1s, so it can't be *that* uncommon ;). [1]: http://www.gnu.org/software/gettext/ [2]: http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html --- diff --git a/README.md b/README.md index f11c5cb..6c45ce4 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,10 @@ Dockerfiles are sorted into directories with names matching the suggested repository. To avoid duplicating ephemeral data (namespace, timestamp tag, …), they appear in the `Dockerfile.template` as markers -(`NAMESPACE`, `TAG`, …). The `build.sh` script replaces the markers -with values while generating a `Dockerfile` from each -`Dockerfile.template`, and then builds each tag with: +(`${NAMESPACE}`, `${TAG}`, …). The `build.sh` script replaces the +markers with values while generating a `Dockerfile` from each +`Dockerfile.template` (using [envsubst][]), and then builds each tag +with: $ docker build -t $NAMESPACE/$REPO:$TAG $REPO @@ -48,5 +49,6 @@ from the host. [Docker]: http://www.docker.io/ [Dockerfiles]: http://www.docker.io/learn/dockerfile/ [Gentoo]: http://www.gentoo.org/ +[envsubst]: http://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html [parameter-expansion]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 [3156]: https://github.com/dotcloud/docker/issues/3156 diff --git a/build.sh b/build.sh index d4ad779..5d59a7a 100755 --- a/build.sh +++ b/build.sh @@ -120,10 +120,16 @@ for REPO in ${REPOS}; do REPO_IMAGES=$(docker images "${NAMESPACE}/${REPO}") REPO_MATCHES=$(echo "${REPO_IMAGES}" | grep "${DATE}") if [ -z "${REPO_MATCHES}" ]; then - cp "${REPO}/Dockerfile.template" "${REPO}/Dockerfile" - sed -i "s|TAG|${DATE}|g" "${REPO}/Dockerfile" - sed -i "s|NAMESPACE|${NAMESPACE}|g" "${REPO}/Dockerfile" - sed -i "s|MAINTAINER.*|MAINTAINER ${AUTHOR}|g" "${REPO}/Dockerfile" + env -i \ + NAMESPACE="${NAMESPACE}" \ + TAG="${DATE}" \ + MAINTAINER="${AUTHOR}" \ + envsubst ' + ${NAMESPACE} + ${TAG} + ${MAINTAINER} + ' \ + < "${REPO}/Dockerfile.template" > "${REPO}/Dockerfile" docker build -t "${NAMESPACE}/${REPO}:${DATE}" "${REPO}" || die "failed to build" fi docker tag -f "${NAMESPACE}/${REPO}:${DATE}" "${NAMESPACE}/${REPO}:latest" || die "failed to tag" diff --git a/buildbot/Dockerfile.template b/buildbot/Dockerfile.template index 1acad24..ccf3ab8 100644 --- a/buildbot/Dockerfile.template +++ b/buildbot/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN echo 'USE="${USE} sqlite"' >> /etc/portage/make.conf RUN echo 'PYTHON_TARGETS="python2_7 python3_3"' >> /etc/portage/make.conf RUN echo 'PYTHON_SINGLE_TARGET="python3_3"' >> /etc/portage/make.conf diff --git a/elasticsearch/Dockerfile.template b/elasticsearch/Dockerfile.template index fa71ff0..baeec80 100644 --- a/elasticsearch/Dockerfile.template +++ b/elasticsearch/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-java:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-java:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN echo 'app-misc/elasticsearch ~amd64' >> /etc/portage/package.accept_keywords RUN emerge -v app-misc/elasticsearch RUN eselect news read new diff --git a/gentoo-en-us/Dockerfile.template b/gentoo-en-us/Dockerfile.template index 9ae7040..cb595fd 100644 --- a/gentoo-en-us/Dockerfile.template +++ b/gentoo-en-us/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-portage:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-portage:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN echo en_US ISO-8859-1 > /etc/locale.gen RUN echo en_US.UTF-8 UTF-8 >> /etc/locale.gen RUN locale-gen diff --git a/gentoo-java/Dockerfile.template b/gentoo-java/Dockerfile.template index 1e153b9..4c5cf1a 100644 --- a/gentoo-java/Dockerfile.template +++ b/gentoo-java/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN echo 'USE="${USE} -X -cups"' >> /etc/portage/make.conf RUN emerge -v dev-java/icedtea-bin RUN eselect news read new diff --git a/gentoo-portage/Dockerfile.template b/gentoo-portage/Dockerfile.template index bc5fc9c..4bae466 100644 --- a/gentoo-portage/Dockerfile.template +++ b/gentoo-portage/Dockerfile.template @@ -22,8 +22,8 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo:TAG -MAINTAINER A. U. Thor +FROM ${NAMESPACE}/gentoo:${TAG} +MAINTAINER ${MAINTAINER} RUN sed -i 's/#rc_sys=""/rc_sys="lxc"/g' /etc/rc.conf RUN echo 'GENTOO_MIRRORS="http://mirror.mcs.anl.gov/pub/gentoo/"' >> /etc/portage/make.conf #RUN echo 'SYNC="rsync://rsync.us.gentoo.org"' >> /etc/portage/make.conf diff --git a/gentoo-syslog/Dockerfile.template b/gentoo-syslog/Dockerfile.template index 9550b71..7f5ee25 100644 --- a/gentoo-syslog/Dockerfile.template +++ b/gentoo-syslog/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-en-us:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-en-us:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN emerge -v sys-process/vixie-cron app-admin/syslog-ng app-admin/logrotate RUN rc-update add syslog-ng default RUN rc-update add vixie-cron default diff --git a/kibana/Dockerfile.template b/kibana/Dockerfile.template index d335dfa..231b316 100644 --- a/kibana/Dockerfile.template +++ b/kibana/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/nginx:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/nginx:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN wget https://download.elasticsearch.org/kibana/kibana/kibana-3.0.0milestone4.tar.gz RUN tar -xvf kibana-3.0.0milestone4.tar.gz --strip-components 1 -C /var/www/localhost/htdocs RUN sed -i 's|"http://"+window.location.hostname+":9200"|"ELASTICSEARCH_URL"|' /var/www/localhost/htdocs/config.js diff --git a/memcached/Dockerfile.template b/memcached/Dockerfile.template index 4522fcb..f983cf1 100644 --- a/memcached/Dockerfile.template +++ b/memcached/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN emerge -v net-misc/memcached RUN eselect news read new RUN rc-update add memcached default diff --git a/nginx/Dockerfile.template b/nginx/Dockerfile.template index bdae994..3cf7124 100644 --- a/nginx/Dockerfile.template +++ b/nginx/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN echo 'NGINX_MODULES_HTTP="access auth_basic autoindex charset fastcgi gzip gzip_static limit_req map proxy rewrite scgi ssi stub_status"' >> /etc/portage/make.conf RUN echo 'NGINX_MODULES_MAIL=""' >> /etc/portage/make.conf RUN emerge -v www-servers/nginx diff --git a/portage/Dockerfile.template b/portage/Dockerfile.template index 65d1520..7c321f9 100644 --- a/portage/Dockerfile.template +++ b/portage/Dockerfile.template @@ -22,8 +22,8 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/portage-import:TAG -MAINTAINER A. U. Thor +FROM ${NAMESPACE}/portage-import:${TAG} +MAINTAINER ${MAINTAINER} # -volumes-from doesn't map names, so we need to shift /portage to # /usr/portage. Add a statically-linked BusyBox for RUN commands. diff --git a/postgresql/Dockerfile.template b/postgresql/Dockerfile.template index 456cf09..a69b695 100644 --- a/postgresql/Dockerfile.template +++ b/postgresql/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN emerge -v dev-db/postgresql-server RUN eselect news read new RUN rc-update add $(basename /etc/init.d/postgresql-*) default diff --git a/redis/Dockerfile.template b/redis/Dockerfile.template index 081956f..1b3e394 100644 --- a/redis/Dockerfile.template +++ b/redis/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN emerge -v dev-db/redis RUN eselect news read new RUN rc-update add redis default diff --git a/stunnel/Dockerfile.template b/stunnel/Dockerfile.template index d5ed4ad..2074174 100644 --- a/stunnel/Dockerfile.template +++ b/stunnel/Dockerfile.template @@ -22,9 +22,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -FROM NAMESPACE/gentoo-syslog:TAG -MAINTAINER A. U. Thor -#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +FROM ${NAMESPACE}/gentoo-syslog:${TAG} +MAINTAINER ${MAINTAINER} +#VOLUME ["${PORTAGE}:/usr/portage:ro", "${PORTAGE}/distfiles:/usr/portage/distfiles:rw"] RUN emerge -v net-misc/stunnel RUN eselect news read new RUN rc-update add stunnel default