diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fdf05019197e8b473d25e84079d2b3f98c8c73d3..c01900b5ef38ba9ea7ebf30008a587839c3531d9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,18 +1,21 @@ --- -# image: python:3.10.15-bullseye - ### ### VARIABLES ### variables: AUTHOR: fejao + ### IMAGES IMAGE_NAME_SYNTAX: python:3.10.15-bullseye IMAGE_NAME_LINT: python:3.10.15-bullseye IMAGE_NAME_MOLECULE: python:3.10.15-bullseye # IMAGE_NAME_MOLECULE: geerlingguy/docker-ubuntu2204-ansible:latest ### PATHS - INVENTORIES_PATH: "inventories/hosts" + PATH_INVENTORIES: "inventories/hosts" + PATH_REQUIREMENTS_SYNTAX_N_LINT: "ci-cd/python_requirements/requirements_syntax_n_lint.txt" + PATH_ENV_DIR_DEPLOYMENT: "/builds/fejao/c3infodesk-deployment" + ### PATHS + # INVENTORIES_PATH: "inventories/hosts" PATH_PLAYBOOK_FOR_ROLE_TEST: "ci-cd/playbooks/01_test.yml" PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES: "ci-cd/playbooks/02_dependencies.yml" PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES: "ci-cd/playbooks/03_clone_repositories.yml" @@ -24,7 +27,7 @@ variables: ### STAGES ### stages: - - before-role-trigger + - debug-variables - syntax-checks - lint-tests - molecule @@ -33,7 +36,42 @@ stages: ### TEMPLATES ### include: - # - local: ci-cd/templates/trigger-pipeline.yml - - local: ci-cd/templates/syntax-checks.yml - - local: ci-cd/templates/lint-tests.yml - - local: ci-cd/templates/molecule.yml + ### ROLE TEST + - local: ci-cd/templates/role-test.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_TEST == "true"' + ### ROLE DEPENDENCIES + - local: ci-cd/templates/role-dependencies.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_DEPENDENCIES == "true"' + ### ROLE CLONE-REPOSITORIES + - local: ci-cd/templates/role-clone-repositories.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_CLONE_REPOSITORIES == "true"' + ### ROLE DOCKER-IMAGES + - local: ci-cd/templates/role-docker-images.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_DOCKER_IMAGES == "true"' + ### ROLE DOCKER-CONTAINERS + - local: ci-cd/templates/role-docker-containers.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_DOCKER_CONTAINERS == "true"' + ### ROLE OH-MY-BASH + - local: ci-cd/templates/role-oh-my-bash.yml + rules: + - if: '$RUN_UPSTREAM_FOR_ROLE_OH_MY_BASH == "true"' + +### +### TEST PARSED VARS FROM UPSTREAM +### +variables-debug: + stage: debug-variables + image: $IMAGE_NAME_SYNTAX + script: + - echo "Testing the parsed variables from up-stream..." + - echo "RUN_UPSTREAM_FOR_ROLE_TEST --> $RUN_UPSTREAM_FOR_ROLE_TEST" + - echo "RUN_UPSTREAM_FOR_ROLE_DEPENDENCIES --> $RUN_UPSTREAM_FOR_ROLE_DEPENDENCIES" + - echo "RUN_UPSTREAM_FOR_ROLE_CLONE_REPOSITORIES --> $RUN_UPSTREAM_FOR_ROLE_CLONE_REPOSITORIES" + - echo "RUN_UPSTREAM_FOR_ROLE_DOCKER_IMAGES --> $RUN_UPSTREAM_FOR_ROLE_DOCKER_IMAGES" + - echo "RUN_UPSTREAM_FOR_ROLE_DOCKER_CONTAINERS --> $RUN_UPSTREAM_FOR_ROLE_DOCKER_CONTAINERS" + - echo "RUN_UPSTREAM_FOR_ROLE_OH_MY_BASH --> $RUN_UPSTREAM_FOR_ROLE_OH_MY_BASH" diff --git a/ci-cd/scripts/syntax_n_lint.yml b/ci-cd/scripts/syntax_n_lint.yml index c934cf732de6803c0017e9d47e885717f659c297..647b2d6c031d5be7dac2f1176196b70121e69695 100644 --- a/ci-cd/scripts/syntax_n_lint.yml +++ b/ci-cd/scripts/syntax_n_lint.yml @@ -1,9 +1,7 @@ --- variables: - INVENTORIES_PATH: "inventories/hosts" - REQUIREMENTS_PATH: "ci-cd/python_requirements/requirements_syntax_n_lint.txt" - ENV_DIR_PATH: "/builds/fejao/c3infodesk-deployment" + AUTHOR: fejao ### ### SCRIPTS @@ -12,17 +10,16 @@ variables: before_script: - echo "Running before_script for 'before_script_syntax_n_lint'" - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r $REQUIREMENTS_PATH - ########### + - pip3 install -r $PATH_REQUIREMENTS_SYNTAX_N_LINT # ### Correct the permissions on the build environment directory. # ### See https://github.com/ansible/ansible/pull/42142/files - - chmod 700 $ENV_DIR_PATH + - chmod 700 $PATH_ENV_DIR_DEPLOYMENT .script_syntax_check_main: extends: .before_script_syntax_n_lint script: - echo "Running script for 'script_syntax_check_main'" - - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH + - ansible-playbook --syntax-check -i $PATH_INVENTORIES $PLAYBOOK_PATH .run_lint: extends: .before_script_syntax_n_lint diff --git a/ci-cd/templates/lint-tests.yml b/ci-cd/templates/lint-tests.yml deleted file mode 100644 index 7449c23b1b5e8b54e1139274f6f6a259b7147fc2..0000000000000000000000000000000000000000 --- a/ci-cd/templates/lint-tests.yml +++ /dev/null @@ -1,77 +0,0 @@ ---- - -### -### VARIABLES -### -variables: - AUTHOR: fejao - -### -### INCLUDE -### -include: - - local: /ci-cd/scripts/syntax_n_lint.yml - -### -### STAGE-LINT-TESTS -### -lint-test: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST - # only: - # changes: - # - roles/c3infodesk-deployment-role-test - -lint-dependencies: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES - # only: - # changes: - # - roles/c3infodesk-deployment-role-dependencies - -lint-clone-repositories: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES - # only: - # changes: - # - roles/c3infodesk-deployment-role-clone-repositories - -lint-docker-images: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES - # only: - # changes: - # - roles/c3infodesk-deployment-role-docker-containers - -lint-docker-containers: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS - # only: - # changes: - # - roles/c3infodesk-deployment-role-docker-containers - -lint-oh-my-bash: - stage: lint-tests - image: $IMAGE_NAME_LINT - extends: .run_lint - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_OH_MY_BASH - # only: - # changes: - # - roles/c3infodesk-deployment-role-oh-my-bash - diff --git a/ci-cd/templates/molecule.yml b/ci-cd/templates/molecule.yml deleted file mode 100644 index 1a311e0e0c8f8616dced084f9cfcc693f844f02b..0000000000000000000000000000000000000000 --- a/ci-cd/templates/molecule.yml +++ /dev/null @@ -1,72 +0,0 @@ ---- - -### -### VARIABLES -### -variables: - AUTHOR: fejao - -molecule-not-enabled: - stage: molecule - image: $IMAGE_NAME_MOLECULE - script: - - echo "This can't be done before enable DIND at the instance" - -### -### STAGE-MOLECULE --> At the moment, running DIND (docker in docker) at this instance is disable :( -### -# molecule-test: -# stage: molecule -# image: $IMAGE_NAME_MOLECULE -# ### AVAILABLE TAGS -# # https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64 -# tags: -# - saas-linux-small-amd64 -# # before_script: -# # # - apk add --no-cache python3 py3-pip -# # # - rm /usr/lib/python*/EXTERNALLY-MANAGED -# # # - python3 -m ensurepip -# # - pip3 install ansible ansible-lint molecule molecule-docker -# # - pip3 install --user "molecule-plugins[docker]" -# script: -# - echo "Running molecule tests at the role-> 'test'" -# - docker ps -a -# # - cd roles/test -# # - molecule test -# allow_failure: false - -# molecule-test: -# stage: molecule -# # image: docker:latest -# # image: docker:27.5.1-alpine3.21 -# # image: docker:27.5.1-dind -# # image: geerlingguy/docker-ubuntu2204-ansible:latest -# image: $IMAGE_NAME_MOLECULE -# before_script: -# # - apk add --no-cache python3 py3-pip -# # - rm /usr/lib/python*/EXTERNALLY-MANAGED -# # - python3 -m ensurepip -# - pip3 install ansible ansible-lint molecule molecule-docker -# - pip3 install --user "molecule-plugins[docker]" -# script: -# - echo "Running ansible-lint tests at the role-> 'test'" -# - docker ps -a -# # - cd roles/test -# # - molecule test -# allow_failure: false - -# molecule-test: -# stage: molecule -# # image: docker:latest -# image: docker:27.5.1-alpine3.21 -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# - pip3 install --upgrade molecule molecule-docker -# # - python3 -m pip install --user "molecule-plugins[docker] -# - pip3 install --user "molecule-plugins[docker]" -# script: -# - echo "Running ansible-lint tests at the role-> 'test'" -# - cd roles/test -# - molecule test -# allow_failure: false diff --git a/ci-cd/templates/role-clone-repositories.yml b/ci-cd/templates/role-clone-repositories.yml new file mode 100644 index 0000000000000000000000000000000000000000..f39780ae9210e0c89837829c0d867540f9cf729c --- /dev/null +++ b/ci-cd/templates/role-clone-repositories.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-clone-repositories: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### LINT +### +lint-clone-repositories: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### MOLECULE +### +molecule-dependencies: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/role-dependencies.yml b/ci-cd/templates/role-dependencies.yml new file mode 100644 index 0000000000000000000000000000000000000000..c13ac85fa5baf16d8f95ceaec33ca1d4200266bf --- /dev/null +++ b/ci-cd/templates/role-dependencies.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-dependencies: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-dependencies + +### +### LINT +### +lint-dependencies: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-dependencies + +### +### MOLECULE +### +molecule-dependencies: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/role-docker-containers.yml b/ci-cd/templates/role-docker-containers.yml new file mode 100644 index 0000000000000000000000000000000000000000..a5c75a31839f9dab9d96614f2cffa0d42aa0a814 --- /dev/null +++ b/ci-cd/templates/role-docker-containers.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-clone-repositories: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### LINT +### +lint-clone-repositories: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### MOLECULE +### +molecule-docker-containers: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/role-docker-images.yml b/ci-cd/templates/role-docker-images.yml new file mode 100644 index 0000000000000000000000000000000000000000..cebbff838f3b002b7905e7a65cbcbeb773bee3e4 --- /dev/null +++ b/ci-cd/templates/role-docker-images.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-docker-images: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES + # only: + # changes: + # - roles/c3infodesk-deployment-role-docker-images + +### +### LINT +### +lint-docker-images: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES + # only: + # changes: + # - roles/c3infodesk-deployment-role-docker-containers + +### +### MOLECULE +### +molecule-docker-images: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/role-oh-my-bash.yml b/ci-cd/templates/role-oh-my-bash.yml new file mode 100644 index 0000000000000000000000000000000000000000..da969cee82709aa13126181982b09344ecf8ece7 --- /dev/null +++ b/ci-cd/templates/role-oh-my-bash.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-clone-repositories: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### LINT +### +lint-clone-repositories: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES + # only: + # changes: + # - roles/c3infodesk-deployment-role-clone-repositories + +### +### MOLECULE +### +molecule-oh-my-bash: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/role-test.yml b/ci-cd/templates/role-test.yml new file mode 100644 index 0000000000000000000000000000000000000000..6517b079c74f63c25c32bdc41b92e4bd743350cf --- /dev/null +++ b/ci-cd/templates/role-test.yml @@ -0,0 +1,51 @@ +--- + +### +### VARIABLES +### +variables: + AUTHOR: fejao + +### +### INCLUDE +### +include: + - local: /ci-cd/scripts/syntax_n_lint.yml + +### +### SYNTAX +### +syntax-test: + stage: syntax-checks + image: $IMAGE_NAME_SYNTAX + extends: .script_syntax_check_main + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST + # only: + # changes: + # - roles/c3infodesk-deployment-role-test + +### +### LINT +### +lint-test: + stage: lint-tests + image: $IMAGE_NAME_LINT + extends: .run_lint + variables: + PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST + # only: + # changes: + # - roles/c3infodesk-deployment-role-test + +### +### MOLECULE +### +molecule-test: + stage: molecule + image: $IMAGE_NAME_MOLECULE + script: + - echo "This can't be done before enable DIND at the instance" + only: + refs: + - main diff --git a/ci-cd/templates/syntax-checks.yml b/ci-cd/templates/syntax-checks.yml deleted file mode 100644 index 04ffeb7152b20b197069dba32c8e134292e2b239..0000000000000000000000000000000000000000 --- a/ci-cd/templates/syntax-checks.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- - -### -### VARIABLES -### -variables: - AUTHOR: fejao - -### -### INCLUDE -### -include: - - local: /ci-cd/scripts/syntax_n_lint.yml - -### -### STAGE-SYNTAX-CHECKS -### -syntax-test: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST - # only: - # changes: - # - roles/c3infodesk-deployment-role-test - # refs: - # - main - -syntax-dependencies: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES - # only: - # changes: - # - roles/c3infodesk-deployment-role-dependencies - -syntax-clone-repositories: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES - # only: - # changes: - # - roles/c3infodesk-deployment-role-clone-repositories - -syntax-docker-images: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES - # only: - # changes: - # - roles/c3infodesk-deployment-role-docker-images - -syntax-docker-containers: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS - # only: - # changes: - # - roles/c3infodesk-deployment-role-docker-containers - -syntax-oh-my-bash: - stage: syntax-checks - image: $IMAGE_NAME_SYNTAX - extends: .script_syntax_check_main - variables: - PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_OH_MY_BASH - # only: - # changes: - # - roles/c3infodesk-deployment-role-oh-my-bash diff --git a/ci-cd/templates/trigger-pipeline.yml b/ci-cd/templates/trigger-pipeline.yml deleted file mode 100644 index 80458f266a0bba2b49c512b86bb3d05ddd6cb235..0000000000000000000000000000000000000000 --- a/ci-cd/templates/trigger-pipeline.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -### -### VARIABLES -### -variables: - AUTHOR: fejao - -trigger-pipeline: - stage: before-role-trigger - # trigger: - # include: <ChildFolder>/.gitlab-ci.yml - # trigger: - # # include: roles/c3infodesk-deployment-role-test/.gitlab-ci.yml - # include: /builds/fejao/c3infodesk-deployment/roles/c3infodesk-deployment-role-test/.gitlab-ci.yml - - script: - - echo "Triggering tests for the 'test' role" - - pwd - # /builds/fejao/c3infodesk-deployment - - ls -la - - ls -la roles - - ls -la roles/c3infodesk-deployment-role-test - - ls -la roles/c3infodesk-deployment-role-test/.gitlab-ci.yml