From 5d138edb0bbbdd35f06940a6393cf9b8f9a86e7e Mon Sep 17 00:00:00 2001 From: Laur Ivan Date: Fri, 28 Apr 2023 00:32:36 +0200 Subject: [PATCH] feat: Initial commit. --- .ansible-lint | 10 ++++ .gitattributes | 3 ++ .github/FUNDING.yml | 2 + .github/ISSUE_TEMPLATE/bug_report.md | 49 +++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 3 ++ .github/ISSUE_TEMPLATE/feature_request.md | 31 ++++++++++++ .github/ISSUE_TEMPLATE/refactor.md | 27 +++++++++++ .github/ISSUE_TEMPLATE/support_request.md | 27 +++++++++++ .github/stale.yml | 33 +++++++++++++ .gitignore | 15 ++++++ .travis.yml | 25 ++++++++++ .yamllint | 33 +++++++++++++ CHANGELOG.md | 18 +++++++ LICENSE | 10 ++++ README.md | 47 ++++++++++++++++++ defaults/main.yml | 44 +++++++++++++++++ handlers/main.yml | 2 + meta/main.yml | 25 ++++++++++ molecule/default/cleanup.yml | 27 +++++++++++ molecule/default/converge.yml | 5 ++ molecule/default/destroy.yml | 27 +++++++++++ molecule/default/molecule.yml | 37 ++++++++++++++ molecule/default/prepare.yml | 38 +++++++++++++++ molecule/default/requirements.yml | 4 ++ molecule/default/tests/test_app.yml | 12 +++++ molecule/default/verify.yml | 59 +++++++++++++++++++++++ tasks/config.yml | 23 +++++++++ tasks/install.yml | 7 +++ tasks/main.yml | 11 +++++ templates/docker-compose.yml.j2 | 43 +++++++++++++++++ templates/env.db.conf.j2 | 4 ++ templates/env.sonarqube.conf.j2 | 5 ++ test-requirements.txt | 6 +++ 33 files changed, 712 insertions(+) create mode 100644 .ansible-lint create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/refactor.md create mode 100644 .github/ISSUE_TEMPLATE/support_request.md create mode 100644 .github/stale.yml create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 .yamllint create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/default/cleanup.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/destroy.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/prepare.yml create mode 100644 molecule/default/requirements.yml create mode 100644 molecule/default/tests/test_app.yml create mode 100644 molecule/default/verify.yml create mode 100644 tasks/config.yml create mode 100644 tasks/install.yml create mode 100644 tasks/main.yml create mode 100644 templates/docker-compose.yml.j2 create mode 100644 templates/env.db.conf.j2 create mode 100644 templates/env.sonarqube.conf.j2 create mode 100644 test-requirements.txt diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..355eeac --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,10 @@ +--- +exclude_paths: + - ./molecule + - ./.travis.yml + - ./.github +parseable: true +skip_list: + - '204' +use_default_rules: true +verbosity: 1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d08e2bf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.yml linguist-detectable=true +*.yaml linguist-detectable=true +*.html linguist-detectable=false diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..2da2ded --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: equinoxel +patreon: laurivan \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..960f91b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,49 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG]" +labels: bug +assignees: '' + +--- + + + +### Description + +[Description of the issue] + +### Steps to Reproduce + +1. [First Step] +2. [Second Step] +3. [and so on...] + +**Expected behavior:** +[What you expect to happen] + +**Actual behavior:** +[What actually happens] + +**Reproduces how often:** +[What percentage of the time does it reproduce?] + +### Environment + +- The release version/s you are using: +- OS: +- Ansible Version: +- Python Version: +- Others: +### Additional Information + +[Any additional information, configuration or data that might be necessary to reproduce the issue.] diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..f3aad96 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,3 @@ +--- + +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..9b2e2d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,31 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE]" +labels: enhancement +assignees: '' + +--- + + + +### Description + +[Description of the issue] + +### Why is this needed? + +[A clear and concise description of why do you think this is needed] + +### Additional Information + +[Any additional information, configuration or data.] diff --git a/.github/ISSUE_TEMPLATE/refactor.md b/.github/ISSUE_TEMPLATE/refactor.md new file mode 100644 index 0000000..8d7bff6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/refactor.md @@ -0,0 +1,27 @@ +--- +name: Refactor +about: Found anything to refactor in this project? +title: "[REFACTOR]" +labels: clean-up +assignees: '' + +--- + + + +### Description + +[Description of the issue] + +### Link/s to the specific code that needs a refactor (if applicable) + +[Links] \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/support_request.md b/.github/ISSUE_TEMPLATE/support_request.md new file mode 100644 index 0000000..a5a9e07 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support_request.md @@ -0,0 +1,27 @@ +--- +name: Support Request +about: Support request or question about this project +title: "[SUPPORT]" +labels: question +assignees: '' + +--- + + + +### Description + +[Description of the issue] + +### Additional Information + +Any additional information, configuration or data that might be necessary to reproduce the issue. \ No newline at end of file diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..c765ed1 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,33 @@ +--- +issues: + # Number of days of inactivity before an issue becomes stale + daysUntilStale: 90 + # Number of days of inactivity before a stale issue is closed + daysUntilClose: 7 + # Issues with these labels will never be considered stale + exemptLabels: + - "pinned" + - "security" + - "good first issue" + # Label to use when marking an issue as stale + staleLabel: wontfix + # Comment to post when marking an issue as stale. Set to `false` to disable + markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + # Comment to post when closing a stale issue. Set to `false` to disable + closeComment: false + +pulls: + # Number of days of inactivity before a pull request becomes stale + daysUntilStale: 90 + # Number of days of inactivity before a stale pull request is closed + daysUntilClose: 7 + # Comment to post when marking a pull request as stale. Set to `false` to disable + markComment: > + This pull request has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + # Comment to post when closing a stale pull request. Set to `false` to disable + closeComment: false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2100e33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ + +tests/playbook.retry +tests/.cache +__pycache__ +.pytest_cache +.molecule +.cache +.venv + +*.iml +.idea +.project + +*.pyc +**/.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9ff0334 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +--- +dist: xenial +language: python +python: "3.9" +os: linux +services: + - docker +install: + - pip install -I pipenv + - pipenv sync +env: + jobs: + - MOLECULE_DISTRO=debian:buster-slim + - MOLECULE_DISTRO=debian:bullseye-slim +script: + - pipenv run molecule test --all + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: + if: branch = main + on_success: change + on_failure: always + recipients: + - laur.ivan@gmail.com diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..80f524b --- /dev/null +++ b/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +ignore: | + molecule/**/tests/ + .venv + .github + .travis.yml + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + empty-lines: + max: 3 + level: error + hyphens: + level: error + key-duplicates: enable + line-length: disable + new-lines: + type: unix + truthy: disable diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..76fb4db --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). + +## [Unreleased](https://github.com/equinoxel/ansible-role-sonarqube/tree/develop) +### Changed +### Added +### Removed +### Fixed + +## [X.Y.Z](https://github.com/equinoxel/ansible-role-sonarqube/tree/X.Y.Z) +### [Full Changelog](https://github.com/equinoxel/ansible-role-sonarqube/compare/1.0.0...X.Y.Z) +### Changed + *[#](https://github.com/equinoxel/ansible-role-sonarqube/issues/) \* @\ + +## [1.0.0](https://github.com/equinoxel/ansible-role-sonarqube/tree/1.0.0) +- Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1936a8d --- /dev/null +++ b/LICENSE @@ -0,0 +1,10 @@ +The MIT License (MIT) +===================== + +Copyright © 2023 Laur IVAN + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0693c5a --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Sonarqube Ansible role + +This role installs Sonarqube via Docker compose. + +## Requirements + +None + +## Role Variables + +All variables are listed below (see also `defaults/main.yml`). + +```yml +--- +``` + +## Dependencies + +You need a machine with docker and docker-compose installed. + +## Example Playbook + +```yml +- hosts: servers + roles: + - 'laurivan.Sonarqube' +``` + +## License + +This project is licensed under the [MIT](https://opensource.org/licenses/MIT) license - see the [LICENSE](LICENSE) file for details. + +![MIT License](https://img.shields.io/badge/license-MIT%20License-brightgreen) + +## Author Information + +This role was created in 2023 by [Laur Ivan](https://www.laurivan.com). + +## Built With + +![Ansible](https://img.shields.io/badge/ansible-5.2.0-green.svg) +![Molecule](https://img.shields.io/badge/molecule-3.4.0-green.svg) +![Goss](https://img.shields.io/badge/goss-0.3.16-green.svg) + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..9a738b8 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,44 @@ +--- + +## General +sonarqube_image: sonarqube:latest + +sonarqube_http_port: 3000 + +# Sonarqube paths +sonarqube_root_path: /var/local +# sonarqube_data_base: "{{ sonarqube_root_path }}/sonarqube" +sonarqube_config_path: "{{ sonarqube_root_path }}/conf/sonarqube" + +# sonarqube_data_volume: "{{ sonarqube_data_base }}/data" +# sonarqube_conf_volume: "{{ sonarqube_data_base }}/conf" +# sonarqube_logs_volume: "{{ sonarqube_data_base }}/logs" +# sonarqube_extensions_volume: "{{ sonarqube_data_base }}/extensions" +# sonarqube_bundled_plugins_volume: "{{ sonarqube_data_base }}/bundled_plugins" + +# sonarqube_db_volume: "{{ sonarqube_data_base }}/posgresql/db" +# sonarqube_db_data_volume: "{{ sonarqube_data_base }}/posgresql/data" + +sonarqube_db_user: "changeme" +sonarqube_db_password: "changeme" + +# Add other paths here to make sure they're created automatically +# +sonarqube_skeleton_paths: + - "{{ sonarqube_config_path }}" + # - "{{ sonarqube_data_volume }}" + # - "{{ sonarqube_conf_volume }}" + # - "{{ sonarqube_logs_volume }}" + # - "{{ sonarqube_extensions_volume }}" + # - "{{ sonarqube_bundled_plugins_volume }}" + # - "{{ sonarqube_db_volume }}" + # - "{{ sonarqube_db_data_volume }}" + +# Add more templates to be copied into the config +sonarqube_configuration_files: + - "docker-compose.yml" + - "env.sonarqube.conf" + - "env.db.conf" + +# Documentation +sonarqube_documentation_link: "https://www.laurivan.com" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..5c58b69 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# Handlers for sonarqube diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..6223b49 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,25 @@ +--- + +galaxy_info: + author: Laur Ivan (laur.ivan@gmail.com) + namespace: laurivan + role_name: sonarqube + description: Sonarqube Role + min_ansible_version: "2.4" + min_ansible_container_version: "2.4" + license: MIT + galaxy_tags: + - sonarqube + - testing + - security + platforms: + - name: Debian + versions: + - bullseye + - buster + + - name: Ubuntu + versions: + - bionic + - focal + - jammy diff --git a/molecule/default/cleanup.yml b/molecule/default/cleanup.yml new file mode 100644 index 0000000..53e971d --- /dev/null +++ b/molecule/default/cleanup.yml @@ -0,0 +1,27 @@ +--- +- name: Clean up + hosts: all + gather_facts: true + tasks: + - name: Load the defaults + ansible.builtin.include_vars: + dir: "../../defaults" + + - name: Check if the docker-compose file exists. + ansible.builtin.stat: + path: "{{ sonarqube_config_path | expanduser | realpath }}/docker-compose.yml" + register: docker_compose_file + + - name: Remove docker-compose. + community.docker.docker_compose: + project_src: "{{ sonarqube_config_path | expanduser | realpath }}/" + build: false + state: absent + when: docker_compose_file.stat.exists + become: false + + - name: Remove the docker-compose file + ansible.builtin.file: + path: "{{ sonarqube_config_path | expanduser | realpath }}/docker-compose.yml" + state: absent + when: docker_compose_file.stat.exists \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..e96290f --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: sonarqube_group + roles: + - role: "laurivan.sonarqube" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml new file mode 100644 index 0000000..44290b5 --- /dev/null +++ b/molecule/default/destroy.yml @@ -0,0 +1,27 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ molecule_no_log }}" + tasks: + # Developer must implement. + - name: Remove the docker image + community.docker.docker_container: + name: sonarqube + state: absent + + # Mandatory configuration for Molecule to function. + + - name: Populate instance config + ansible.builtin.set_fact: + instance_conf: {} + + - name: Dump instance config + ansible.builtin.copy: + content: | + # Molecule managed + {{ instance_conf | to_json | from_json | to_yaml }} + dest: "{{ molecule_instance_config }}" + mode: 0600 + when: server.changed | default(false) | bool diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..37e904b --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,37 @@ +--- +dependency: + name: galaxy + options: + ignore-certs: true + ignore-errors: true + role-file: molecule/requirements.yml + requirements-file: molecule/requirements.yml +driver: + name: docker +lint: | + yamllint . + ansible-lint . +platforms: + - name: sonarqube + groups: + - sonarqube_group + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos8}-ansible:latest" + privileged: true + pre_build_image: true + capabilities: + - SYS_ADMIN + tmpfs: + - /tmp + - /run + - /run/lock + volumes: + - '/sys/fs/cgroup:/sys/fs/cgroup:ro' + - '/var/run/docker.sock:/tmp/docker_mounted.sock' + command: '/lib/systemd/systemd' + stop_signal: 'RTMIN+3' +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} +verifier: + name: ansible diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..97c6914 --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,38 @@ +--- +- name: Setup the test machine + hosts: sonarqube + tasks: + - name: Check if /var/run/docker.sock already exists + ansible.builtin.stat: + path: "/var/run/docker.sock" + register: docker_sock_stat + + - name: Create docker.sock + ansible.builtin.raw: touch /var/run/docker.sock + become: true + changed_when: false + when: not docker_sock_stat.stat.exists + + - name: Move docker.sock from tmp + ansible.builtin.raw: > + mount --move /tmp/docker_mounted.sock /var/run/docker.sock + become: true + changed_when: false + when: not docker_sock_stat.stat.exists + + - name: Update apt cache. + ansible.builtin.apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + + - name: Install python requests + ansible.builtin.pip: + name: + - requests + - docker + - docker-compose + + - name: Install docker + vars: + docker_service_manage: false + ansible.builtin.include_role: + name: geerlingguy.docker diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..a6284de --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,4 @@ +--- +roles: + - geerlingguy.docker +collections: [] diff --git a/molecule/default/tests/test_app.yml b/molecule/default/tests/test_app.yml new file mode 100644 index 0000000..38a1eea --- /dev/null +++ b/molecule/default/tests/test_app.yml @@ -0,0 +1,12 @@ +--- +## TODO: Remember to adapt goss tests to your convenience + + +## Check if ports are really exposed +# port: +# # Check port at IPv6 +# # https://github.com/aelsabbahy/goss/issues/177 +# tcp6:: +# listening: true +# ip: +# - '::' diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..eaf55cc --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,59 @@ +--- +# This is an example playbook to execute goss tests. +# Tests need distributed to the appropriate ansible host/groups +# prior to execution by `goss validate`. + +- name: Verify sonarqube + hosts: + - sonarqube + become: true + vars: + goss_version: v0.3.16 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + goss_test_directory: /tmp + goss_format: documentation + + vars_files: + - ../../defaults/main.yml + + tasks: + - name: Download and install Goss + get_url: + url: "{{ goss_url }}" + dest: "{{ goss_dst }}" + checksum: "sha256:{{ goss_sha256sum }}" + mode: 0755 + register: download_goss + until: download_goss is succeeded + retries: 3 + + - name: Copy Goss tests to remote + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "tests/test_*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_*.yml" + register: test_files + + - name: Execute Goss tests + command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}" + register: test_results + with_items: "{{ test_files.stdout_lines }}" + ignore_errors: true + + - name: Display details about the Goss results + debug: + msg: "{{ item.stdout_lines }}" + with_items: "{{ test_results.results }}" + + - name: Fail when tests fail + fail: + msg: "Goss failed to validate" + when: item.rc != 0 + with_items: "{{ test_results.results }}" diff --git a/tasks/config.yml b/tasks/config.yml new file mode 100644 index 0000000..9f8301b --- /dev/null +++ b/tasks/config.yml @@ -0,0 +1,23 @@ +--- +- name: "SONARQUBE | Set up directories" + ansible.builtin.file: + state: directory + path: "{{ item }}" + owner: "{{ ansible_effective_user_id }}" + group: "{{ ansible_effective_group_id }}" + mode: "0750" + with_items: + - "{{ sonarqube_skeleton_paths }}" + tags: + - sonarqube_configure + become: true + +- name: "SONARQUBE | Write configuration files" + ansible.builtin.template: + src: "{{ item }}.j2" + dest: "{{ sonarqube_config_path | expanduser | realpath }}/{{ item }}" + mode: '0640' + with_items: + - "{{ sonarqube_configuration_files }}" + tags: + - sonarqube_configure diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..fe6382d --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,7 @@ +--- +- name: "SONARQUBE | Ensure sonarqube is running" + community.docker.docker_compose: + project_src: "{{ sonarqube_config_path | expanduser | realpath }}" + build: false + tags: + - sonarqube_install diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..94a79a0 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,11 @@ +--- + +- name: "SONARQUBE | Configure" + ansible.builtin.import_tasks: config.yml + tags: + - sonarqube_configure + +- name: "SONARQUBE | Install" + ansible.builtin.import_tasks: install.yml + tags: + - sonarqube_install diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..6aa42ea --- /dev/null +++ b/templates/docker-compose.yml.j2 @@ -0,0 +1,43 @@ +# sonarqube docker compose +version: '3.9' +services: + sonarqube: + image: "{{ sonarqube_image }}" + container_name: sonarqube-service + restart: always + env_file: + - "{{ sonarqube_config_path | expanduser }}/env.sonarqube.conf" + ports: + - "{{ sonarqube_http_port }}" + # Add more ports if necessary + networks: + - sonarqube-net + # optional + volumes: + - sonarqube_conf:/opt/sonarqube/conf + - sonarqube_data:/opt/sonarqube/data + - sonarqube_extensions:/opt/sonarqube/extensions + - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins + depends_on: + - db + + db: + image: postgres:12 + container_name: sonarqube-db + restart: always + env_file: + - "{{ sonarqube_config_path | expanduser }}/env.db.conf" + volumes: + - sonarqube_db:/var/lib/postgresql + - postgresql_data:/var/lib/postgresql/data + +volumes: + postgresql_data: + sonarqube_bundled-plugins: + sonarqube_conf: + sonarqube_data: + sonarqube_db: + sonarqube_extensions: + +networks: + sonarqube-net: {} \ No newline at end of file diff --git a/templates/env.db.conf.j2 b/templates/env.db.conf.j2 new file mode 100644 index 0000000..730ef4b --- /dev/null +++ b/templates/env.db.conf.j2 @@ -0,0 +1,4 @@ +# Database configuration +POSTGRES_USER={{ sonarqube_db_user }} +POSTGRES_PASSWORD={{ sonarqube_db_password }} +POSTGRES_DB=sonarqube \ No newline at end of file diff --git a/templates/env.sonarqube.conf.j2 b/templates/env.sonarqube.conf.j2 new file mode 100644 index 0000000..252771f --- /dev/null +++ b/templates/env.sonarqube.conf.j2 @@ -0,0 +1,5 @@ +# Add environment variables for sonarqube here +# Note: This is a .ini file format +SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonarqube +SONAR_JDBC_USERNAME={{ sonarqube_db_user }} +SONAR_JDBC_PASSWORD={{ sonarqube_db_password }} diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..a0bf4f5 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,6 @@ +ansible==7.2.0 +molecule==4.0.4 +docker==6.0.1 +molecule-docker==2.1.0 +ansible-lint==6.14.4 +yamllint==1.30.0 \ No newline at end of file