From 5c1bf545769e4e1169405db8224fb668516ffabc Mon Sep 17 00:00:00 2001 From: Yevhen Vydolob Date: Thu, 7 Feb 2019 14:15:53 +0200 Subject: [PATCH] #39 simplufy docker build Signed-off-by: Yevhen Vydolob --- build_and_push_docker_images.sh | 3 +-- dockerfiles/build.include | 10 +++++++++- dockerfiles/theia-dev/e2e/Dockerfile | 2 +- dockerfiles/theia/Dockerfile | 16 ++++++++-------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/build_and_push_docker_images.sh b/build_and_push_docker_images.sh index 83ead99a4..c69189ceb 100755 --- a/build_and_push_docker_images.sh +++ b/build_and_push_docker_images.sh @@ -30,8 +30,7 @@ for image_dir in "${DOCKER_FILES_LOCATIONS[@]}" do if [ "$image_dir" == "dockerfiles/theia" ]; then THEIA_IMAGE_TAG="$(awk '/ARG THEIA_VERSION=/{print $NF}' dockerfiles/theia/Dockerfile | cut -d '=' -f2)-nightly" - bash $(pwd)/$image_dir/build.sh --build-arg:GITHUB_TOKEN=${GITHUB_TOKEN} - bash $(pwd)/$image_dir/build.sh --build-args:GITHUB_TOKEN=${GITHUB_TOKEN},THEIA_VERSION=master --name:theia-master + bash $(pwd)/$image_dir/build.sh --build-args:GITHUB_TOKEN=${GITHUB_TOKEN},THEIA_VERSION=master --branch:master --git-ref:refs\\/heads\\/master elif [ "$image_dir" == "dockerfiles/theia-dev" ]; then bash $(pwd)/$image_dir/build.sh --build-arg:GITHUB_TOKEN=${GITHUB_TOKEN} else diff --git a/dockerfiles/build.include b/dockerfiles/build.include index 2c9edf55b..e83d71337 100755 --- a/dockerfiles/build.include +++ b/dockerfiles/build.include @@ -50,6 +50,8 @@ init() { BUILD_ARGS="" PARENT_IMAGE="" + BRANCH="" + GIT_REF="" while [ $# -gt 0 ]; do case $1 in @@ -84,6 +86,12 @@ init() { BUILD_ARGS_CSV="${1#*:}" prepare_build_args $BUILD_ARGS_CSV shift ;; + --branch:*) + BRANCH="${1#*:}" + shift ;; + --git-ref:*) + GIT_REF="${1#*:}" + shift ;; --*) printf "${RED}Unknown parameter: $1${NC}\n"; exit 2 ;; *) @@ -130,7 +138,7 @@ build() { build_image() { printf "${BOLD}Building Docker Image ${IMAGE_NAME} from $DIR directory with tag $TAG${NC}\n" # Replace macros in Dockerfiles - cat ${DIR}/${DOCKERFILE} | sed s/\$\{BUILD_ORGANIZATION\}/${ORGANIZATION}/ | sed s/\$\{BUILD_PREFIX\}/${PREFIX}/ | sed s/\$\{BUILD_TAG\}/${TAG}/ | sed s/\$\{BUILD_PARENT_IMAGE\}/${PARENT_IMAGE}/ > ${DIR}/.Dockerfile + cat ${DIR}/${DOCKERFILE} | sed s/\$\{BUILD_ORGANIZATION\}/${ORGANIZATION}/ | sed s/\$\{BUILD_PREFIX\}/${PREFIX}/ | sed s/\$\{BUILD_TAG\}/${TAG}/ | sed s/\$\{BUILD_PARENT_IMAGE\}/${PARENT_IMAGE}/ | sed s/\$\{GIT_BRANCH_NAME\}/${BRANCH}/ | sed s/\$\{GIT_REF\}/"${GIT_REF}"/ > ${DIR}/.Dockerfile cd "${DIR}" && docker build -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . rm ${DIR}/.Dockerfile if [ $? -eq 0 ]; then diff --git a/dockerfiles/theia-dev/e2e/Dockerfile b/dockerfiles/theia-dev/e2e/Dockerfile index f070a4046..5a5ae10e1 100644 --- a/dockerfiles/theia-dev/e2e/Dockerfile +++ b/dockerfiles/theia-dev/e2e/Dockerfile @@ -12,6 +12,6 @@ FROM ${BUILD_ORGANIZATION}/${BUILD_PREFIX}-theia-dev:${BUILD_TAG} ARG GITHUB_TOKEN # Just try to build the latest theia with current image -RUN git clone -b 'v0.3.17' --single-branch --depth 1 https://github.com/theia-ide/theia theia +RUN git clone -b 'v0.3.19' --single-branch --depth 1 https://github.com/theia-ide/theia theia RUN cd theia && yarn diff --git a/dockerfiles/theia/Dockerfile b/dockerfiles/theia/Dockerfile index dd5409443..e74f90681 100644 --- a/dockerfiles/theia/Dockerfile +++ b/dockerfiles/theia/Dockerfile @@ -40,16 +40,16 @@ RUN if [ ! -z "${GITHUB_TOKEN-}" ]; then \ fi #invalidate cashe -ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/theia-ide/theia/git/refs/heads/master /tmp/master.json +ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/theia-ide/theia/git/${GIT_REF} /tmp/master.json # Clone theia -#RUN git clone --branch v${THEIA_VERSION} --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code -RUN if [ $THEIA_VERSION == "master" ]; then \ - echo "Cloning Theia master branch"; \ - (git clone --branch master --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code) ; \ - else \ - (git clone --branch v${THEIA_VERSION} --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code); \ - fi +RUN git clone --branch ${GIT_BRANCH_NAME} --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code +# RUN if [ $THEIA_VERSION == "master" ]; then \ +# echo "Cloning Theia master branch"; \ +# (git clone --branch master --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code) ; \ +# else \ +# (git clone --branch v${THEIA_VERSION} --single-branch --depth 1 https://github.com/theia-ide/theia ${HOME}/theia-source-code); \ +# fi # Add patches ADD src/patches ${HOME}/patches