From 3b87d4de64292683ab1be5b03af653e82aea2ec3 Mon Sep 17 00:00:00 2001 From: jianglai Date: Wed, 10 Apr 2019 14:03:56 -0700 Subject: [PATCH] Build the builder image in a script This makes it so that only one extra layer is added in the builder image, improving performance (may no longer relevant for newer versions of docker). See: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#minimize-the-number-of-layers ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=242936360 --- builder/Dockerfile | 38 +++++++++++++++++--------------------- builder/build.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 21 deletions(-) create mode 100755 builder/build.sh diff --git a/builder/Dockerfile b/builder/Dockerfile index 9abb36186..ba3d4e542 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -1,27 +1,23 @@ +# Copyright 2019 The Nomulus Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # This Dockerfile builds an image that can be used to build the nomulus app. # We need the following programs during Gradle build: # 1. Java 8 for compilation. # 2. Node.js/NPM for JavaScript compilation. # 3. Google Cloud SDK for generating the WARs. -# TODO: We should probably combine multile RUN statments into one so that only -# one layer is produced, but separating them makes it easier to experiment, as -# previous layers are cached. When we settle on the content, consider merging -# the RUNs. FROM marketplace.gcr.io/google/ubuntu1804 -ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update && apt-get install apt-utils -y && apt-get upgrade -y -RUN apt-get install -y locales lsb-release -# Cribbed from https://hub.docker.com/_/ubuntu -RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 -ENV LANG en_US.utf8 -RUN apt-get install openjdk-8-jdk-headless -y -RUN apt-get install npm -y -# Cribbed from https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu -RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ - echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" \ - | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ - | apt-key add - && apt-get update -y -RUN apt-get install google-cloud-sdk-app-engine-java -y -RUN apt-get remove apt-utils locales lsb-release -y && \ - apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* +ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 +ADD ./build.sh . +RUN ["bash", "./build.sh"] diff --git a/builder/build.sh b/builder/build.sh new file mode 100755 index 000000000..cf701a6da --- /dev/null +++ b/builder/build.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Copyright 2019 The Nomulus Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +apt-get install locales -y +locale-gen en_US.UTF-8 +apt-get install apt-utils -y +apt-get update -y +apt-get upgrade -y +# Install Java +apt-get install openjdk-8-jdk-headless -y +# Install npm +apt-get install npm -y +# Install gcloud +# Cribbed from https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu +apt-get install lsb-release -y +export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" +echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" \ + | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list +curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ + | apt-key add - +apt-get update -y +apt-get install google-cloud-sdk-app-engine-java -y +apt-get remove apt-utils locales lsb-release -y +apt-get autoclean -y +apt-get autoremove -y +rm -rf /var/lib/apt/lists/*