diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26a969c070c912a7e17b79d3f32a33162373d2f5..5f91aa17d6b67212bad451195244fb46360638c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,26 @@ default: - shell stages: + - default_validate - build + - deliver -build-job: +include: + - project: 'digit-c4/digitc4-template-cicd' + file: 'gitlab-ci-ansible.yml' + ref: main + +build-job: # This job runs in the build stage, which runs first. stage: build script: - - echo "Build..." + - ansible-playbook ansible/build.yml + +deliver-latest-job: + stage: deliver + variables: + IMAGE_TAG: "latest" + script: + - ansible-playbook ansible/deliver.yml + only: + - main + - master diff --git a/Dockerfile b/Dockerfile index 50269fd9c0131171bbbb539ef0417fdcd68ea02f..616d97f648c1c774f377f5e4eb75392247f6743d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,6 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* COPY . /opt/netbox/netbox/plugins/netbox_rps_plugin +COPY netbox_configuration/plugins.py /etc/netbox/config/plugins.py -RUN pip install /opt/netbox/netbox/plugins/netbox_rps_plugin - -RUN echo "PLUGINS = ['netbox_rps_plugin']" >> /opt/netbox/netbox/netbox/configuration.py +RUN pip install -r /opt/netbox/netbox/plugins/netbox_rps_plugin/requirements.txt diff --git a/ansible/build.yml b/ansible/build.yml new file mode 100644 index 0000000000000000000000000000000000000000..eb79cf26bb47ac6051e1165f9f4edb6bb628a6a9 --- /dev/null +++ b/ansible/build.yml @@ -0,0 +1,50 @@ +- name: Build testing image + hosts: localhost + + tasks: + - name: Log into private registry + docker_login: + registry: "{{ lookup('ansible.builtin.env','CI_REGISTRY') }}" + username: "{{ lookup('ansible.builtin.env','CI_REGISTRY_USER') }}" + password: "{{ lookup('ansible.builtin.env','CI_REGISTRY_PASSWORD') }}" + reauthorize: true + + - name: Remove image + community.docker.docker_image: + state: absent + name: "{{ lookup('ansible.builtin.env','CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + force_absent: true + + - name: Building image + community.docker.docker_image: + build: + path: ../ + args: + http_proxy: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}" + https_proxy: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}" + name: "{{ lookup('ansible.builtin.env','CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + repository: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + push: true + force_source: true + force_tag: true + source: build + + - name: Remove local image + community.docker.docker_image: + state: absent + name: "{{ lookup('ansible.builtin.env','CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + force_absent: true + + - name: Remove local image + community.docker.docker_image: + state: absent + name: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + force_absent: true + + - name: Log out of registry + community.docker.docker_login: + state: absent + + - name: debug + debug: + msg: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" diff --git a/ansible/deliver.yml b/ansible/deliver.yml new file mode 100644 index 0000000000000000000000000000000000000000..ad0fedbfe2d9f11720c146c4f763450eb5ab5a4c --- /dev/null +++ b/ansible/deliver.yml @@ -0,0 +1,39 @@ +- name: Push to Registry + hosts: localhost + + tasks: + - name: Log into private registry + docker_login: + registry: "{{ lookup('ansible.builtin.env','CI_REGISTRY') }}" + username: "{{ lookup('ansible.builtin.env','CI_REGISTRY_USER') }}" + password: "{{ lookup('ansible.builtin.env','CI_REGISTRY_PASSWORD') }}" + reauthorize: true + + - name: Get image to deliver + community.docker.docker_image: + name: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + source: pull + + - name: Push tag image + community.docker.docker_image: + name: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + repository: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','IMAGE_TAG') }}" + push: true + force_tag: true + source: local + + - name: Remove local image + community.docker.docker_image: + state: absent + name: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','CI_COMMIT_SHORT_SHA') }}" + force_absent: true + + - name: Remove local image + community.docker.docker_image: + state: absent + name: "{{ lookup('ansible.builtin.env','CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env','IMAGE_TAG') }}" + force_absent: true + + - name: Log out of registry + community.docker.docker_login: + state: absent diff --git a/ansible/start.yml b/ansible/start.yml new file mode 100644 index 0000000000000000000000000000000000000000..66b165cc85dfbf35f6311b61003c004783b5f243 --- /dev/null +++ b/ansible/start.yml @@ -0,0 +1,19 @@ +- name: Start services + hosts: localhost + + tasks: + - name: Log into private registry + docker_login: + registry: "{{ lookup('ansible.builtin.env','CI_REGISTRY') }}" + username: "{{ lookup('ansible.builtin.env','CI_REGISTRY_USER') }}" + password: "{{ lookup('ansible.builtin.env','CI_REGISTRY_PASSWORD') }}" + reauthorize: true + + - name: Start up services + community.docker.docker_compose: + project_src: ../ + files: + - docker-compose.yml + - docker-compose.testci.yml + state: present + remove_orphans: true diff --git a/ansible/stop.yml b/ansible/stop.yml new file mode 100644 index 0000000000000000000000000000000000000000..8ad54cd04507604c9bf6ea47c850c185a78d0fc0 --- /dev/null +++ b/ansible/stop.yml @@ -0,0 +1,10 @@ +- name: Stop Services + hosts: localhost + gather_facts: false + tasks: + - name: Tear down existing services + community.docker.docker_compose: + project_src: ./ + state: absent + remove_volumes: true + remove_orphans: true diff --git a/netbox_configuration/plugins.py b/netbox_configuration/plugins.py new file mode 100644 index 0000000000000000000000000000000000000000..209d3ac431c7d17b9f33ffecb244a3f5842f214e --- /dev/null +++ b/netbox_configuration/plugins.py @@ -0,0 +1 @@ +PLUGINS = ['netbox_dns', 'netbox_rps_plugin'] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c27f299c50e1fbb480c462725b01660d48bd856f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +/opt/netbox/netbox/plugins/netbox_rps_plugin +netbox-plugin-dns \ No newline at end of file