From a27dca2d9be052e5fdf0156f9a0e2b8a6fe23c19 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 11:28:54 +0000 Subject: Azure: Build and push container --- scripts/deploy-azure.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/deploy-azure.sh (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh new file mode 100644 index 000000000..f18407c8b --- /dev/null +++ b/scripts/deploy-azure.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) + +if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" + + echo "Building bot base" + docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile . + + echo "Pushing image to Docker Hub" + docker push pythondiscord/bot-base:latest +else + echo "base.Dockerfile was not changed, not building" +fi + +echo "Building image" +docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile . + +echo "Pushing image" +docker push pythondiscord/bot:latest + +#echo "Deploying container" +#curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -- cgit v1.2.3 From 3ece07a0f25ee4f11d2422a0ab8241212026e778 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 11:36:02 +0000 Subject: Azure: Move branch trigger to Docker build script --- azure-pipelines.yml | 5 ----- scripts/deploy-azure.sh | 37 +++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3f063ea41..22f214226 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -40,11 +40,6 @@ jobs: - job: build displayName: 'Build containers' - trigger: - branches: - include: - - master - steps: - task: Docker@1 displayName: 'Login: Docker Hub' diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index f18407c8b..4df5cb0fc 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,24 +1,29 @@ #!/bin/bash -changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) +# Build and deploy on master branch +if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]]; then + changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) -if [ $changed_lines != '0' ]; then - echo "base.Dockerfile was changed" + if [ $changed_lines != '0' ]; then + echo "base.Dockerfile was changed" - echo "Building bot base" - docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile . + echo "Building bot base" + docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile . - echo "Pushing image to Docker Hub" - docker push pythondiscord/bot-base:latest -else - echo "base.Dockerfile was not changed, not building" -fi + echo "Pushing image to Docker Hub" + docker push pythondiscord/bot-base:latest + else + echo "base.Dockerfile was not changed, not building" + fi -echo "Building image" -docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile . + echo "Building image" + docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile . -echo "Pushing image" -docker push pythondiscord/bot:latest + echo "Pushing image" + docker push pythondiscord/bot:latest -#echo "Deploying container" -#curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK + # echo "Deploying container" + # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK +else + echo "Skipping deploy" +fi \ No newline at end of file -- cgit v1.2.3 From ed14faee08f82b6569517fae6e33c43abda47eed Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 11:56:56 +0000 Subject: Azure: Attempt to fix differing build script syntax --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 4df5cb0fc..378cceaf6 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,7 +1,7 @@ #!/bin/bash # Build and deploy on master branch -if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]]; then +if [ $BUILD_SOURCEBRANCHNAME == 'master' ]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From 50ca98c9e854e2841ca18d18b8b41c47db117687 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 12:01:34 +0000 Subject: Azure: I hate bash. --- azure-pipelines.yml | 2 +- scripts/deploy-azure.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bb8d7999e..bce6dbce4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -50,5 +50,5 @@ jobs: dockerRegistryEndpoint: 'DockerHub' command: 'login' - - bash: sh scripts/deploy-azure.sh + - bash: bash scripts/deploy-azure.sh displayName: 'Build and deploy containers' diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 378cceaf6..4df5cb0fc 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,7 +1,7 @@ #!/bin/bash # Build and deploy on master branch -if [ $BUILD_SOURCEBRANCHNAME == 'master' ]; then +if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From 433871f52e5af50234b65ba35d198f907ef5565f Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 12:28:59 +0000 Subject: Azure: Finish deployment; skip if PR GitLab: Remove deployment step --- .gitlab-ci.yml | 10 ---------- azure-pipelines.yml | 4 ++-- scripts/deploy-azure.sh | 10 ++++++---- 3 files changed, 8 insertions(+), 16 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7aee8165..44126ded9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,13 +26,3 @@ test: - python -m flake8 - ls /root/.cache/ -build: - tags: - - docker - - services: - - docker:dind - - stage: build - script: - - sh scripts/deploy.sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bce6dbce4..534742f4f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ variables: jobs: - job: test - displayName: 'Lint and test' + displayName: 'Lint & Test' pool: vmImage: 'Ubuntu 16.04' @@ -38,7 +38,7 @@ jobs: displayName: 'Run linter' - job: build - displayName: 'Build containers' + displayName: 'Build Containers' dependsOn: 'test' steps: diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 4df5cb0fc..659a297bf 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,7 +1,9 @@ #!/bin/bash -# Build and deploy on master branch -if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]]; then +if [[ ]] + +# Build and deploy on master branch, only if not a pull request +if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]] && [[ -z "${SYSTEM_PULLREQUEST_PULLREQUESTID}" ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then @@ -22,8 +24,8 @@ if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]]; then echo "Pushing image" docker push pythondiscord/bot:latest - # echo "Deploying container" - # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK + echo "Deploying container" + curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK else echo "Skipping deploy" fi \ No newline at end of file -- cgit v1.2.3 From 138662eb447282722fee307e8d923039d1039124 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 12:33:13 +0000 Subject: Azure: Did I ever say I hate bash? --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 659a297bf..fe1aeb245 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -3,7 +3,7 @@ if [[ ]] # Build and deploy on master branch, only if not a pull request -if [[ $BUILD_SOURCEBRANCHNAME == 'master' ]] && [[ -z "${SYSTEM_PULLREQUEST_PULLREQUESTID}" ]]; then +if [[ $BUILD_SOURCEBRANCHNAME == 'master' && -z "${SYSTEM_PULLREQUEST_PULLREQUESTID}" ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From 0444287263ef64f383c29f9b8407b075a889cd59 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 12:39:44 +0000 Subject: Azure: Why does Bash have to be so awful? --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index fe1aeb245..81037c217 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -3,7 +3,7 @@ if [[ ]] # Build and deploy on master branch, only if not a pull request -if [[ $BUILD_SOURCEBRANCHNAME == 'master' && -z "${SYSTEM_PULLREQUEST_PULLREQUESTID}" ]]; then +if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z "${SYSTEM_PULLREQUEST_PULLREQUESTID}") ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From db7e0a596e41e854b127db15bb141a254ce7314b Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:03:01 +0000 Subject: Azure: Maybe bash requires single quotes? I hate bash. --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 81037c217..157d77e7f 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -3,7 +3,7 @@ if [[ ]] # Build and deploy on master branch, only if not a pull request -if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z "${SYSTEM_PULLREQUEST_PULLREQUESTID}") ]]; then +if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z '$SYSTEM_PULLREQUEST_PULLREQUESTID') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From 550e491517f6d6bf8757cfb5a381537b4e391dbd Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:13:57 +0000 Subject: Azure: Let's bash Bash --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 157d77e7f..187aeda00 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -3,7 +3,7 @@ if [[ ]] # Build and deploy on master branch, only if not a pull request -if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z '$SYSTEM_PULLREQUEST_PULLREQUESTID') ]]; then +if [ [$BUILD_SOURCEBRANCHNAME == 'master'] && [-z '$SYSTEM_PULLREQUEST_PULLREQUESTID'] ]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From a8a76263de738726eced0cee2e43ef212a5f5ba7 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:20:45 +0000 Subject: Azure: Where'd this extra line come from? --- scripts/deploy-azure.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 187aeda00..9f64b52a2 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,9 +1,7 @@ #!/bin/bash -if [[ ]] - # Build and deploy on master branch, only if not a pull request -if [ [$BUILD_SOURCEBRANCHNAME == 'master'] && [-z '$SYSTEM_PULLREQUEST_PULLREQUESTID'] ]; then +if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z '$SYSTEM_PULLREQUEST_PULLREQUESTID') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From c7be43a3f4ec885d7712ae62d8a96cdde9148d15 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:24:47 +0000 Subject: Azure: Unfortunately I have to check this manually --- scripts/deploy-azure.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 9f64b52a2..f700a4847 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,5 +1,7 @@ #!/bin/bash +echo "PR ID: $SYSTEM_PULLREQUEST_PULLREQUESTID" + # Build and deploy on master branch, only if not a pull request if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z '$SYSTEM_PULLREQUEST_PULLREQUESTID') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) -- cgit v1.2.3 From 42e0d51b5c3b87a088d27fb046005e5d8b0c9cf1 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:31:16 +0000 Subject: Azure: Hopefully that'll do it --- scripts/deploy-azure.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index f700a4847..23573df82 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,9 +1,9 @@ #!/bin/bash -echo "PR ID: $SYSTEM_PULLREQUEST_PULLREQUESTID" +export SYSTEM_PULLREQUEST_PULLREQUESTID = $SYSTEM_PULLREQUEST_PULLREQUESTID | xargs # Build and deploy on master branch, only if not a pull request -if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && (-z '$SYSTEM_PULLREQUEST_PULLREQUESTID') ]]; then +if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) if [ $changed_lines != '0' ]; then -- cgit v1.2.3 From 463dee7f84c9bc32dc6d07d177a1d42a200b7695 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:36:06 +0000 Subject: Azure: I'm rewriting this in Python someday --- scripts/deploy-azure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 23573df82..5f7666bb0 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,6 +1,6 @@ #!/bin/bash -export SYSTEM_PULLREQUEST_PULLREQUESTID = $SYSTEM_PULLREQUEST_PULLREQUESTID | xargs +export SYSTEM_PULLREQUEST_PULLREQUESTID="$(echo -e '${SYSTEM_PULLREQUEST_PULLREQUESTID}' | xargs)" # Build and deploy on master branch, only if not a pull request if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then -- cgit v1.2.3 From c8641271431c724acab3fbaf7f424718becefed8 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:40:29 +0000 Subject: Azure: It's amusing that bash is the problem today --- scripts/deploy-azure.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 5f7666bb0..84509f461 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,7 +1,5 @@ #!/bin/bash -export SYSTEM_PULLREQUEST_PULLREQUESTID="$(echo -e '${SYSTEM_PULLREQUEST_PULLREQUESTID}' | xargs)" - # Build and deploy on master branch, only if not a pull request if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) -- cgit v1.2.3 From 343c1fbdbea110d9b4aca00c4182accb977d2202 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 13:56:29 +0000 Subject: Azure: OK, turns out secret variables must be task args and otherwise aren't available to the running script --- azure-pipelines.yml | 1 + scripts/deploy-azure.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/deploy-azure.sh') diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b9fe8beb0..fe7486a5c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -55,3 +55,4 @@ jobs: inputs: scriptPath: scripts/deploy-azure.sh + args: '$(AUTODEPLOY_TOKEN) $(AUTODEPLOY_WEBHOOK)' diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 84509f461..8cb9fe770 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -23,7 +23,7 @@ if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTI docker push pythondiscord/bot:latest echo "Deploying container" - curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK + curl -H "token: $1" $2 else echo "Skipping deploy" fi \ No newline at end of file -- cgit v1.2.3 From 497eef8bf66dd19c69c0df963c7db62961aff64c Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 16 Nov 2018 14:02:22 +0000 Subject: Azure: This should be all, I hope. --- scripts/deploy-azure.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/deploy-azure.sh') diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh index 8cb9fe770..6b3dea508 100644 --- a/scripts/deploy-azure.sh +++ b/scripts/deploy-azure.sh @@ -1,5 +1,7 @@ #!/bin/bash +cd .. + # Build and deploy on master branch, only if not a pull request if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l) -- cgit v1.2.3