From 8b036302537aac731c305562fd9afc2f71b6dbc2 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 3 May 2020 22:02:18 +0200 Subject: [PATCH] Added DockerHub image deploy automatisation --- .travis.yml | 14 +++++ ChangeLog.md | 1 + scripts/travis/build.sh | 5 +- scripts/travis/deploy_dev_server.sh | 16 +++--- scripts/travis/deploy_docker.sh | 59 ++++++++++++++++++++ scripts/travis/deploy_github.sh | 84 +---------------------------- scripts/travis/properties.sh | 4 ++ 7 files changed, 93 insertions(+), 90 deletions(-) create mode 100644 scripts/travis/deploy_docker.sh create mode 100644 scripts/travis/properties.sh diff --git a/.travis.yml b/.travis.yml index 9532ebc3..bd5d6bb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ before_install: - chmod +x ./scripts/travis/build.sh - chmod +x ./scripts/travis/deploy_dev_server.sh - chmod +x ./scripts/travis/deploy_github.sh + - chmod +x ./scripts/travis/deploy_docker.sh stages: - compile @@ -30,9 +31,22 @@ deploy: skip_cleanup: true on: branch: develop + - provider: script + cleanup: false + skip_cleanup: true + script: "bash scripts/travis/deploy_docker.sh development" + on: + branch: develop + - provider: script cleanup: false skip_cleanup: true script: "bash scripts/travis/deploy_github.sh" + on: + branch: master + - provider: script + cleanup: false + skip_cleanup: true + script: "bash scripts/travis/deploy_docker.sh release" on: branch: master \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md index 80948153..d11a428f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ * **03.05.20** - Splitup the file transfer & management part - Added the ability to register a custom file transfer provider (required for the native client) + - Added DockerHub image deploy automatisation * **25.04.20** - Fixed missing channel tree update on talk power change diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh index afc2b845..a93f8267 100644 --- a/scripts/travis/build.sh +++ b/scripts/travis/build.sh @@ -1,7 +1,8 @@ #!/bin/bash -LOG_FILE="auto-build/logs/build.log" -PACKAGES_DIRECTORY="auto-build/packages/" +cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } +source ./scripts/travis/properties.sh + build_verbose=0 build_release=1 build_debug=0 diff --git a/scripts/travis/deploy_dev_server.sh b/scripts/travis/deploy_dev_server.sh index 762ec815..88625b2d 100644 --- a/scripts/travis/deploy_dev_server.sh +++ b/scripts/travis/deploy_dev_server.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -PACKAGES_DIRECTORY="auto-build/packages/" +cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } +source ./scripts/travis/properties.sh + if [[ -z "${SSH_KEY}" ]]; then echo "Missing environment variable SSH_KEY. Please set it before using this script!" exit 1 @@ -12,7 +14,6 @@ chmod 600 /tmp/sftp_key echo "Failed to write SSH key" exit 1 } -cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } file=$(find "$PACKAGES_DIRECTORY" -maxdepth 1 -name "TeaWeb-release*.zip" -print) [[ $(echo "$file" | wc -l) -ne 1 ]] && { @@ -26,16 +27,19 @@ file=$(find "$PACKAGES_DIRECTORY" -maxdepth 1 -name "TeaWeb-release*.zip" -print #TeaSpeak-Travis-Web # ssh -oStrictHostKeyChecking=no $h TeaSpeak-Travis-Web@dev.web.teaspeak.de ssh -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@dev.web.teaspeak.de rm "tmp-upload/*.zip" # Cleanup the old files -[[ $? -ne 0 ]] && { - echo "Failed to delete the old .zip files" +_exit_code=$? +[[ $_exit_code -ne 0 ]] && { + echo "Failed to delete the old .zip files ($_exit_code)" } filename="TeaWeb-Release-$(git rev-parse --short HEAD).zip" sftp -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@dev.web.teaspeak.de << EOF put $file tmp-upload/$filename EOF -[[ $? -ne 0 ]] && { - echo "Failed to upload the .zip file" +_exit_code=$? +[[ $_exit_code -ne 0 ]] && { + echo "Failed to upload the .zip file ($_exit_code)" + exit 1 } ssh -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@dev.web.teaspeak.de "./unpack.sh tmp-upload/$filename" exit $? \ No newline at end of file diff --git a/scripts/travis/deploy_docker.sh b/scripts/travis/deploy_docker.sh new file mode 100644 index 00000000..14136e76 --- /dev/null +++ b/scripts/travis/deploy_docker.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } +source ./scripts/travis/properties.sh + +git_rev=$(git rev-parse --short HEAD) +[[ ! "$git_rev" =~ [a-z0-9]{6} ]] && { + echo "Failed to parse git rev. Received: '$git_rev'." + exit 1 +} + +if [[ "$1" == "release" ]]; then + echo "Releasing $git_rev as release" + rolling_tag="latest" +elif [[ "$1" == "development" ]]; then + echo "Releasing $git_rev as beta release" + rolling_tag="beta" +else + echo "Invalid release mode" + exit 1 +fi + +zip_file=$(find "$PACKAGES_DIRECTORY" -maxdepth 1 -name "TeaWeb-release*.zip" -print) +[[ $(echo "$zip_file" | wc -l) -ne 1 ]] && { + echo "Invalid .zip file count (Expected 1 but got $(echo "$zip_file" | wc -l)): ${zip_file[*]}" + exit 1 +} +[[ ! -e "$zip_file" ]] && { + echo "File ($zip_file) does not exists" + exit 1 +} + +git clone https://github.com/TeaSpeak/TeaDocker.git auto-build/teadocker || { + echo "Failed to clone the TeaDocker project" + exit 1 +} + +docker build -f auto-build/teadocker/web/travis.Dockerfile --build-arg WEB_VERSION="$git_rev" --build-arg WEB_ZIP="$zip_file" -t teaspeak/web:"$rolling_tag" auto-build/teadocker/web || { + echo "Failed to build dockerfile" + exit 1 +} + +docker tag teaspeak/web:latest teaspeak/web:"$git_rev" || { + echo "Failed to tag docker release" + exit 1 +} + +docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_TOKEN" || { + echo "Failed to login to docker hub" + exit 1 +} + +docker push teaspeak/web || { + echo "Failed to push new teaspeak/web tags" + exit 1 +} +docker logout # &> /dev/null + +exit 0 \ No newline at end of file diff --git a/scripts/travis/deploy_github.sh b/scripts/travis/deploy_github.sh index 69b647a6..cc2b628a 100644 --- a/scripts/travis/deploy_github.sh +++ b/scripts/travis/deploy_github.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -PACKAGES_DIRECTORY="auto-build/packages/" -LOG_FILE="auto-build/logs/build.log" +cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } +source ./scripts/travis/properties.sh if [[ -z "${GIT_AUTHTOKEN}" ]]; then echo "GIT_AUTHTOKEN isn't set. Don't deploying build!" @@ -12,87 +12,7 @@ GIT_COMMIT_SHORT=$(git rev-parse --short HEAD) GIT_COMMIT_LONG=$(git rev-parse HEAD) echo "Deploying $GIT_COMMIT_SHORT ($GIT_COMMIT_LONG) to github." -GIT_RELEASE_EXECUTABLE="/tmp/git-release" -if [[ ! -x ${GIT_RELEASE_EXECUTABLE} ]]; then - if [[ ! -f ${GIT_RELEASE_EXECUTABLE} ]]; then - echo "Downloading github-release-linux (1.2.4)" - - if [[ -f /tmp/git-release.gz ]]; then - rm /tmp/git-release.gz - fi - wget https://github.com/tfausak/github-release/releases/download/1.2.4/github-release-linux.gz -O /tmp/git-release.gz -q; - [[ $? -eq 0 ]] || { - echo "Failed to download github-release-linux" - exit 1 - } - - gunzip /tmp/git-release.gz; _exit_code=$?; - [[ $_exit_code -eq 0 ]] || { - echo "Failed to unzip github-release-linux" - exit 1 - } - chmod +x /tmp/git-release; - - echo "Download of github-release-linux (1.2.4) finished" - else - chmod +x ${GIT_RELEASE_EXECUTABLE} - fi - - if [[ ! -x ${GIT_RELEASE_EXECUTABLE} ]]; then - echo "git-release isn't executable" - exit 1 - fi -fi - -cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; } echo "Generating release" -${GIT_RELEASE_EXECUTABLE} release \ - --repo "TeaWeb" \ - --owner "TeaSpeak" \ - --token "${GIT_AUTHTOKEN}" \ - --title "Travis autobuild ${GIT_COMMIT_SHORT}" \ - --tag "${GIT_COMMIT_SHORT}" \ - --description "This is a autobuild release from travis" -[[ $? -eq 0 ]] || { - echo "Failed to generate git release" - exit 1 -} - -echo "Uploading release files" -folders=("${LOG_FILE}" "${PACKAGES_DIRECTORY}") -uploaded_files=() -failed_files=() - -for folder in "${folders[@]}"; do - echo "Scanning folder $folder" - if [[ ! -d ${folder} ]]; then - continue; - fi - - for file in ${folder}*; do - if [[ -d ${file} ]]; then - echo " Skipping directory `basename $file` ($file)" - continue - fi - echo " Found entry `basename $file` ($file). Uploading file."; - - ${GIT_RELEASE_EXECUTABLE} upload \ - --repo "TeaWeb" \ - --owner "TeaSpeak" \ - --token "${GIT_AUTHTOKEN}" \ - --tag "${GIT_COMMIT_SHORT}" \ - --file "$file" \ - --name "`basename $file`" - - [[ $? -eq 0 ]] && { - echo " Uploaded."; - uploaded_files+="$file" - } || { - echo "Failed to generate git release" - failed_files+="$file" - } - done -done echo "Successfully uploaded ${#uploaded_files[@]} files. ${#failed_files[@]} uploads failed." exit 0 \ No newline at end of file diff --git a/scripts/travis/properties.sh b/scripts/travis/properties.sh new file mode 100644 index 00000000..ed059bf2 --- /dev/null +++ b/scripts/travis/properties.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +LOG_FILE="auto-build/logs/build.log" +PACKAGES_DIRECTORY="auto-build/packages/" \ No newline at end of file