Aurelio Jargas 01755dad64 Pin artifactory Docker image to 7.77.12
The last successful run for the job `zuul-jobs-test-upload-artifactory`
was almost one year ago in 2024-05-12.

Currently, the artifactory container is unable to start successfully.
The ping task "Wait for artifactory to start" fails with:

    Status code was -1 and not [200]:
    Connection failure: [Errno 104] Connection reset by peer

In this change we're pinning the artifactory image to a version that was
likely to be set as `latest` back in 2024-05-12, according to
https://jfrog.com/help/r/jfrog-release-information/artifactory-7.77.12-self-hosted

This version worked locally, but it took a long time to startup:

    $ docker run -p 8081:8081 -p 8082:8082 --rm \
      docker.bintray.io/jfrog/artifactory-oss:7.77.12
    ...
    All services started successfully in 248.494 seconds

That's why this change is also increasing the delay in the retries.

While trying other more recent versions (7.77.17, 7.84.10), they failed
with:

    Failed pinging artifactory for 300connect ECONNREFUSED 127.0.0.1:8046

Change-Id: I6be6c28f902a73d5f1ff22d47b2d86b8ed9cbf43
2025-04-19 09:16:50 +02:00

138 lines
4.8 KiB
YAML

- hosts: all
tasks:
- name: Ensure docker is installed
include_role:
name: ensure-docker
- name: Start artifactory in a container
command: >-
docker run -d
-p 8081:8081 -p 8082:8082
--name {{ zuul.build }}
docker.bintray.io/jfrog/artifactory-oss:7.77.12
- name: Wait for artifactory to start
uri:
url: http://localhost:8082/artifactory/api/system/ping
method: GET
register: artifactory_status
until: artifactory_status.status == 200
retries: 12
delay: 20
- name: Create a generic repository in artifactory
uri:
url: http://localhost:8082/artifactory/api/system/configuration
user: admin
password: password
force_basic_auth: true
method: PATCH
body: |
localRepositories:
generic-repository:
type: generic
headers:
Content-Type: application/yaml
- name: Create an api key for the admin user
uri:
url: http://localhost:8082/artifactory/api/security/apiKey
user: admin
password: password
status_code: 201
return_content: true
method: POST
register: artifactory_api_key
- name: Set artifactory instances fact
set_fact:
cacheable: true
upload_artifactory_instances:
localhost_password:
fqdn: localhost:8081
transport: http
user: admin
password: password
force_basic_auth: true
localhost_api_key:
fqdn: localhost:8081
transport: http
user: admin
api_key: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
localhost_properties:
fqdn: localhost:8081
transport: http
user: admin
api_key: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
- hosts: all
vars:
# Since we're testing a role that normally requires a
# trusted context flip the delegate_to so we execute on the
# remote instead. Also set the working directory to something
# that is known to exist on the remote.
_undocumented_test_worker_node_: "{{ inventory_hostname }}"
_undocumented_test_work_dir_: "{{ ansible_user_dir }}/zuul-output"
pre_tasks:
- name: Write a file with some content to artifacts directory
copy:
content: |
First file
dest: "{{ ansible_user_dir }}/zuul-output/artifacts/test-file.txt"
- name: Set upload_artifactory_manifest_basic fact
set_fact:
upload_artifactory_manifest:
artifacts:
- name: test-password.txt
src: test-file.txt
dest: generic-repository/path/to/dest/test-password.txt
instance: localhost_password
- name: test-api-key.txt
src: test-file.txt
dest: generic-repository/path/to/dest/test-api-key.txt
instance: localhost_api_key
- name: test-properties.txt
src: test-file.txt
dest: generic-repository/path/to/dest/test-properties.txt
instance: localhost_properties
properties:
version: 1.0.0
supports:
- 1.0.1
- 1.0.2
roles:
- role: upload-artifactory
post_tasks:
- name: Load artifacts information from zuul_return
set_fact:
artifacts: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json) ['data']['zuul']['artifacts'] }}"
- name: Expected artifacts are backwards
set_fact:
expected_artifacts:
- name: test-properties.txt
url: http://localhost:8081/artifactory/generic-repository/path/to/dest/test-properties.txt
- name: test-api-key.txt
url: http://localhost:8081/artifactory/generic-repository/path/to/dest/test-api-key.txt
- name: test-password.txt
url: http://localhost:8081/artifactory/generic-repository/path/to/dest/test-password.txt
- name: Assert artifact
assert:
that:
- item.0.name == item.1.name
- item.0.url == item.1.url
loop: "{{ artifacts | zip(expected_artifacts) | list }}"
- name: Query properties artifact
uri:
method: POST
url: 'http://localhost:8081/artifactory/api/search/aql'
headers:
X-JFrog-Art-Api: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
Content-Type: 'text/plain'
body: 'items.find({"$and":[{"repo":"generic-repository"},{"path":"path/to/dest"},{"@version":"1.0.0"}]})'
register: artifact_query
- name: Assert property filtered response
assert:
that: artifact_query.json.results[0].name == 'test-properties.txt'