From d102c1ded59589d8508b4aa802e783e60ef1851a Mon Sep 17 00:00:00 2001 From: Anton Boritskiy Date: Fri, 16 Aug 2019 18:47:40 +0100 Subject: [PATCH] ADHOC feat (azure-deploy): add azure deploy possibility we can pull images from Azure as well this is not a backwards compatible change variable names were changed. Originally this was not planned, but ambiguity in variable naming was discovered, hence - renaming to enforce review of those variables in all consuming projects. --- defaults/main.yml | 7 ++++++- tasks/download-from/aws-s3.yml | 17 +++++++++++++++++ tasks/download-from/azure-blob.yml | 16 ++++++++++++++++ tasks/installation.yml | 23 +++++------------------ 4 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 tasks/download-from/aws-s3.yml create mode 100644 tasks/download-from/azure-blob.yml diff --git a/defaults/main.yml b/defaults/main.yml index c6efbd5..3b7e964 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,9 @@ --- +## The name of the release storage provider (AWS S3 or Azure Blob Storage) +## (required) +magento_release_storage_provider: "aws-s3" +#magento_release_storage_provider: "azure-blob" + ## The AWS S3 bucket that contains the tarball releases of Magento ## (Required) # magento_bucket_name: @@ -6,7 +11,7 @@ ## The full path to the release in S3. For example, if the release is at "s3://foo-bar-bar/foo/bar.tar.gz", than the ## the full path is "foo/bar.tar.gz" ## (Required) -# magento_storage_path: +# magento_storage_file_path: ## The magento release folder. Contains the current set of releases ## (Required) diff --git a/tasks/download-from/aws-s3.yml b/tasks/download-from/aws-s3.yml new file mode 100644 index 0000000..230986c --- /dev/null +++ b/tasks/download-from/aws-s3.yml @@ -0,0 +1,17 @@ +--- +# The AWS S3 ansible role is deliberately not used, as it does not handle multipart uploads well. +# See https://github.com/ansible/ansible/issues/5442 +# +# This expects to authenticat based on the invokers AWS credentials, supplied through environment variables +- name: "Download Magento release" + shell: | + AWS_ACCESS_KEY_ID="{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}" \ + AWS_SECRET_ACCESS_KEY="{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}" \ + aws s3 cp s3://{{ magento_bucket_name }}/{{ magento_storage_file_path }} {{ magento_workdir }} \ + --cli-read-timeout 300 \ + --cli-connect-timeout 0 + args: + creates: "{{ magento_workdir }}/{{ magento_storage_file_name }}" + when: + - not magento_release_stat.stat.exists + - magento_skip_release == False diff --git a/tasks/download-from/azure-blob.yml b/tasks/download-from/azure-blob.yml new file mode 100644 index 0000000..6945fb8 --- /dev/null +++ b/tasks/download-from/azure-blob.yml @@ -0,0 +1,16 @@ +--- +# This expects to authenticat based on the invokers Azure credentials, supplied through environment variables +- name: "Download Magento release" + shell: | + AZURE_CLIENT_ID="{{ lookup('env','AZURE_CLIENT_ID') }}" \ + AZURE_SECRET="{{ lookup('env','AZURE_SECRET') }}" \ + AZURE_TENANT="{{ lookup('env','AZURE_TENANT') }}" \ + AZURE_SUBSCRIPTION_ID="{{ lookup('env','AZURE_SUBSCRIPTION_ID') }}" \ + AZURE_STORAGE_ACCOUNT="{{ lookup('env','AZURE_STORAGE_ACCOUNT') }}" \ + AZURE_STORAGE_KEY="{{ lookup('env','AZURE_STORAGE_KEY') }}" \ + az storage blob download --container-name="{{ lookup('env','AZURE_APP_RELEASES_BLOB_CONTAINER_NAME') }}" --file={{ magento_workdir }}/{{ magento_storage_file_name }} --name={{ magento_storage_file_path }} + args: + creates: "{{ magento_workdir }}/{{ magento_storage_file_name }}" + when: + - not magento_release_stat.stat.exists + - magento_skip_release == False diff --git a/tasks/installation.yml b/tasks/installation.yml index c113048..e377671 100644 --- a/tasks/installation.yml +++ b/tasks/installation.yml @@ -34,7 +34,7 @@ - name: "Get the magento filename from the storage path" set_fact: - magento_file_name: "{{ magento_storage_path | basename }}" + magento_storage_file_name: "{{ magento_storage_file_path | basename }}" when: - not magento_release_stat.stat.exists - magento_skip_release == False @@ -47,6 +47,7 @@ when: - not magento_release_stat.stat.exists - magento_skip_release == False + - name: "Set the workdir for later tasks" set_fact: magento_workdir: "{{ tmpdir.path }}" @@ -54,26 +55,12 @@ - not magento_release_stat.stat.exists - magento_skip_release == False -# The AWS S3 ansible role is deliberately not used, as it does not handle multipart uploads well. -# See https://github.com/ansible/ansible/issues/5442 -# -# This expects to authenticat based on the invokers AWS credentials, supplied through environment variables - name: "Download Magento release" - shell: | - AWS_ACCESS_KEY_ID="{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}" \ - AWS_SECRET_ACCESS_KEY="{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}" \ - aws s3 cp s3://{{ magento_bucket_name }}/{{ magento_storage_path }} {{ magento_workdir }} \ - --cli-read-timeout 300 \ - --cli-connect-timeout 0 - args: - creates: "{{ magento_workdir }}/{{ magento_file_name }}" - when: - - not magento_release_stat.stat.exists - - magento_skip_release == False + include: "download-from/{{ magento_release_storage_provider }}.yml" - name: "Unpack the release" unarchive: - src: "{{ magento_workdir }}/{{ magento_file_name }}" + src: "{{ magento_workdir }}/{{ magento_storage_file_name }}" dest: "{{ magento_workdir }}" remote_src: true when: @@ -82,7 +69,7 @@ - name: "Clean up the downloaded archive" file: - path: "{{ magento_workdir }}/{{ magento_file_name }}" + path: "{{ magento_workdir }}/{{ magento_storage_file_name }}" state: "absent" when: - not magento_release_stat.stat.exists