Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tasks/update-code/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- name: ANSISTRANO | download | Download artifact
get_url:
url: "{{ ansistrano_get_url }}"
dest: "{{ ansistrano_release_path.stdout }}/{{ ansistrano_get_url | urlsplit('path') | basename }}"
dest: "{{ ansistrano_release_path.stdout }}/"
force_basic_auth: "{{ ansistrano_download_force_basic_auth | default(omit) }}"
headers: "{{ ansistrano_download_headers | default(omit) }}"
register: ansistrano_download_result
2 changes: 1 addition & 1 deletion tasks/update-code/download_unarchive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

- name: ANSISTRANO | download_unarchive | Set archived file
set_fact:
ansistrano_archived_file: "{{ ansistrano_release_path.stdout }}/{{ ansistrano_get_url | urlsplit('path') | basename }}"
ansistrano_archived_file: "{{ ansistrano_download_result.dest }}"

- include_tasks: unarchive.yml
112 changes: 112 additions & 0 deletions test/download-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,115 @@
- debug:
msg: "ansistrano_release_path.stdout/deploy-master does not exist"
when: st.stat.exists is sameas false

- name: Given a local artifact endpoint with filename only in Content-Disposition
hosts: all
vars:
ansistrano_fixture_download_root: "/tmp/ansistrano-download-fixture"
ansistrano_fixture_download_port: 18080
tasks:
- name: Remove previous download fixture directory
file:
path: "{{ ansistrano_fixture_download_root }}"
state: absent

- name: Create download fixture directory
file:
path: "{{ ansistrano_fixture_download_root }}/artifact"
state: directory

- name: Create download fixture file
copy:
dest: "{{ ansistrano_fixture_download_root }}/artifact/README.txt"
content: "download fixture via content disposition\n"

- name: Create zipped download fixture
archive:
path: "{{ ansistrano_fixture_download_root }}/artifact"
dest: "{{ ansistrano_fixture_download_root }}/artifact.zip"
format: zip

- name: Create HTTP fixture server
copy:
dest: "{{ ansistrano_fixture_download_root }}/server.py"
mode: "0755"
content: |
from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path
from urllib.parse import urlparse

root = Path("{{ ansistrano_fixture_download_root }}")
payload = (root / "artifact.zip").read_bytes()

class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if urlparse(self.path).path != "/download":
self.send_response(404)
self.end_headers()
return

self.send_response(200)
self.send_header("Content-Type", "application/zip")
self.send_header(
"Content-Disposition",
'attachment; filename="artifact.zip"',
)
self.send_header("Content-Length", str(len(payload)))
self.end_headers()
self.wfile.write(payload)

def log_message(self, format, *args):
return

HTTPServer(("127.0.0.1", {{ ansistrano_fixture_download_port }}), Handler).serve_forever()

- name: Start HTTP fixture server
shell: >-
python3 {{ ansistrano_fixture_download_root }}/server.py
> {{ ansistrano_fixture_download_root }}/server.log 2>&1
& echo $! > {{ ansistrano_fixture_download_root }}/server.pid
args:
creates: "{{ ansistrano_fixture_download_root }}/server.pid"

- name: Wait for HTTP fixture server
wait_for:
host: "127.0.0.1"
port: "{{ ansistrano_fixture_download_port }}"
timeout: 10

- name: When deploying using download strategy and a /download endpoint with querystring
hosts: all
vars:
ansistrano_deploy_via: "download_unarchive"
ansistrano_get_url: "http://127.0.0.1:18080/download?job=build:staging"
ansistrano_deploy_to: "/tmp/download/content-disposition"
roles:
- { role: local-ansistrano }

- name: Then the content-disposition download strategy should be unarchived successfully
hosts: all
vars:
ansistrano_deploy_to: "/tmp/download/content-disposition"
tasks:
- name: Assert downloaded archive was extracted
stat:
path: "{{ ansistrano_deploy_to }}/current/artifact/README.txt"
register: st
- debug:
msg: "Content-Disposition artifact was downloaded and extracted"
when: st.stat.exists is defined and st.stat.exists

- name: Clean up local download fixture server
hosts: all
vars:
ansistrano_fixture_download_root: "/tmp/ansistrano-download-fixture"
tasks:
- name: Stop HTTP fixture server
shell: kill "$(cat {{ ansistrano_fixture_download_root }}/server.pid)"
args:
removes: "{{ ansistrano_fixture_download_root }}/server.pid"

- name: Remove download fixture directory
file:
path: "{{ ansistrano_fixture_download_root }}"
state: absent
Loading