Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

104 line
4.9 KiB

  1. ---
  2. # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
  3. # We don't want to fail in such cases.
  4. - name: Fail if matrix-synapse role already executed
  5. ansible.builtin.fail:
  6. msg: >-
  7. The matrix-bridge-beeper-linkedin role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed | default(False)"
  9. - name: Ensure Beeper LinkedIn paths exists
  10. ansible.builtin.file:
  11. path: "{{ item.path }}"
  12. state: directory
  13. mode: 0750
  14. owner: "{{ matrix_user_username }}"
  15. group: "{{ matrix_user_groupname }}"
  16. with_items:
  17. - {path: "{{ matrix_beeper_linkedin_base_path }}", when: true}
  18. - {path: "{{ matrix_beeper_linkedin_config_path }}", when: true}
  19. - {path: "{{ matrix_beeper_linkedin_data_path }}", when: true}
  20. - {path: "{{ matrix_beeper_linkedin_docker_src_files_path }}", when: "{{ matrix_beeper_linkedin_container_image_self_build }}"}
  21. when: "item.when | bool"
  22. - name: Ensure Beeper LinkedIn image is pulled
  23. docker_image:
  24. name: "{{ matrix_beeper_linkedin_docker_image }}"
  25. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  26. force_source: "{{ matrix_beeper_linkedin_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  27. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_beeper_linkedin_docker_image_force_pull }}"
  28. when: "not matrix_beeper_linkedin_container_image_self_build | bool"
  29. register: result
  30. retries: "{{ matrix_container_retries_count }}"
  31. delay: "{{ matrix_container_retries_delay }}"
  32. until: result is not failed
  33. - when: "matrix_beeper_linkedin_container_image_self_build | bool"
  34. block:
  35. - name: Ensure Beeper LinkedIn repository is present on self-build
  36. ansible.builtin.git:
  37. repo: "{{ matrix_beeper_linkedin_container_image_self_build_repo }}"
  38. dest: "{{ matrix_beeper_linkedin_docker_src_files_path }}"
  39. version: "{{ matrix_beeper_linkedin_container_image_self_build_branch }}"
  40. force: "yes"
  41. become: true
  42. become_user: "{{ matrix_user_username }}"
  43. register: matrix_beeper_linkedin_git_pull_results
  44. # Building the container image (using the default Dockerfile) requires that a docker-requirements.txt file be generated.
  45. # See: https://github.com/beeper/linkedin/blob/94442db17ccb9769b377cdb8e4bf1cb3955781d7/.gitlab-ci.yml#L30-40
  46. - name: Ensure docker-requirements.txt is generated before building Beeper LinkedIn Docker Image
  47. ansible.builtin.command:
  48. cmd: |
  49. {{ matrix_host_command_docker }} run
  50. --rm
  51. --entrypoint=/bin/sh
  52. --mount type=bind,src={{ matrix_beeper_linkedin_docker_src_files_path }},dst=/work
  53. -w /work
  54. docker.io/python:3.9.6-buster
  55. -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt"
  56. register: matrix_beeper_linkedin_generate_docker_requirements_result
  57. changed_when: matrix_beeper_linkedin_generate_docker_requirements_result.rc == 0
  58. - name: Ensure Beeper LinkedIn Docker image is built
  59. docker_image:
  60. name: "{{ matrix_beeper_linkedin_docker_image }}"
  61. source: build
  62. force_source: "{{ matrix_beeper_linkedin_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  63. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_beeper_linkedin_git_pull_results.changed }}"
  64. build:
  65. dockerfile: Dockerfile
  66. path: "{{ matrix_beeper_linkedin_docker_src_files_path }}"
  67. pull: true
  68. args:
  69. TARGETARCH: "{{ matrix_architecture }}"
  70. - name: Ensure beeper-linkedin config.yaml installed
  71. ansible.builtin.copy:
  72. content: "{{ matrix_beeper_linkedin_configuration | to_nice_yaml(indent=2, width=999999) }}"
  73. dest: "{{ matrix_beeper_linkedin_config_path }}/config.yaml"
  74. mode: 0644
  75. owner: "{{ matrix_user_username }}"
  76. group: "{{ matrix_user_groupname }}"
  77. - name: Ensure beeper-linkedin registration.yaml installed
  78. ansible.builtin.copy:
  79. content: "{{ matrix_beeper_linkedin_registration | to_nice_yaml(indent=2, width=999999) }}"
  80. dest: "{{ matrix_beeper_linkedin_config_path }}/registration.yaml"
  81. mode: 0644
  82. owner: "{{ matrix_user_username }}"
  83. group: "{{ matrix_user_groupname }}"
  84. - name: Ensure matrix-beeper-linkedin.service installed
  85. ansible.builtin.template:
  86. src: "{{ role_path }}/templates/systemd/matrix-beeper-linkedin.service.j2"
  87. dest: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service"
  88. mode: 0644
  89. register: matrix_beeper_linkedin_systemd_service_result
  90. - name: Ensure systemd reloaded after matrix-beeper-linkedin.service installation
  91. ansible.builtin.service:
  92. daemon_reload: true
  93. when: "matrix_beeper_linkedin_systemd_service_result.changed"