Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 7a551ddc authored by Laurent VENIER's avatar Laurent VENIER :speech_balloon:
Browse files

Merge branch 'autobuild-docker-images' into 'main'

add docker images builder

See merge request digit-c4/netbox-mapping!2
parents 8f567fe1 0dbbb105
No related branches found
No related tags found
1 merge request!2add docker images builder
Pipeline #59119 passed
......@@ -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
......@@ -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
- 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') }}"
- 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
- 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
- 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
PLUGINS = ['netbox_dns', 'netbox_rps_plugin']
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment