From b5d64505ea1491135189f0a9255da978eed0d68c Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Mon, 14 Mar 2022 16:24:26 +1300 Subject: [PATCH] Include from external file. --- .drone.jsonnet | 48 ++++-------------------------------------- .drone/utils.libsonnet | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 44 deletions(-) create mode 100644 .drone/utils.libsonnet diff --git a/.drone.jsonnet b/.drone.jsonnet index 7ba520e..70803ee 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -6,57 +6,17 @@ local distros = ['centos7', 'debian11']; -/* Configuration of DIND */ -local docker_service() = - { - name: 'docker', - image: 'docker:dind', - privileged: true, - volumes: [{ name: 'dockersock', path: '/var/run' },], - }; - -local email_notification() = - { - name: 'notify by email', - image: 'drillster/drone-email', - settings: - { host: 'mail.guise.net.nz', - username: - { from_secret: 'EMAIL_USER' }, - password: - { from_secret: 'EMAIL_PASS' }, - from: 'drone@guise.net.nz' - }, - when: - { status: [ 'changed', 'failure' ] }, - }; - -local test_distro(distribution) = - { - name: 'Test on %(distribution)s' % { distribution: distribution }, - volumes: [{ name: 'dockersock', path: '/var/run' },], - image: 'guisea/ansible-molecule:latest', - commands: [ - 'sleep 10', // give docker enough time to start - 'mkdir ${DRONE_REPO_NAME}', - 'rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME}', - 'cd ${DRONE_REPO_NAME}', - 'molecule test' - ], - environment: - { MOLECULE_DISTRO: '%(distribution)s' % { distribution: distribution } - }, - }; +local utils = import './.drone/docker_service.libsonnet'; local gen_pipeline(distro) = {kind: 'pipeline', type: 'docker', name: 'Test on %(distro)s' % { distro: distro }, steps: [ - test_distro(distro), - email_notification()], + utils.test_distro(distro), + utils.email_notification()], services: [ - docker_service(), + utils.docker_service(), ], volumes: [{ diff --git a/.drone/utils.libsonnet b/.drone/utils.libsonnet new file mode 100644 index 0000000..51becad --- /dev/null +++ b/.drone/utils.libsonnet @@ -0,0 +1,42 @@ +{ +docker_service():: + { + name: 'docker', + image: 'docker:dind', + privileged: true, + volumes: [{ name: 'dockersock', path: '/var/run' },], + }, + +email_notification():: + { + name: 'notify by email', + image: 'drillster/drone-email', + settings: + { host: 'mail.guise.net.nz', + username: + { from_secret: 'EMAIL_USER' }, + password: + { from_secret: 'EMAIL_PASS' }, + from: 'drone@guise.net.nz' + }, + when: + { status: [ 'changed', 'failure' ] }, + }, + +test_distro(distribution):: + { + name: 'Test on %(distribution)s' % { distribution: distribution }, + volumes: [{ name: 'dockersock', path: '/var/run' },], + image: 'guisea/ansible-molecule:latest', + commands: [ + 'sleep 10', // give docker enough time to start + 'mkdir ${DRONE_REPO_NAME}', + 'rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME}', + 'cd ${DRONE_REPO_NAME}', + 'molecule test' + ], + environment: + { MOLECULE_DISTRO: '%(distribution)s' % { distribution: distribution } + }, + }, +}