Skip to content

Commit

Permalink
Merge pull request #5 from sitewards/adhoc-add-azure
Browse files Browse the repository at this point in the history
Adhoc add azure
  • Loading branch information
aboritskiy authored Aug 19, 2019
2 parents 782c06d + d102c1d commit c29200f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
7 changes: 6 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
---
## 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:

## 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)
Expand Down
17 changes: 17 additions & 0 deletions tasks/download-from/aws-s3.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions tasks/download-from/azure-blob.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 5 additions & 18 deletions tasks/installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,33 +47,20 @@
when:
- not magento_release_stat.stat.exists
- magento_skip_release == False

- name: "Set the workdir for later tasks"
set_fact:
magento_workdir: "{{ tmpdir.path }}"
when:
- 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:
Expand All @@ -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
Expand Down

0 comments on commit c29200f

Please sign in to comment.