From 84d53bfcba001b5f772c391e92c7059d1c843d4c Mon Sep 17 00:00:00 2001 From: chabad360 Date: Tue, 3 Mar 2020 05:03:13 +0000 Subject: [PATCH 1/8] convert edge build to travis.sh --- .travis.yml | 36 ++++++++----------------- travis.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 25 deletions(-) create mode 100755 travis.sh diff --git a/.travis.yml b/.travis.yml index 8158bb93..18c0d604 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ before_install: - if [[ $BUILD == "development" ]];then sudo apt-get update && sudo apt-get -y install docker-compose; fi + - chmod u+x ./travis.sh after_success: - docker --version @@ -22,43 +23,28 @@ matrix: - name: "Build Frappe python environment (edge)" if: branch = develop AND type != pull_request script: - - docker build -t frappe-worker -f build/frappe-worker/Dockerfile . - - docker tag frappe-worker frappe/frappe-worker:edge - - docker tag frappe-worker frappe/frappe-worker:develop - - docker push frappe/frappe-worker:edge - - docker push frappe/frappe-worker:develop + - ./travis.sh --worker --tag edge --name frappe + - ./travis.sh --worker --tag develop --name frappe --tag-only - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - docker build -t frappe-assets -f build/frappe-assets/Dockerfile . - - docker tag frappe-assets frappe/frappe-assets:edge - - docker tag frappe-assets frappe/frappe-assets:develop - - docker push frappe/frappe-assets:edge - - docker push frappe/frappe-assets:develop + - ./travis.sh --assets --tag edge --name frappe + - ./travis.sh --assets --tag develop --name frappe --tag-only - name: "Build ERPNext python environment (edge)" if: branch = develop AND type != pull_request script: - - docker build -t erpnext-worker -f build/erpnext-worker/Dockerfile . - - docker tag erpnext-worker frappe/erpnext-worker:edge - - docker tag erpnext-worker frappe/erpnext-worker:develop - - docker push frappe/erpnext-worker:edge - - docker push frappe/erpnext-worker:develop + - ./travis.sh --worker --tag edge --name erpnext + - ./travis.sh --worker --tag develop --name erpnext --tag-only - name: "Build ERPNext nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - docker build -t erpnext-assets -f build/erpnext-assets/Dockerfile . - - docker tag erpnext-assets frappe/erpnext-assets:edge - - docker tag erpnext-assets frappe/erpnext-assets:develop - - docker push frappe/erpnext-assets:edge - - docker push frappe/erpnext-assets:develop + - ./travis.sh --assets --tag edge --name erpnext + - ./travis.sh --assets --tag develop --name erpnext --tag-only - name: "Build Frappe socketio service (edge)" if: branch = develop AND type != pull_request script: - - docker build -t frappe-socketio -f build/frappe-socketio/Dockerfile . - - docker tag frappe-socketio frappe/frappe-socketio:edge - - docker tag frappe-socketio frappe/frappe-socketio:develop - - docker push frappe/frappe-socketio:edge - - docker push frappe/frappe-socketio:develop + - ./travis.sh --socketio --tag edge --name frappe + - ./travis.sh --socketio --tag develop --name frappe --tag-only - name: "Build Frappe python environment (v12)" if: branch = master AND type != pull_request script: diff --git a/travis.sh b/travis.sh new file mode 100755 index 00000000..dc813fbf --- /dev/null +++ b/travis.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +################# travis.sh ################# +# This script takes care of the common steps +# found in the Travis CI builds. + +POSITIONAL=() +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -t|--tag) + TAG="$2" + shift + shift + ;; + -w|--worker) + WORKER=1 + shift + ;; + -a|--assets) + ASSETS=1 + shift + ;; + -s|--socketio) + SOCKETIO=1 + shift + ;; + -n|--name) + NAME="$2" + shift + shift + ;; + -o|--tag-only) + TAGONLY=1 + shift + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; + esac +done + +function tagAndPush() { + echo "Tagging ${1} as \"${2}\" and pushing" + docker tag ${1} frappe/${1}:${2} + docker push frappe/${1}:${2} +} + +function build () { + echo "Building ${1} ${3} image" + docker build -t ${1}-${3} -f build/${1}-worker/Dockerfile . + tagAndPush "${1}-${3}" ${2} +} + +if [[ $WORKER ]]; then + if [[ $TAGONLY ]]; then + tagAndPush "${NAME}-worker" ${TAG} + else + build $NAME $TAG worker + fi +elif [[ $ASSETS ]]; then + if [[ $TAGONLY ]]; then + tagAndPush "${NAME}-assets" ${TAG} + else + build $NAME $TAG assets + fi +elif [[ $SOCKETIO ]]; then + if [[ $TAGONLY ]]; then + tagAndPush "${NAME}-socketio" ${TAG} + else + build $NAME $TAG socketio + fi +fi \ No newline at end of file From ca715e3e5cde352435a29c3b5da1a95e37ad3568 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Tue, 3 Mar 2020 05:27:18 +0000 Subject: [PATCH 2/8] add versioning support to travis.sh --- .travis.yml | 140 +++++++++++----------------------------------------- travis.sh | 36 ++++++++++---- 2 files changed, 56 insertions(+), 120 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18c0d604..64d829bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,140 +48,60 @@ matrix: - name: "Build Frappe python environment (v12)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-12 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-worker:$VERSION -f build/frappe-worker/v12.Dockerfile . - - docker tag frappe/frappe-worker:$VERSION frappe/frappe-worker:version-12 - - docker tag frappe/frappe-worker:$VERSION frappe/frappe-worker:v12 - - docker push frappe/frappe-worker:$VERSION - - docker push frappe/frappe-worker:version-12 - - docker push frappe/frappe-worker:v12 + - ./travis.sh --worker --git-branch 12 --name frappe + - ./travis.sh --worker --tag v12 --name frappe --tag-only + - ./travis.sh --worker --tag version-12 --name frappe --tag-only - name: "Build Frappe nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-12 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-assets:$VERSION -f build/frappe-assets/v12.Dockerfile . - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:version-12 - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:v12 - - docker push frappe/frappe-assets:$VERSION - - docker push frappe/frappe-assets:version-12 - - docker push frappe/frappe-assets:v12 + - ./travis.sh --assets --git-branch 12 --name frappe + - ./travis.sh --assets --tag v12 --name frappe --tag-only + - ./travis.sh --assets --tag version-12 --name frappe --tag-only - name: "Build ERPNext python environment (v12)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/erpnext --branch version-12 - - cd erpnext - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/erpnext-worker:$VERSION -f build/erpnext-worker/v12.Dockerfile . - - docker tag frappe/erpnext-worker:$VERSION frappe/erpnext-worker:version-12 - - docker tag frappe/erpnext-worker:$VERSION frappe/erpnext-worker:v12 - - docker push frappe/erpnext-worker:$VERSION - - docker push frappe/erpnext-worker:version-12 - - docker push frappe/erpnext-worker:v12 + - ./travis.sh --worker --git-branch 12 --name erpnext + - ./travis.sh --worker --tag v12 --name erpnext --tag-only + - ./travis.sh --worker --tag version-12 --name erpnext --tag-only - name: "Build ERPNext nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/erpnext --branch version-12 - - cd erpnext - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/erpnext-assets:$VERSION -f build/erpnext-assets/v12.Dockerfile . - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:version-12 - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:v12 - - docker push frappe/erpnext-assets:$VERSION - - docker push frappe/erpnext-assets:version-12 - - docker push frappe/erpnext-assets:v12 + - ./travis.sh --assets --git-branch 12 --name erpnext + - ./travis.sh --assets --tag v12 --name erpnext --tag-only + - ./travis.sh --assets --tag version-12 --name erpnext --tag-only - name: "Build Frappe socketio service (v12)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-12 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-socketio:$VERSION -f build/frappe-socketio/v12.Dockerfile . - - docker tag frappe/frappe-socketio:$VERSION frappe/frappe-socketio:version-12 - - docker tag frappe/frappe-socketio:$VERSION frappe/frappe-socketio:v12 - - docker push frappe/frappe-socketio:$VERSION - - docker push frappe/frappe-socketio:version-12 - - docker push frappe/frappe-socketio:v12 + - ./travis.sh --socketio --git-branch 12 --name frappe + - ./travis.sh --socketio --tag v12 --name frappe --tag-only + - ./travis.sh --socketio --tag version-12 --name frappe --tag-only - name: "Build Frappe python environment (v11)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-11 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-worker:$VERSION -f build/frappe-worker/v11.Dockerfile . - - docker tag frappe/frappe-worker:$VERSION frappe/frappe-worker:version-11 - - docker tag frappe/frappe-worker:$VERSION frappe/frappe-worker:v11 - - docker push frappe/frappe-worker:$VERSION - - docker push frappe/frappe-worker:version-11 - - docker push frappe/frappe-worker:v11 + - ./travis.sh --worker --git-branch 11 --name frappe + - ./travis.sh --worker --tag v11 --name frappe --tag-only + - ./travis.sh --worker --tag version-11 --name frappe --tag-only - name: "Build Frappe nginx + static assets (v11)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-11 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-assets:$VERSION -f build/frappe-assets/v11.Dockerfile . - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:version-11 - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:v11 - - docker push frappe/frappe-assets:$VERSION - - docker push frappe/frappe-assets:version-11 - - docker push frappe/frappe-assets:v11 + - ./travis.sh --assets --git-branch 11 --name frappe + - ./travis.sh --assets --tag v11 --name frappe --tag-only + - ./travis.sh --assets --tag version-11 --name frappe --tag-only - name: "Build ERPNext python environment (v11)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/erpnext --branch version-11 - - cd erpnext - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/erpnext-worker:$VERSION -f build/erpnext-worker/v11.Dockerfile . - - docker tag frappe/erpnext-worker:$VERSION frappe/erpnext-worker:version-11 - - docker tag frappe/erpnext-worker:$VERSION frappe/erpnext-worker:v11 - - docker push frappe/erpnext-worker:$VERSION - - docker push frappe/erpnext-worker:version-11 - - docker push frappe/erpnext-worker:v11 + - ./travis.sh --worker --git-branch 11 --name erpnext + - ./travis.sh --worker --tag v11 --name erpnext --tag-only + - ./travis.sh --worker --tag version-11 --name erpnext --tag-only - name: "Build ERPNext nginx + static assets (v11)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/erpnext --branch version-11 - - cd erpnext - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/erpnext-assets:$VERSION -f build/erpnext-assets/v11.Dockerfile . - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:version-11 - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:v11 - - docker push frappe/erpnext-assets:$VERSION - - docker push frappe/erpnext-assets:version-11 - - docker push frappe/erpnext-assets:v11 + - ./travis.sh --assets --git-branch 11 --name erpnext + - ./travis.sh --assets --tag v11 --name erpnext --tag-only + - ./travis.sh --assets --tag version-11 --name erpnext --tag-only - name: "Build Frappe socketio service (v11)" if: branch = master AND type != pull_request script: - - git clone https://github.com/frappe/frappe --branch version-11 - - cd frappe - - git fetch --tags - - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - - cd .. - - docker build -t frappe/frappe-socketio:$VERSION -f build/frappe-socketio/v11.Dockerfile . - - docker tag frappe/frappe-socketio:$VERSION frappe/frappe-socketio:version-11 - - docker tag frappe/frappe-socketio:$VERSION frappe/frappe-socketio:v11 - - docker push frappe/frappe-socketio:$VERSION - - docker push frappe/frappe-socketio:version-11 - - docker push frappe/frappe-socketio:v11 + - ./travis.sh --socketio --git-branch 11 --name erpnext + - ./travis.sh --socketio --tag v11 --name erpnext --tag-only + - ./travis.sh --socketio --tag version-11 --name erpnext --tag-only diff --git a/travis.sh b/travis.sh index dc813fbf..e375abec 100755 --- a/travis.sh +++ b/travis.sh @@ -4,7 +4,6 @@ # This script takes care of the common steps # found in the Travis CI builds. -POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1" @@ -35,13 +34,24 @@ while [[ $# -gt 0 ]]; do TAGONLY=1 shift ;; - *) # unknown option - POSITIONAL+=("$1") # save it in an array for later - shift # past argument + -g|--git-branch) + BRANCH="$2" + shift + shift ;; esac done +function gitVersion() { + echo "Pulling ${1} v${2}" + git clone https://github.com/frappe/${1} --branch version-${2} + cd ${1} + git fetch --tags + TAG=$(git tag --list --sort=-version:refname "v${2}*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') + cd .. + DOCKERFILE="v${2}.Dockerfile" +} + function tagAndPush() { echo "Tagging ${1} as \"${2}\" and pushing" docker tag ${1} frappe/${1}:${2} @@ -49,27 +59,33 @@ function tagAndPush() { } function build () { - echo "Building ${1} ${3} image" - docker build -t ${1}-${3} -f build/${1}-worker/Dockerfile . + echo "Building ${1} ${3} image using ${4}" + docker build -t ${1}-${3} -f build/${1}-${3}/${4:-Dockerfile} . tagAndPush "${1}-${3}" ${2} } +if [[ $BRANCH ]]; then + gitVersion $NAME $BRANCH +fi + +DOCKERFILE=${DOCKERFILE:-Dockerfile} + if [[ $WORKER ]]; then if [[ $TAGONLY ]]; then - tagAndPush "${NAME}-worker" ${TAG} + tagAndPush "${NAME}-worker" ${TAG} else - build $NAME $TAG worker + build $NAME $TAG worker ${DOCKERFILE} fi elif [[ $ASSETS ]]; then if [[ $TAGONLY ]]; then tagAndPush "${NAME}-assets" ${TAG} else - build $NAME $TAG assets + build $NAME $TAG assets ${DOCKERFILE} fi elif [[ $SOCKETIO ]]; then if [[ $TAGONLY ]]; then tagAndPush "${NAME}-socketio" ${TAG} else - build $NAME $TAG socketio + build $NAME $TAG socketio ${DOCKERFILE} fi fi \ No newline at end of file From 37eabd9018c7d7bad5c2535be816a10f415e4f58 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Tue, 3 Mar 2020 05:56:14 +0000 Subject: [PATCH 3/8] add a help file and alphabetize --- travis.sh | 119 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 30 deletions(-) diff --git a/travis.sh b/travis.sh index e375abec..58943b87 100755 --- a/travis.sh +++ b/travis.sh @@ -1,13 +1,61 @@ #!/bin/bash -################# travis.sh ################# +################# ./travis.sh ################# # This script takes care of the common steps -# found in the Travis CI builds. +# found in the frappe_docker Travis CI builds. +# +# Usage: [-a | -s | -w | -h] [-n ] [-t | -g ] [-o] +# +# Argumets: +# +# -a | --assets (exclusive): Build the nginx + static assets image +# -s | --socketio (exclusive): Build the frappe-socketio image +# -w | --worker (exclusive): Build the python environment image +# -h | --help (exclusive): Print this page +# +# -n | --service : Name of the service to build: "erpnext" or "frappe" +# Note: --socketio does not respect this argument +# Note: This will build an image with the name "$SERVICE-assets" (i.e. "erpnext-worker", "frappe-assets", etc.) +# +# -t | --tag (exclusive): The image tag (i.e. erpnext-worker:$TAG ) +# -g | --git-version (exclusive): The version number of --service (i.e. "11", "12", etc.) +# Note: This must be a number, not a string! +# +# -o | --tag-only: Only tag an image and push it. +# +# + while [[ $# -gt 0 ]]; do key="$1" case $key in + -a|--assets) + ASSETS=1 + shift + ;; + -g|--git-version) + version="$2" + shift + shift + ;; + -h|--help) + HELP=1 + shift + ;; + -n|--service) + SERVICE="$2" + shift + shift + ;; + -o|--tag-only) + TAGONLY=1 + shift + ;; + -s|--socketio) + SOCKETIO=1 + shift + ;; -t|--tag) TAG="$2" shift @@ -17,31 +65,37 @@ while [[ $# -gt 0 ]]; do WORKER=1 shift ;; - -a|--assets) - ASSETS=1 - shift - ;; - -s|--socketio) - SOCKETIO=1 - shift - ;; - -n|--name) - NAME="$2" + *) + HELP=1 shift - shift - ;; - -o|--tag-only) - TAGONLY=1 - shift - ;; - -g|--git-branch) - BRANCH="$2" - shift - shift ;; esac done +function help() { + echo "################ $0 #################" + echo " This script takes care of the common steps found in the frappe_docker Travis CI builds." + echo "" + echo " Usage: [-a | -s | -w | -h] [-n ] [-t | -g ] [-o]" + echo "" + echo " Argumets:" + echo "" + echo " -a | --assets (exclusive): Build the nginx + static assets image" + echo " -s | --socketio (exclusive): Build the frappe-socketio image" + echo " -w | --worker (exclusive): Build the python environment image" + echo " -h | --help (exclusive): Print this page" + echo "" + echo " -n | --service : Name of the service to build: \"erpnext\" or \"frappe\"" + echo " Note: --socketio does not respect this argument" + echo " Note: This will build an image with the name \"\$SERVICE-assets\" (i.e. \"erpnext-worker\", \"frappe-assets\", etc.)" + echo "" + echo " -t | --tag (exclusive): The image tag (i.e. erpnext-worker:\$TAG)" + echo " -g | --git-version (exclusive): The version number of --service (i.e. \"11\", \"12\", etc.)" + echo " Note: This must be a number, not a string!" + echo "" + echo " -o | --tag-only: Only tag an image and push it." +} + function gitVersion() { echo "Pulling ${1} v${2}" git clone https://github.com/frappe/${1} --branch version-${2} @@ -64,28 +118,33 @@ function build () { tagAndPush "${1}-${3}" ${2} } -if [[ $BRANCH ]]; then - gitVersion $NAME $BRANCH +if [[ HELP ]]; then + help + exit 1 +fi + +if [[ $VERSION ]]; then + gitVersion $SERVICE $VERSION fi DOCKERFILE=${DOCKERFILE:-Dockerfile} if [[ $WORKER ]]; then if [[ $TAGONLY ]]; then - tagAndPush "${NAME}-worker" ${TAG} + tagAndPush "${SERVICE}-worker" ${TAG} else - build $NAME $TAG worker ${DOCKERFILE} + build $SERVICE $TAG worker ${DOCKERFILE} fi elif [[ $ASSETS ]]; then if [[ $TAGONLY ]]; then - tagAndPush "${NAME}-assets" ${TAG} + tagAndPush "${SERVICE}-assets" ${TAG} else - build $NAME $TAG assets ${DOCKERFILE} + build $SERVICE $TAG assets ${DOCKERFILE} fi elif [[ $SOCKETIO ]]; then if [[ $TAGONLY ]]; then - tagAndPush "${NAME}-socketio" ${TAG} + tagAndPush "frappe-socketio" ${TAG} else - build $NAME $TAG socketio ${DOCKERFILE} + build frappe $TAG socketio ${DOCKERFILE} fi fi \ No newline at end of file From 77aca4d3cc627dff3f536cebbfc9c309072c4621 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Tue, 3 Mar 2020 06:04:17 +0000 Subject: [PATCH 4/8] organize travis.yml a bit --- .travis.yml | 112 ++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64d829bd..0440e032 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,85 +23,87 @@ matrix: - name: "Build Frappe python environment (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --worker --tag edge --name frappe - - ./travis.sh --worker --tag develop --name frappe --tag-only + - ./travis.sh --worker --service frappe --tag edge + - ./travis.sh --worker --service frappe --tag develop --tag-only - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --assets --tag edge --name frappe - - ./travis.sh --assets --tag develop --name frappe --tag-only + - ./travis.sh --assets --service frappe --tag edge + - ./travis.sh --assets --service frappe --tag develop--tag-only - name: "Build ERPNext python environment (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --worker --tag edge --name erpnext - - ./travis.sh --worker --tag develop --name erpnext --tag-only + - ./travis.sh --worker --service erpnext --tag edge + - ./travis.sh --worker --service erpnext --tag develop --tag-only - name: "Build ERPNext nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --assets --tag edge --name erpnext - - ./travis.sh --assets --tag develop --name erpnext --tag-only + - ./travis.sh --assets --service erpnext --tag edge + - ./travis.sh --assets --service erpnext --tag develop --tag-only - name: "Build Frappe socketio service (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --socketio --tag edge --name frappe - - ./travis.sh --socketio --tag develop --name frappe --tag-only + - ./travis.sh --socketio --service frappe --tag edge + - ./travis.sh --socketio --service frappe --tag develop --tag-only - name: "Build Frappe python environment (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --git-branch 12 --name frappe - - ./travis.sh --worker --tag v12 --name frappe --tag-only - - ./travis.sh --worker --tag version-12 --name frappe --tag-only + - ./travis.sh --worker --service frappe --git-branch 12 + - ./travis.sh --worker --service frappe --tag v12 --tag-only + - ./travis.sh --worker --service frappe --tag version-12 --tag-only - name: "Build Frappe nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --git-branch 12 --name frappe - - ./travis.sh --assets --tag v12 --name frappe --tag-only - - ./travis.sh --assets --tag version-12 --name frappe --tag-only + - ./travis.sh --assets --service frappe --git-branch 12 + - ./travis.sh --assets --service frappe --tag v12 --tag-only + - ./travis.sh --assets --service frappe --tag version-12 --tag-only - name: "Build ERPNext python environment (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --git-branch 12 --name erpnext - - ./travis.sh --worker --tag v12 --name erpnext --tag-only - - ./travis.sh --worker --tag version-12 --name erpnext --tag-only + - ./travis.sh --worker --service erpnext --git-branch 12 + - ./travis.sh --worker --service erpnext --tag v12 --tag-only + - ./travis.sh --worker --service erpnext --tag version-12 --tag-only - name: "Build ERPNext nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --git-branch 12 --name erpnext - - ./travis.sh --assets --tag v12 --name erpnext --tag-only - - ./travis.sh --assets --tag version-12 --name erpnext --tag-only - - name: "Build Frappe socketio service (v12)" - if: branch = master AND type != pull_request - script: - - ./travis.sh --socketio --git-branch 12 --name frappe - - ./travis.sh --socketio --tag v12 --name frappe --tag-only - - ./travis.sh --socketio --tag version-12 --name frappe --tag-only - - name: "Build Frappe python environment (v11)" - if: branch = master AND type != pull_request - script: - - ./travis.sh --worker --git-branch 11 --name frappe - - ./travis.sh --worker --tag v11 --name frappe --tag-only - - ./travis.sh --worker --tag version-11 --name frappe --tag-only - - name: "Build Frappe nginx + static assets (v11)" - if: branch = master AND type != pull_request - script: - - ./travis.sh --assets --git-branch 11 --name frappe - - ./travis.sh --assets --tag v11 --name frappe --tag-only - - ./travis.sh --assets --tag version-11 --name frappe --tag-only - - name: "Build ERPNext python environment (v11)" - if: branch = master AND type != pull_request - script: - - ./travis.sh --worker --git-branch 11 --name erpnext - - ./travis.sh --worker --tag v11 --name erpnext --tag-only - - ./travis.sh --worker --tag version-11 --name erpnext --tag-only - - name: "Build ERPNext nginx + static assets (v11)" - if: branch = master AND type != pull_request - script: - - ./travis.sh --assets --git-branch 11 --name erpnext - - ./travis.sh --assets --tag v11 --name erpnext --tag-only - - ./travis.sh --assets --tag version-11 --name erpnext --tag-only + - ./travis.sh --assets --service erpnext--git-branch 12 + - ./travis.sh --assets --service erpnext --tag v12 --tag-only + - ./travis.sh --assets --service erpnext --tag version-12 --tag-only - name: "Build Frappe socketio service (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --socketio --git-branch 11 --name erpnext - - ./travis.sh --socketio --tag v11 --name erpnext --tag-only - - ./travis.sh --socketio --tag version-11 --name erpnext --tag-only + - ./travis.sh --socketio --service frappe --git-branch 11 + - ./travis.sh --socketio --service frappe --tag v11 --tag-only + - ./travis.sh --socketio --service frappe --tag version-11 --tag-only + - name: "Build Frappe python environment (v11)" + if: branch = master AND type != pull_request + script: + - ./travis.sh --worker --service frappe --git-branch 11 + - ./travis.sh --worker --service frappe --tag v11 --tag-only + - ./travis.sh --worker --service frappe --tag version-11 --tag-only + - name: "Build Frappe nginx + static assets (v11)" + if: branch = master AND type != pull_request + script: + - ./travis.sh --assets --service frappe --git-branch 11 + - ./travis.sh --assets --service frappe --tag v11 --tag-only + - ./travis.sh --assets --service frappe --tag version-11 --tag-only + - name: "Build ERPNext python environment (v11)" + if: branch = master AND type != pull_request + script: + - ./travis.sh --worker --service erpnext --git-branch 11 + - ./travis.sh --worker --service erpnext --tag v11 --tag-only + - ./travis.sh --worker --service erpnext --tag version-11 --tag-only + - name: "Build ERPNext nginx + static assets (v11)" + if: branch = master AND type != pull_request + script: + - ./travis.sh --assets --service erpnext--git-branch 11 + - ./travis.sh --assets --service erpnext --tag v11 --tag-only + - ./travis.sh --assets --service erpnext --tag version-11 --tag-only + - name: "Build Frappe socketio service (v11)" + if: branch = master AND type != pull_request + script: + - ./travis.sh --socketio --service frappe --git-branch 11 + - ./travis.sh --socketio --service frappe --tag v11 --tag-only + - ./travis.sh --socketio --service frappe --tag version-11 --tag-only + + \ No newline at end of file From 8c008730653474b4729590a2e1c3e7c2cf0ea8f2 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Wed, 4 Mar 2020 02:15:59 +0000 Subject: [PATCH 5/8] swap out travis.sh for python and be compat with #100 --- .travis.yml | 82 ++++++++++++++-------------- travis.py | 66 +++++++++++++++++++++++ travis.sh | 150 ---------------------------------------------------- 3 files changed, 107 insertions(+), 191 deletions(-) create mode 100755 travis.py delete mode 100755 travis.sh diff --git a/.travis.yml b/.travis.yml index 0440e032..a01d8898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: - if [[ $BUILD == "development" ]];then sudo apt-get update && sudo apt-get -y install docker-compose; fi - - chmod u+x ./travis.sh + - chmod u+x ./travis.py after_success: - docker --version @@ -23,87 +23,87 @@ matrix: - name: "Build Frappe python environment (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --worker --service frappe --tag edge - - ./travis.sh --worker --service frappe --tag develop --tag-only + - ./travis.py frappe --worker --tag edge + - ./travis.py frappe --worker --tag develop --tag-only - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --assets --service frappe --tag edge - - ./travis.sh --assets --service frappe --tag develop--tag-only + - ./travis.py frappe --nginx --tag edge + - ./travis.py frappe --nginx --tag develop--tag-only - name: "Build ERPNext python environment (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --worker --service erpnext --tag edge - - ./travis.sh --worker --service erpnext --tag develop --tag-only + - ./travis.py erpnext --worker --tag edge + - ./travis.py erpnext --worker --tag develop --tag-only - name: "Build ERPNext nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --assets --service erpnext --tag edge - - ./travis.sh --assets --service erpnext --tag develop --tag-only + - ./travis.py erpnext --nginx --tag edge + - ./travis.py erpnext --nginx --tag develop --tag-only - name: "Build Frappe socketio service (edge)" if: branch = develop AND type != pull_request script: - - ./travis.sh --socketio --service frappe --tag edge - - ./travis.sh --socketio --service frappe --tag develop --tag-only + - ./travis.py frappe --socketio --tag edge + - ./travis.py frappe --socketio --tag develop --tag-only - name: "Build Frappe python environment (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --service frappe --git-branch 12 - - ./travis.sh --worker --service frappe --tag v12 --tag-only - - ./travis.sh --worker --service frappe --tag version-12 --tag-only + - ./travis.py frappe --worker --git-branch 12 + - ./travis.py frappe --worker --tag v12 --tag-only + - ./travis.py frappe --worker --tag version-12 --tag-only - name: "Build Frappe nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --service frappe --git-branch 12 - - ./travis.sh --assets --service frappe --tag v12 --tag-only - - ./travis.sh --assets --service frappe --tag version-12 --tag-only + - ./travis.py frappe --nginx --git-branch 12 + - ./travis.py frappe --nginx --tag v12 --tag-only + - ./travis.py frappe --nginx --tag version-12 --tag-only - name: "Build ERPNext python environment (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --service erpnext --git-branch 12 - - ./travis.sh --worker --service erpnext --tag v12 --tag-only - - ./travis.sh --worker --service erpnext --tag version-12 --tag-only + - ./travis.py erpnext --worker --git-branch 12 + - ./travis.py erpnext --worker --tag v12 --tag-only + - ./travis.py erpnext --worker --tag version-12 --tag-only - name: "Build ERPNext nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --service erpnext--git-branch 12 - - ./travis.sh --assets --service erpnext --tag v12 --tag-only - - ./travis.sh --assets --service erpnext --tag version-12 --tag-only + - ./travis.py erpnext --nginx --git-branch 12 + - ./travis.py erpnext --nginx --tag v12 --tag-only + - ./travis.py erpnext --nginx --tag version-12 --tag-only - name: "Build Frappe socketio service (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --socketio --service frappe --git-branch 11 - - ./travis.sh --socketio --service frappe --tag v11 --tag-only - - ./travis.sh --socketio --service frappe --tag version-11 --tag-only + - ./travis.py frappe --socketio --git-branch 11 + - ./travis.py frappe --socketio --tag v11 --tag-only + - ./travis.py frappe --socketio --tag version-11 --tag-only - name: "Build Frappe python environment (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --service frappe --git-branch 11 - - ./travis.sh --worker --service frappe --tag v11 --tag-only - - ./travis.sh --worker --service frappe --tag version-11 --tag-only + - ./travis.py frappe --worker --git-branch 11 + - ./travis.py frappe --worker --tag v11 --tag-only + - ./travis.py frappe --worker --tag version-11 --tag-only - name: "Build Frappe nginx + static assets (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --service frappe --git-branch 11 - - ./travis.sh --assets --service frappe --tag v11 --tag-only - - ./travis.sh --assets --service frappe --tag version-11 --tag-only + - ./travis.py erpnext frappe --nginx --git-branch 11 + - ./travis.py erpnext frappe --nginx --tag v11 --tag-only + - ./travis.py erpnext frappe --nginx --tag version-11 --tag-only - name: "Build ERPNext python environment (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --worker --service erpnext --git-branch 11 - - ./travis.sh --worker --service erpnext --tag v11 --tag-only - - ./travis.sh --worker --service erpnext --tag version-11 --tag-only + - ./travis.py erpnext --worker --git-branch 11 + - ./travis.py erpnext --worker --tag v11 --tag-only + - ./travis.py erpnext --worker --tag version-11 --tag-only - name: "Build ERPNext nginx + static assets (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --assets --service erpnext--git-branch 11 - - ./travis.sh --assets --service erpnext --tag v11 --tag-only - - ./travis.sh --assets --service erpnext --tag version-11 --tag-only + - ./travis.py erpnext --nginx --git-branch 11 + - ./travis.py erpnext --nginx --tag v11 --tag-only + - ./travis.py erpnext --nginx --tag version-11 --tag-only - name: "Build Frappe socketio service (v11)" if: branch = master AND type != pull_request script: - - ./travis.sh --socketio --service frappe --git-branch 11 - - ./travis.sh --socketio --service frappe --tag v11 --tag-only - - ./travis.sh --socketio --service frappe --tag version-11 --tag-only + - ./travis.py frappe --socketio --git-branch 11 + - ./travis.py frappe --socketio --tag v11 --tag-only + - ./travis.py frappe --socketio --tag version-11 --tag-only \ No newline at end of file diff --git a/travis.py b/travis.py new file mode 100755 index 00000000..ba4270df --- /dev/null +++ b/travis.py @@ -0,0 +1,66 @@ +#!/bin/env python3 + +import argparse +import subprocess +import os + +parser = argparse.ArgumentParser(description='frappe_docker common CI elements', add_help=True) + +image_type = parser.add_mutually_exclusive_group(required=True) +image_type.add_argument('-a', '--nginx', action='store_const', dest='image_type', const='nginx', help='Build the nginx + static assets image') +image_type.add_argument('-s', '--socketio', action='store_const', dest='image_type', const='socketio', help='Build the frappe-socketio image') +image_type.add_argument('-w', '--worker', action='store_const', dest='image_type', const='worker', help='Build the python environment image') + +parser.add_argument('service', action='store', type=str, help='Name of the service to build: "erpnext" or "frappe"') + +tag_type = parser.add_mutually_exclusive_group(required=True) +tag_type.add_argument('-g', '--git-version', action='store', type=int, dest='version', help='The version number of --service (i.e. "11", "12", etc.)') +tag_type.add_argument('-t', '--tag', action='store', type=str, dest='tag', help='The image tag (i.e. erpnext-worker:$TAG )') + +parser.add_argument('-o', '--tag-only', required=False, action='store_true', dest='tag_only', help='Only tag an image and push it.') + +args = parser.parse_args() + +print('image_type = {!r}'.format(args.image_type)) +print('service = {!r}'.format(args.service)) +print('version = {!r}'.format(args.version)) +print('tag = {!r}'.format(args.tag)) +print('tag_only = {!r}'.format(args.tag_only)) + +def git_version(service, version): + print(f'Pulling {service} v{version}') + subprocess.run(f'git clone https://github.com/frappe/{service} --branch version-{version}', shell=True) + cd = os.getcwd() + os.chdir(os.getcwd() + f'/{service}') + subprocess.run('git fetch --tags', shell=True) + version_tag = subprocess.check_output(f'git tag --list --sort=-version:refname "v{version}*" | sed -n 1p | sed -e \'s#.*@\(\)#\\1#\'', shell=True).strip().decode('ascii') + os.chdir(cd) + return version_tag + +def build(service, tag, image, dockerfile): + print(f'Building {service} {image} image using {dockerfile}') + subprocess.run(f'docker build -t {service}-{image} -f build/{service}-{image}/{dockerfile} .', shell=True) + tag_and_push(f'{service}-{image}', tag) + +def tag_and_push(image_name, tag): + print(f'Tagging {image_name} as "{tag}" and pushing') + subprocess.run(f'docker tag {image_name} frappe/{image_name}:{tag}', shell=True) + subprocess.run(f'docker push frappe/{image_name}:{tag}', shell=True) + +def main(): + global tag + global dockerfile + + if args.version: + tag = git_version(args.service, args.version) + dockerfile = 'v{!r}.Dockerfile'.format(args.version) + else: + tag = args.tag + dockerfile = 'Dockerfile' + + if args.tag_only: + tag_and_push(f'{args.service}-{args.image_type}', tag) + else: + build(args.service, tag, args.image_type, dockerfile) + +main() diff --git a/travis.sh b/travis.sh deleted file mode 100755 index 58943b87..00000000 --- a/travis.sh +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/bash - -################# ./travis.sh ################# -# This script takes care of the common steps -# found in the frappe_docker Travis CI builds. -# -# Usage: [-a | -s | -w | -h] [-n ] [-t | -g ] [-o] -# -# Argumets: -# -# -a | --assets (exclusive): Build the nginx + static assets image -# -s | --socketio (exclusive): Build the frappe-socketio image -# -w | --worker (exclusive): Build the python environment image -# -h | --help (exclusive): Print this page -# -# -n | --service : Name of the service to build: "erpnext" or "frappe" -# Note: --socketio does not respect this argument -# Note: This will build an image with the name "$SERVICE-assets" (i.e. "erpnext-worker", "frappe-assets", etc.) -# -# -t | --tag (exclusive): The image tag (i.e. erpnext-worker:$TAG ) -# -g | --git-version (exclusive): The version number of --service (i.e. "11", "12", etc.) -# Note: This must be a number, not a string! -# -# -o | --tag-only: Only tag an image and push it. -# -# - - -while [[ $# -gt 0 ]]; do - key="$1" - - case $key in - -a|--assets) - ASSETS=1 - shift - ;; - -g|--git-version) - version="$2" - shift - shift - ;; - -h|--help) - HELP=1 - shift - ;; - -n|--service) - SERVICE="$2" - shift - shift - ;; - -o|--tag-only) - TAGONLY=1 - shift - ;; - -s|--socketio) - SOCKETIO=1 - shift - ;; - -t|--tag) - TAG="$2" - shift - shift - ;; - -w|--worker) - WORKER=1 - shift - ;; - *) - HELP=1 - shift - ;; - esac -done - -function help() { - echo "################ $0 #################" - echo " This script takes care of the common steps found in the frappe_docker Travis CI builds." - echo "" - echo " Usage: [-a | -s | -w | -h] [-n ] [-t | -g ] [-o]" - echo "" - echo " Argumets:" - echo "" - echo " -a | --assets (exclusive): Build the nginx + static assets image" - echo " -s | --socketio (exclusive): Build the frappe-socketio image" - echo " -w | --worker (exclusive): Build the python environment image" - echo " -h | --help (exclusive): Print this page" - echo "" - echo " -n | --service : Name of the service to build: \"erpnext\" or \"frappe\"" - echo " Note: --socketio does not respect this argument" - echo " Note: This will build an image with the name \"\$SERVICE-assets\" (i.e. \"erpnext-worker\", \"frappe-assets\", etc.)" - echo "" - echo " -t | --tag (exclusive): The image tag (i.e. erpnext-worker:\$TAG)" - echo " -g | --git-version (exclusive): The version number of --service (i.e. \"11\", \"12\", etc.)" - echo " Note: This must be a number, not a string!" - echo "" - echo " -o | --tag-only: Only tag an image and push it." -} - -function gitVersion() { - echo "Pulling ${1} v${2}" - git clone https://github.com/frappe/${1} --branch version-${2} - cd ${1} - git fetch --tags - TAG=$(git tag --list --sort=-version:refname "v${2}*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - cd .. - DOCKERFILE="v${2}.Dockerfile" -} - -function tagAndPush() { - echo "Tagging ${1} as \"${2}\" and pushing" - docker tag ${1} frappe/${1}:${2} - docker push frappe/${1}:${2} -} - -function build () { - echo "Building ${1} ${3} image using ${4}" - docker build -t ${1}-${3} -f build/${1}-${3}/${4:-Dockerfile} . - tagAndPush "${1}-${3}" ${2} -} - -if [[ HELP ]]; then - help - exit 1 -fi - -if [[ $VERSION ]]; then - gitVersion $SERVICE $VERSION -fi - -DOCKERFILE=${DOCKERFILE:-Dockerfile} - -if [[ $WORKER ]]; then - if [[ $TAGONLY ]]; then - tagAndPush "${SERVICE}-worker" ${TAG} - else - build $SERVICE $TAG worker ${DOCKERFILE} - fi -elif [[ $ASSETS ]]; then - if [[ $TAGONLY ]]; then - tagAndPush "${SERVICE}-assets" ${TAG} - else - build $SERVICE $TAG assets ${DOCKERFILE} - fi -elif [[ $SOCKETIO ]]; then - if [[ $TAGONLY ]]; then - tagAndPush "frappe-socketio" ${TAG} - else - build frappe $TAG socketio ${DOCKERFILE} - fi -fi \ No newline at end of file From 34d97848b54df6ba639be269a744aa04dfcd1931 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Wed, 4 Mar 2020 02:22:29 +0000 Subject: [PATCH 6/8] remove some debugging lines --- travis.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/travis.py b/travis.py index ba4270df..0be54695 100755 --- a/travis.py +++ b/travis.py @@ -21,12 +21,6 @@ parser.add_argument('-o', '--tag-only', required=False, action='store_true', des args = parser.parse_args() -print('image_type = {!r}'.format(args.image_type)) -print('service = {!r}'.format(args.service)) -print('version = {!r}'.format(args.version)) -print('tag = {!r}'.format(args.tag)) -print('tag_only = {!r}'.format(args.tag_only)) - def git_version(service, version): print(f'Pulling {service} v{version}') subprocess.run(f'git clone https://github.com/frappe/{service} --branch version-{version}', shell=True) From 63ae6cf9ea6a8255660b0dbbfa6140997b776cdb Mon Sep 17 00:00:00 2001 From: chabad360 Date: Wed, 4 Mar 2020 20:21:19 +0000 Subject: [PATCH 7/8] consistent use of f-strings --- travis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis.py b/travis.py index 0be54695..1a5884a3 100755 --- a/travis.py +++ b/travis.py @@ -47,7 +47,7 @@ def main(): if args.version: tag = git_version(args.service, args.version) - dockerfile = 'v{!r}.Dockerfile'.format(args.version) + dockerfile = f'v{args.version}.Dockerfile' else: tag = args.tag dockerfile = 'Dockerfile' From 301e5e3ab629b565bd0da6db2d84eb655e861c94 Mon Sep 17 00:00:00 2001 From: chabad360 Date: Wed, 4 Mar 2020 20:27:53 +0000 Subject: [PATCH 8/8] a bit of refactoring --- travis.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/travis.py b/travis.py index 1a5884a3..06ed6c17 100755 --- a/travis.py +++ b/travis.py @@ -6,19 +6,18 @@ import os parser = argparse.ArgumentParser(description='frappe_docker common CI elements', add_help=True) +parser.add_argument('service', action='store', type=str, help='Name of the service to build: "erpnext" or "frappe"') +parser.add_argument('-o', '--tag-only', required=False, action='store_true', dest='tag_only', help='Only tag an image and push it.') + image_type = parser.add_mutually_exclusive_group(required=True) image_type.add_argument('-a', '--nginx', action='store_const', dest='image_type', const='nginx', help='Build the nginx + static assets image') image_type.add_argument('-s', '--socketio', action='store_const', dest='image_type', const='socketio', help='Build the frappe-socketio image') image_type.add_argument('-w', '--worker', action='store_const', dest='image_type', const='worker', help='Build the python environment image') -parser.add_argument('service', action='store', type=str, help='Name of the service to build: "erpnext" or "frappe"') - tag_type = parser.add_mutually_exclusive_group(required=True) tag_type.add_argument('-g', '--git-version', action='store', type=int, dest='version', help='The version number of --service (i.e. "11", "12", etc.)') tag_type.add_argument('-t', '--tag', action='store', type=str, dest='tag', help='The image tag (i.e. erpnext-worker:$TAG )') -parser.add_argument('-o', '--tag-only', required=False, action='store_true', dest='tag_only', help='Only tag an image and push it.') - args = parser.parse_args() def git_version(service, version):