From 32861b1c726333ff57d63610e3c4acc6a636558e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 16 Dec 2018 09:26:08 +0100 Subject: [PATCH] Added new travis deployment which will build the docker image --- .travis.yml | 22 ++++++++++++++-------- build.sh | 5 +++-- data/travis/trigger_docker_build.sh | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 data/travis/trigger_docker_build.sh diff --git a/.travis.yml b/.travis.yml index 38d21750..0456973a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,11 +41,17 @@ before_deploy: - ./build.sh ${TRAVIS_TAG#?} deploy: - provider: releases - api_key: - secure: a9dbZchocqeuOViwUeNH54bQR5Sz7rEYXx5b9WPFtnFn9LGKKUaLbA2U91UQ9QKPrcTpsALubUYbw2CnNmvCwzaY+R8lCD3gkU4ohsEnbpnw3deOeixI74sqBHJAuCH9FSaRDGILoBMtUKx2xlzIymFxkIsgIukkGbdkWHDlRWY3oTUUuw1SQ2Xk9KDsbJQtjIc1+G/O6gHaV4qv/R9W8NPmJExKTNDrAZbC1vIUnxqp4UpVo1hst8qPd1at94CndDYM5rG+7imGbdtxTxzamt819qdTO1OfvtctKawNAm7YXZrrWft6c7gI6j6SI4hxd+ZrrPBqbaRFHkZHjnNssO/yn4SaOHFFzccmu0MzvpPCf0qWZwd3sGHVYer1MnR2mHYqU84QPlW3nrHwJjkrpq3+q0JcBY6GsJs+RskHNtkMTKV05Iz6QUI5YZGwTpuXaRm036SmavjGc4IDlMaYCk/NmbB9BKpthJxLdUpczOHpnjXXHziotWD6cfEnbjU3byfD8HY5WrxSjsNT7SKmXN3hRof7bk985ewQVjGT42O3NbnfnqjQQWr/B7/zFTpLR4f526Bkq12CdCyf5lvrbq+POkLVdJ+uFfR7ds248Ue/jBQy6kM1tWmKF9QiwisFlA84eQ4CW3I93Rp97URv+AQa9zmbD0Ve3Udp+g6nF5I= - file: "./build/shlink_${TRAVIS_TAG#?}_dist.zip" - skip_cleanup: true - on: - tags: true - php: 7.1 + - provider: releases + api_key: + secure: a9dbZchocqeuOViwUeNH54bQR5Sz7rEYXx5b9WPFtnFn9LGKKUaLbA2U91UQ9QKPrcTpsALubUYbw2CnNmvCwzaY+R8lCD3gkU4ohsEnbpnw3deOeixI74sqBHJAuCH9FSaRDGILoBMtUKx2xlzIymFxkIsgIukkGbdkWHDlRWY3oTUUuw1SQ2Xk9KDsbJQtjIc1+G/O6gHaV4qv/R9W8NPmJExKTNDrAZbC1vIUnxqp4UpVo1hst8qPd1at94CndDYM5rG+7imGbdtxTxzamt819qdTO1OfvtctKawNAm7YXZrrWft6c7gI6j6SI4hxd+ZrrPBqbaRFHkZHjnNssO/yn4SaOHFFzccmu0MzvpPCf0qWZwd3sGHVYer1MnR2mHYqU84QPlW3nrHwJjkrpq3+q0JcBY6GsJs+RskHNtkMTKV05Iz6QUI5YZGwTpuXaRm036SmavjGc4IDlMaYCk/NmbB9BKpthJxLdUpczOHpnjXXHziotWD6cfEnbjU3byfD8HY5WrxSjsNT7SKmXN3hRof7bk985ewQVjGT42O3NbnfnqjQQWr/B7/zFTpLR4f526Bkq12CdCyf5lvrbq+POkLVdJ+uFfR7ds248Ue/jBQy6kM1tWmKF9QiwisFlA84eQ4CW3I93Rp97URv+AQa9zmbD0Ve3Udp+g6nF5I= + file: "./build/shlink_${TRAVIS_TAG#?}_dist.zip" + skip_cleanup: true + on: + tags: true + php: 7.1 + - provider: script + script: bash data/travis/trigger_docker_build.sh + skip_cleanup: true + on: + tags: true + php: 7.1 diff --git a/build.sh b/build.sh index cbcaa180..cab2f4d3 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -if [ "$#" -ne 1 ]; then +if [[ "$#" -ne 1 ]]; then echo "Usage:" >&2 echo " $0 {version}" >&2 exit 1 @@ -10,7 +10,7 @@ fi version=$1 builtcontent="./build/shlink_${version}_dist" projectdir=$(pwd) -[ -f ./composer.phar ] && composerBin='./composer.phar' || composerBin='composer' +[[ -f ./composer.phar ]] && composerBin='./composer.phar' || composerBin='composer' # Copy project content to temp dir echo 'Copying project files...' @@ -18,6 +18,7 @@ rm -rf "${builtcontent}" mkdir -p "${builtcontent}" rsync -av * "${builtcontent}" \ --exclude=data/infra \ + --exclude=data/travis \ --exclude=data/migrations_template.txt \ --exclude=data/GeoLite2-City.mmdb \ --exclude=**/.gitignore \ diff --git a/data/travis/trigger_docker_build.sh b/data/travis/trigger_docker_build.sh new file mode 100644 index 00000000..565b30b5 --- /dev/null +++ b/data/travis/trigger_docker_build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +# Get latest commit in master, in plain text +LATEST_MASTER_COMMIT=$(curl -H "Accept: application/vnd.github.sha" -X GET https://api.github.com/repos/shlinkio/shlink-docker-image/commits/master) + +# Create new tag and a ref to the tag, which will trigger image build on it +curl -u acelaya:${GITHUB_OAUTH_KEY} \ + -H "Content-Type: application/json" \ + --data "{ \"tag\": \"${TRAVIS_TAG}\", \"message\": \"${TRAVIS_TAG}\", \"object\": \"${LATEST_MASTER_COMMIT}\", \"type\": \"commit\" }" \ + -X POST https://api.github.com/repos/shlinkio/shlink-docker-image/git/tags +curl -u acelaya:${GITHUB_OAUTH_KEY} \ + -H "Content-Type: application/json" \ + --data "{ \"ref\": \"refs/tags/${TRAVIS_TAG}\", \"sha\": \"${LATEST_MASTER_COMMIT}\" }" \ + -X POST https://api.github.com/repos/shlinkio/shlink-docker-image/git/refs + +# Trigger image build for "latest +curl -H "Content-Type: application/json" \ + --data '{ "docker_tag": "latest" }' \ + -X POST https://registry.hub.docker.com/u/shlinkio/shlink/trigger/${DOCKER_TRIGGER_TOKEN}/