From 4e2d8cd47c80fb51261d11ca287738603aa0f1fc Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 18 Oct 2019 13:30:31 +0200 Subject: [PATCH] refactor ci pipeline --- .drone.jsonnet | 227 ++++++++++++++++++++-------------- .drone.yml | 85 +++++++++---- .gitignore | 2 - .yamllint | 33 +++++ HEADER.md | 4 + molecule/default/molecule.yml | 2 +- 6 files changed, 232 insertions(+), 121 deletions(-) create mode 100644 .yamllint create mode 100644 HEADER.md diff --git a/.drone.jsonnet b/.drone.jsonnet index b27694c..3276ca7 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -1,107 +1,148 @@ -local AnsibleVersions(version="latest", package="ansible") = { - name: "ansible-" + version, - image: "python:3.7", - pull: "always", - environment: { - PY_COLORS: 1 +local PipelineLinting = { + kind: "pipeline", + name: "linting", + platform: { + os: "linux", + arch: "amd64", }, - commands: [ - "pip install " + package + " ansible-later~=0.2.0 -qq", - "git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy", - "ansible-later -c ~/policy/config.yml" - ], - depends_on: [ - "clone", + steps: [ + { + name: "ansible-later", + image: "xoxys/ansible-later:latest", + environment: { + PY_COLORS: 1 + }, + commands: [ + "git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy", + "ansible-later -c ~/policy/config.yml" + ], + }, ], + trigger: { + ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"], + }, }; -local PipelineLinting = { - kind: "pipeline", - name: "linting", - platform: { - os: "linux", - arch: "amd64", - }, - steps: [ - AnsibleVersions(version="latest", package="ansible"), - AnsibleVersions(version="master", package="git+https://github.com/ansible/ansible.git@devel"), - ], - trigger: { - ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"], - }, +local PipelineDeployment = { + kind: "pipeline", + name: "deployment", + platform: { + os: "linux", + arch: "amd64", + }, + concurrency: { + limit: 1 + }, + workspace: { + base: "/drone/src", + path: "xoxys.python3" + }, + steps: [ + { + name: "ansible-molecule", + image: "xoxys/molecule:do-linux-amd64", + environment: { + DO_API_KEY: { "from_secret": "do_api_key" }, + USER: "root", + MOLECULE_CUSTOM_MODULES_REPO: "https://gitea.rknet.org/ansible/custom_modules", + MOLECULE_CUSTOM_FILTERS_REPO: "https://gitea.rknet.org/ansible/custom_filters", + PY_COLORS: 1 + }, + commands: [ + "/bin/bash /docker-entrypoint.sh", + "molecule test -s default", + ], + }, + ], + depends_on: [ + "linting", + ], + trigger: { + ref: ["refs/heads/master", "refs/tags/**"], + }, }; -local PipelineDeployment = { - kind: "pipeline", - name: "deployment", - platform: { - os: "linux", - arch: "amd64", - }, - workspace: { - base: "/drone/src", - path: "xoxys.python3" - }, - steps: [ - { - name: "molecule", - image: "xoxys/molecule:do-linux-amd64", - pull: "always", - environment: { - DO_API_KEY: { "from_secret": "do_api_key" }, - USER: "root", - MOLECULE_CUSTOM_MODULES_REPO: "https://gitea.rknet.org/ansible/custom_modules", - MOLECULE_CUSTOM_FILTERS_REPO: "https://gitea.rknet.org/ansible/custom_filters", - PY_COLORS: 1 - }, - commands: [ - "/bin/bash /docker-entrypoint.sh", - "molecule test -s default", - ], +local PipelineDocumentation = { + kind: "pipeline", + name: "documentation", + platform: { + os: "linux", + arch: "amd64", + }, + steps: [ + { + name: "ansible-doctor", + image: "xoxys/ansible-doctor:latest", + environment: { + ANSIBLE_DOCTOR_LOG_LEVEL: "INFO", + ANSIBLE_DOCTOR_FORCE_OVERWRITE: true, + ANSIBLE_DOCTOR_EXCLUDE_FILES: "molecule/", + ANSIBLE_DOCTOR_CUSTOM_HEADER: "HEADER.md", + PY_COLORS: 1 + }, + }, + { + name: "push-to-repo", + image: "plugins/git-action:latest", + settings: { + actions: ["commit", "push"], + author_email: "shipper@rknet.org", + author_name: "DroneShipper", + branch: "master", + message: "[SKIP CI] update readme", + remote: "https://gitea.rknet.org/ansible/xoxys.python3", + netrc_machine: "gitea.rknet.org", + netrc_username: {"from_secret": "gitea_username"}, + netrc_password: {"from_secret": "gitea_token"}, + }, + when: { + ref: ["refs/heads/master"], + }, + }, + ], + depends_on: [ + "deployment", + ], + trigger: { + ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"], }, - ], - depends_on: [ - "linting", - ], - trigger: { - ref: ["refs/heads/master", "refs/tags/**"], - }, }; -local PipelineNotifications = { - kind: "pipeline", - name: "notifications", - platform: { - os: "linux", - arch: "amd64", - }, - clone: { - disable: true, - }, - steps: [ - { - name: "matrix", - image: "plugins/matrix", - settings: { - homeserver: "https://matrix.rknet.org", - roomid: "MtidqQXWWAtQcByBhH:rknet.org", - template: "Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}", - username: { "from_secret": "matrix_username" }, - password: { "from_secret": "matrix_password" }, - }, +local PipelineNotification= { + kind: "pipeline", + name: "notification", + platform: { + os: "linux", + arch: "amd64", + }, + clone: { + disable: true, + }, + steps: [ + { + name: "matrix", + image: "plugins/matrix", + settings: { + homeserver: { "from_secret": "matrix_homeserver" }, + roomid: { "from_secret": "matrix_roomid" }, + template: "Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}", + username: { "from_secret": "matrix_username" }, + password: { "from_secret": "matrix_password" }, + }, + }, + ], + depends_on: [ + "documentation", + ], + trigger: { + status: [ "success", "failure" ], + ref: ["refs/heads/master", "refs/tags/**"], }, - ], - depends_on: [ - "deployment", - ], - trigger: { - status: [ "success", "failure" ], - ref: ["refs/heads/master", "refs/tags/**"], - }, }; [ - PipelineLinting, - PipelineDeployment, - PipelineNotifications, + PipelineLinting, + PipelineDeployment, + PipelineDocumentation, + PipelineNotification, ] diff --git a/.drone.yml b/.drone.yml index c4785d2..10ce886 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,29 +7,13 @@ platform: arch: amd64 steps: -- name: ansible-latest - pull: always - image: python:3.7 +- name: ansible-later + image: xoxys/ansible-later:latest commands: - - pip install ansible ansible-later~=0.2.0 -qq - git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy - ansible-later -c ~/policy/config.yml environment: PY_COLORS: 1 - depends_on: - - clone - -- name: ansible-master - pull: always - image: python:3.7 - commands: - - "pip install git+https://github.com/ansible/ansible.git@devel ansible-later~=0.2.0 -qq" - - git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy - - ansible-later -c ~/policy/config.yml - environment: - PY_COLORS: 1 - depends_on: - - clone trigger: ref: @@ -45,13 +29,15 @@ platform: os: linux arch: amd64 +concurrency: + limit: 1 + workspace: base: /drone/src path: xoxys.python3 steps: -- name: molecule - pull: always +- name: ansible-molecule image: xoxys/molecule:do-linux-amd64 commands: - /bin/bash /docker-entrypoint.sh @@ -74,7 +60,54 @@ depends_on: --- kind: pipeline -name: notifications +name: documentation + +platform: + os: linux + arch: amd64 + +steps: +- name: ansible-doctor + image: xoxys/ansible-doctor:latest + environment: + ANSIBLE_DOCTOR_CUSTOM_HEADER: HEADER.md + ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/ + ANSIBLE_DOCTOR_FORCE_OVERWRITE: true + ANSIBLE_DOCTOR_LOG_LEVEL: INFO + PY_COLORS: 1 + +- name: push-to-repo + image: plugins/git-action:latest + settings: + actions: + - commit + - push + author_email: "shipper@rknet.org" + author_name: DroneShipper + branch: master + message: "[SKIP CI] update readme" + netrc_machine: gitea.rknet.org + netrc_password: + from_secret: gitea_token + netrc_username: + from_secret: gitea_username + remote: https://gitea.rknet.org/ansible/xoxys.python3 + when: + ref: + - refs/heads/master + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- deployment + +--- +kind: pipeline +name: notification platform: os: linux @@ -87,10 +120,12 @@ steps: - name: matrix image: plugins/matrix settings: - homeserver: https://matrix.rknet.org + homeserver: + from_secret: matrix_homeserver password: from_secret: matrix_password - roomid: MtidqQXWWAtQcByBhH:rknet.org + roomid: + from_secret: matrix_roomid template: "Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}" username: from_secret: matrix_username @@ -104,10 +139,10 @@ trigger: - failure depends_on: -- deployment +- documentation --- kind: signature -hmac: dcbfd67bd82e9f46e08a46d27c123391441d6efe733deb6508125cc5079c3d7e +hmac: 7e54586f39e5e24f1b1900880efbb7e13a7a45e9f1fe92838a7792290459fc31 ... diff --git a/.gitignore b/.gitignore index 3c21f75..5becda8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,3 @@ __pycache__/ *.py[cod] *$py.class -# ---> Molecule -.yamllint diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +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 + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/HEADER.md b/HEADER.md new file mode 100644 index 0000000..63ebed9 --- /dev/null +++ b/HEADER.md @@ -0,0 +1,4 @@ +# xoxys.python3 + +[![Build Status](https://drone.rknet.org/api/badges/ansible/xoxys.python/status.svg)](https://drone.rknet.org/ansible/xoxys.python) + diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 476cce7..c55df56 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -4,7 +4,7 @@ dependency: driver: name: digitalocean platforms: - - name: centos7-python3 + - name: centos7-python region_id: fra1 image_id: centos-7-x64 size_id: s-1vcpu-1gb