Skip to content

Commit

Permalink
Merge pull request #63 from paulrbr-fl/upgrade-clever-cli
Browse files Browse the repository at this point in the history
deploy: remove custom polling script now that the CLI does it for us
  • Loading branch information
paulrbr-fl authored Jun 17, 2020
2 parents 5816bb8 + b89d054 commit d5c5bf8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 155 deletions.
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# defaults file for clever
clever_cli_version: 1.6.3
clever_cli_version: 2.6.1
clever_user_path: .local/bin
clever_app_root: "{{ app_root | default(playbook_dir + '/..') }}"
clever_app_confdir: "{{ clever_app_root }}/.clever_cloud"
Expand Down
96 changes: 0 additions & 96 deletions files/clever-wait-deploy.sh

This file was deleted.

75 changes: 20 additions & 55 deletions tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,80 +24,45 @@
CONFIGURATION_FILE: "{{ clever_login_file }}"
changed_when: false

#TODO: Improve ssh-key validation
- name: Accept Clever-Cloud servers
shell: "ssh-keyscan -H push-par-clevercloud-customers.services.clever-cloud.com >> ~/.ssh/known_hosts"
tags:
- skip_ansible_lint

- name: Deploy to Clever-Cloud
command: "git push --force git+ssh://[email protected]/{{ clever_app }}.git HEAD:refs/heads/master"
args:
chdir: "{{ clever_app_root }}"
register: clever_deploy
ignore_errors: true
tags:
- skip_ansible_lint

##################################################################
# Re-deploy only if its the first clever deploy for that project #
##################################################################

- name: First time push to Clever-Cloud needs a full git clone
command: "git fetch --unshallow"
args:
chdir: "{{ clever_app_root }}"
when:
- clever_deploy is failed
- clever_deploy.stderr is defined
- clever_deploy.stderr is search("Failed to read git object")
tags:
- skip_ansible_lint

- name: Deploy to Clever-Cloud
command: "git push --force git+ssh://[email protected]/{{ clever_app }}.git HEAD:refs/heads/master"
args:
chdir: "{{ clever_app_root }}"
when:
- clever_deploy is failed
- clever_deploy.stderr is defined
- clever_deploy.stderr is search("Failed to read git object")
register: clever_deploy
tags:
- skip_ansible_lint

##############################################################################
# Poll deployment status from 'clever activity' command. #
# 'clever deploy' command is not yet 100% reliable to get a blocking command #
# until the deployment is over. Hence the need for a custom waiting script. #
##############################################################################

- name: Watch deployment status
command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-wait-deploy.sh"
shell: "clever deploy --force"
args:
chdir: "{{ clever_app_root }}"
environment:
CONFIGURATION_FILE: "{{ clever_login_file }}"
async: 2400 # 40 minutes
poll: 0
register: long_command
changed_when: False
ignore_errors: true
register: clever_deploy
tags:
- skip_ansible_lint

- name: Wait 40 minutes for deployment completion
- name: Wait up to 40 minutes for deployment completion
async_status:
jid: "{{ long_command.ansible_job_id }}"
jid: "{{ clever_deploy.ansible_job_id }}"
register: job_result
until: job_result.finished
ignore_errors: true
delay: 30
retries: 80 # 40 minutes (80 * 30 secs delay)

- name: Waiting script logs (stdout)
##################################################################
# Re-deploy only if its the first clever deploy for that project #
##################################################################

- name: Retry deploy to clever-cloud
include_tasks: redeploy.yml
when:
- not job_result.rc == 0
- job_result.stderr is defined
- job_result.stderr is search("Failed to read git object")

- name: Deploy logs (stdout)
debug:
var: job_result.stdout_lines
when: job_result.stdout_lines is defined

- name: Waiting script logs (stderr)
- name: Deploy error logs (stderr)
debug:
var: job_result.stderr_lines
when: job_result.stderr_lines is defined
Expand Down
33 changes: 33 additions & 0 deletions tasks/redeploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
##################################################################
# Re-deploy only if its the first clever deploy for that project #
##################################################################

- name: First time push to Clever-Cloud needs a full git clone
command: "git fetch --unshallow"
args:
chdir: "{{ clever_app_root }}"
tags:
- skip_ansible_lint

- name: Deploy to Clever-Cloud
shell: "clever deploy --force"
args:
chdir: "{{ clever_app_root }}"
environment:
CONFIGURATION_FILE: "{{ clever_login_file }}"
async: 2400 # 40 minutes
poll: 0
ignore_errors: true
register: clever_deploy
tags:
- skip_ansible_lint

- name: Wait up to 40 minutes for deployment completion
async_status:
jid: "{{ clever_deploy.ansible_job_id }}"
register: job_result
until: job_result.finished
ignore_errors: true
delay: 30
retries: 80 # 40 minutes (80 * 30 secs delay)
3 changes: 1 addition & 2 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
src: "{{ clever_repo }}/{{ clever_tools_archive }}"
dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}"
vars:
clever_repo: https://clever-tools.cellar.services.clever-cloud.com/releases
clever_repo: https://clever-tools.clever-cloud.com/releases
clever_tools_archive: "{{ clever_cli_version }}/clever-tools-{{ clever_cli_version }}_linux.tar.gz"
when: clever_returned_version is failed or clever_returned_version.stdout != clever_cli_version

Expand All @@ -27,6 +27,5 @@
dest: "{{ ansible_env.HOME }}/{{ clever_user_path }}/{{ item }}"
mode: 0755
with_items:
- clever-wait-deploy.sh
- clever-set-domain.sh
- clever-set-drain.sh
2 changes: 1 addition & 1 deletion tests/fake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ binary="${0/*\/}"
fakeCommit="aaa000aaa000aaa000aaa000aaa000aaa000aaa0"

if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then
echo "1.6.3"
echo "2.6.1"
elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${fakeCommit} Git"
elif [ "${binary}" = "git" ]; then
Expand Down

0 comments on commit d5c5bf8

Please sign in to comment.