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.
 
 

118 lines
5.4 KiB

  1. # SPDX-FileCopyrightText: 2021 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2021 Alexandar Mechev
  3. # SPDX-FileCopyrightText: 2022 Cody Wyatt Neiman
  4. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  5. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  6. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  7. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  8. # SPDX-FileCopyrightText: 2024 David Mehren
  9. #
  10. # SPDX-License-Identifier: AGPL-3.0-or-later
  11. ---
  12. - name: Ensure Beeper LinkedIn paths exists
  13. ansible.builtin.file:
  14. path: "{{ item.path }}"
  15. state: directory
  16. mode: '0750'
  17. owner: "{{ matrix_user_name }}"
  18. group: "{{ matrix_group_name }}"
  19. with_items:
  20. - {path: "{{ matrix_beeper_linkedin_base_path }}", when: true}
  21. - {path: "{{ matrix_beeper_linkedin_config_path }}", when: true}
  22. - {path: "{{ matrix_beeper_linkedin_data_path }}", when: true}
  23. - {path: "{{ matrix_beeper_linkedin_container_src_files_path }}", when: "{{ matrix_beeper_linkedin_container_image_self_build }}"}
  24. when: "item.when | bool"
  25. - name: Ensure beeper-linkedin config.yaml installed
  26. ansible.builtin.copy:
  27. content: "{{ matrix_beeper_linkedin_configuration | to_nice_yaml(indent=2, width=999999) }}"
  28. dest: "{{ matrix_beeper_linkedin_config_path }}/config.yaml"
  29. mode: '0644'
  30. owner: "{{ matrix_user_name }}"
  31. group: "{{ matrix_group_name }}"
  32. register: matrix_beeper_linkedin_config_result
  33. - name: Ensure beeper-linkedin registration.yaml installed
  34. ansible.builtin.copy:
  35. content: "{{ matrix_beeper_linkedin_registration | to_nice_yaml(indent=2, width=999999) }}"
  36. dest: "{{ matrix_beeper_linkedin_config_path }}/registration.yaml"
  37. mode: '0644'
  38. owner: "{{ matrix_user_name }}"
  39. group: "{{ matrix_group_name }}"
  40. register: matrix_beeper_linkedin_registration_result
  41. - name: Ensure Beeper LinkedIn container image is pulled
  42. community.docker.docker_image_pull:
  43. name: "{{ matrix_beeper_linkedin_container_image }}"
  44. pull: always
  45. when: "not matrix_beeper_linkedin_container_image_self_build | bool"
  46. register: matrix_beeper_linkedin_container_image_pull_result
  47. retries: "{{ devture_playbook_help_container_retries_count }}"
  48. delay: "{{ devture_playbook_help_container_retries_delay }}"
  49. until: matrix_beeper_linkedin_container_image_pull_result is not failed
  50. - when: "matrix_beeper_linkedin_container_image_self_build | bool"
  51. block:
  52. - name: Ensure Beeper LinkedIn repository is present on self-build
  53. ansible.builtin.git:
  54. repo: "{{ matrix_beeper_linkedin_container_image_self_build_repo }}"
  55. dest: "{{ matrix_beeper_linkedin_container_src_files_path }}"
  56. version: "{{ matrix_beeper_linkedin_container_image_self_build_branch }}"
  57. force: "yes"
  58. become: true
  59. become_user: "{{ matrix_user_name }}"
  60. register: matrix_beeper_linkedin_git_pull_results
  61. # Building the container image (using the default Dockerfile) requires that a docker-requirements.txt file be generated.
  62. # See: https://github.com/beeper/linkedin/blob/94442db17ccb9769b377cdb8e4bf1cb3955781d7/.gitlab-ci.yml#L30-40
  63. - name: Ensure docker-requirements.txt is generated before building Beeper LinkedIn container image
  64. ansible.builtin.command:
  65. cmd: |
  66. {{ devture_systemd_docker_base_host_command_docker }} run
  67. --rm
  68. --entrypoint=/bin/sh
  69. --mount type=bind,src={{ matrix_beeper_linkedin_container_src_files_path }},dst=/work
  70. -w /work
  71. docker.io/python:3.9.6-buster
  72. -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt"
  73. register: matrix_beeper_linkedin_generate_docker_requirements_result
  74. changed_when: matrix_beeper_linkedin_generate_docker_requirements_result.rc == 0
  75. - name: Ensure Beeper LinkedIn container image is built
  76. community.docker.docker_image_build:
  77. name: "{{ matrix_beeper_linkedin_container_image }}"
  78. dockerfile: Dockerfile
  79. path: "{{ matrix_beeper_linkedin_container_src_files_path }}"
  80. pull: true
  81. rebuild: "{{ 'always' if matrix_beeper_linkedin_git_pull_results.changed | bool else 'never' }}"
  82. args:
  83. TARGETARCH: "{{ matrix_architecture }}"
  84. register: matrix_beeper_linkedin_container_image_build_result
  85. - name: Ensure beeper-linkedin container network is created
  86. community.general.docker_network:
  87. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  88. name: "{{ matrix_beeper_linkedin_container_network }}"
  89. driver: bridge
  90. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  91. - name: Ensure matrix-beeper-linkedin.service installed
  92. ansible.builtin.template:
  93. src: "{{ role_path }}/templates/systemd/matrix-beeper-linkedin.service.j2"
  94. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-beeper-linkedin.service"
  95. mode: '0644'
  96. register: matrix_beeper_linkedin_systemd_service_result
  97. - name: Determine whether matrix-beeper-linkedin needs a restart
  98. ansible.builtin.set_fact:
  99. matrix_beeper_linkedin_restart_necessary: >-
  100. {{
  101. matrix_beeper_linkedin_config_result.changed | default(false)
  102. or matrix_beeper_linkedin_registration_result.changed | default(false)
  103. or matrix_beeper_linkedin_systemd_service_result.changed | default(false)
  104. or matrix_beeper_linkedin_container_image_pull_result.changed | default(false)
  105. or matrix_beeper_linkedin_container_image_build_result.changed | default(false)
  106. }}