refactoring

This commit is contained in:
Robert Kaussow 2020-02-20 17:24:52 +01:00
parent ae4010b6a1
commit 89f60c8795
8 changed files with 183 additions and 136 deletions

View File

@ -1,129 +1,132 @@
local PipelineBuild(arch="amd64") = { local PipelineBuild(arch='amd64') = {
kind: "pipeline", kind: 'pipeline',
name: "build-" + arch, name: 'build-' + arch,
platform: { platform: {
os: "linux", os: 'linux',
arch: arch, arch: arch,
}, },
steps: [ steps: [
{ {
name: "dryrun", name: 'dryrun',
image: "plugins/docker:18-linux-" + arch, image: 'plugins/docker:18-linux-' + arch,
pull: "always",
settings: { settings: {
dry_run: true, dry_run: true,
dockerfile: "Dockerfile", dockerfile: 'Dockerfile.' + arch,
repo: "xoxys/molecule", repo: 'xoxys/molecule',
username: { from_secret: "docker_username" }, username: { from_secret: 'docker_username' },
password: { from_secret: "docker_password" }, password: { from_secret: 'docker_password' },
},
},
{
name: "publish",
image: "plugins/docker:18-linux-" + arch,
pull: "always",
settings: {
auto_tag: true,
auto_tag_suffix: arch,
dockerfile: "Dockerfile",
repo: "xoxys/molecule",
username: { from_secret: "docker_username" },
password: { from_secret: "docker_password" },
}, },
when: { when: {
ref: [ ref: [
"refs/heads/master", 'refs/pull/**',
"refs/tags/**",
], ],
}, },
}, },
{
name: 'publish',
image: 'plugins/docker:18-linux-' + arch,
settings: {
auto_tag: true,
auto_tag_suffix: arch,
dockerfile: 'Dockerfile.' + arch,
repo: 'xoxys/molecule',
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
},
when: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
},
},
{
name: 'publish-gitea',
image: 'plugins/gitea-release',
pull: 'always',
settings: {
api_key: { from_secret: 'gitea_token' },
base_url: 'https://gitea.rknet.org',
overwrite: true,
title: '${DRONE_TAG}',
note: 'CHANGELOG.md',
},
when: {
ref: ['refs/tags/**'],
},
},
], ],
}; };
local PipelineNotifications(depends_on=[]) = { local PipelineNotifications(depends_on=[]) = {
kind: "pipeline", kind: 'pipeline',
name: "notifications", name: 'notifications',
platform: { platform: {
os: "linux", os: 'linux',
arch: "amd64", arch: 'amd64',
}, },
steps: [ steps: [
{ {
image: "plugins/manifest", image: 'plugins/manifest',
name: "manifest", name: 'manifest',
pull: "always",
settings: { settings: {
ignore_missing: true, ignore_missing: true,
username: { from_secret: "docker_username" }, tags: [
password: { from_secret: "docker_password" }, '${DRONE_TAG}',
spec: "manifest.tmpl", '${DRONE_TAG%-*}',
}, '${DRONE_TAG%.*}',
when: { '${DRONE_TAG%%.*}',
ref: [
"refs/heads/master",
"refs/tags/**",
], ],
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
spec: 'manifest.tmpl',
}, },
}, },
{ {
name: "readme", name: 'readme',
image: "sheogorath/readme-to-dockerhub", image: 'sheogorath/readme-to-dockerhub',
pull: "always",
environment: { environment: {
DOCKERHUB_USERNAME: { from_secret: "docker_username" }, DOCKERHUB_USERNAME: { from_secret: 'docker_username' },
DOCKERHUB_PASSWORD: { from_secret: "docker_password" }, DOCKERHUB_PASSWORD: { from_secret: 'docker_password' },
DOCKERHUB_REPO_PREFIX: "xoxys", DOCKERHUB_REPO_PREFIX: 'xoxys',
DOCKERHUB_REPO_NAME: "molecule", DOCKERHUB_REPO_NAME: 'molecule',
README_PATH: "README.md", README_PATH: 'README.md',
SHORT_DESCRIPTION: "Molecule - Automated Ansible roles testing" SHORT_DESCRIPTION: 'Molecule - Automated Ansible roles testing',
}, },
when: { when: {
ref: [ status: [
"refs/heads/master", 'success',
"refs/tags/**",
], ],
}, },
}, },
{ {
name: "microbadger", name: 'matrix',
image: "plugins/webhook", image: 'plugins/matrix',
pull: "always",
settings: { settings: {
urls: { from_secret: "microbadger_url" }, template: 'Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}',
}, roomid: { from_secret: 'matrix_roomid' },
when: { homeserver: { from_secret: 'matrix_homeserver' },
ref: [ username: { from_secret: 'matrix_username' },
"refs/heads/master", password: { from_secret: 'matrix_password' },
"refs/tags/**",
],
},
},
{
name: "matrix",
image: "plugins/matrix",
pull: "always",
settings: {
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}",
roomid: { "from_secret": "matrix_roomid" },
homeserver: { "from_secret": "matrix_homeserver" },
username: { from_secret: "matrix_username" },
password: { from_secret: "matrix_password" },
},
when: {
status: [ "success", "failure" ],
ref: [
"refs/heads/master",
"refs/tags/**",
],
}, },
}, },
], ],
depends_on: depends_on, depends_on: depends_on,
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
status: [
'success',
'failure',
],
},
}; };
[ [
PipelineBuild(arch="amd64"), PipelineBuild(arch='amd64'),
PipelineNotifications(depends_on=[ PipelineNotifications(depends_on=[
"build-amd64", 'build-amd64',
]) ]),
] ]

View File

@ -8,24 +8,25 @@ platform:
steps: steps:
- name: dryrun - name: dryrun
pull: always
image: plugins/docker:18-linux-amd64 image: plugins/docker:18-linux-amd64
settings: settings:
dockerfile: Dockerfile dockerfile: Dockerfile.amd64
dry_run: true dry_run: true
password: password:
from_secret: docker_password from_secret: docker_password
repo: xoxys/molecule repo: xoxys/molecule
username: username:
from_secret: docker_username from_secret: docker_username
when:
ref:
- refs/pull/**
- name: publish - name: publish
pull: always
image: plugins/docker:18-linux-amd64 image: plugins/docker:18-linux-amd64
settings: settings:
auto_tag: true auto_tag: true
auto_tag_suffix: amd64 auto_tag_suffix: amd64
dockerfile: Dockerfile dockerfile: Dockerfile.amd64
password: password:
from_secret: docker_password from_secret: docker_password
repo: xoxys/molecule repo: xoxys/molecule
@ -36,6 +37,20 @@ steps:
- refs/heads/master - refs/heads/master
- refs/tags/** - refs/tags/**
- name: publish-gitea
pull: always
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://gitea.rknet.org
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
--- ---
kind: pipeline kind: pipeline
name: notifications name: notifications
@ -46,22 +61,21 @@ platform:
steps: steps:
- name: manifest - name: manifest
pull: always
image: plugins/manifest image: plugins/manifest
settings: settings:
ignore_missing: true ignore_missing: true
password: password:
from_secret: docker_password from_secret: docker_password
spec: manifest.tmpl spec: manifest.tmpl
tags:
- ${DRONE_TAG}
- ${DRONE_TAG%-*}
- ${DRONE_TAG%.*}
- ${DRONE_TAG%%.*}
username: username:
from_secret: docker_username from_secret: docker_username
when:
ref:
- refs/heads/master
- refs/tags/**
- name: readme - name: readme
pull: always
image: sheogorath/readme-to-dockerhub image: sheogorath/readme-to-dockerhub
environment: environment:
DOCKERHUB_PASSWORD: DOCKERHUB_PASSWORD:
@ -73,23 +87,10 @@ steps:
README_PATH: README.md README_PATH: README.md
SHORT_DESCRIPTION: Molecule - Automated Ansible roles testing SHORT_DESCRIPTION: Molecule - Automated Ansible roles testing
when: when:
ref: status:
- refs/heads/master - success
- refs/tags/**
- name: microbadger
pull: always
image: plugins/webhook
settings:
urls:
from_secret: microbadger_url
when:
ref:
- refs/heads/master
- refs/tags/**
- name: matrix - name: matrix
pull: always
image: plugins/matrix image: plugins/matrix
settings: settings:
homeserver: homeserver:
@ -101,19 +102,20 @@ steps:
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}" template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
username: username:
from_secret: matrix_username from_secret: matrix_username
when:
ref: trigger:
- refs/heads/master ref:
- refs/tags/** - refs/heads/master
status: - refs/tags/**
- success status:
- failure - success
- failure
depends_on: depends_on:
- build-amd64 - build-amd64
--- ---
kind: signature kind: signature
hmac: 63cc04ce09b24f38ae1b5eb3664f6585f52a434cb2e2520abd9e4208b9f49ee3 hmac: 569724d921f5f116f046c6a23305a82ea62621cd41f442372d577b7e1023988f
... ...

1
CHANGELOG.md Normal file
View File

@ -0,0 +1 @@
* Inital release

View File

@ -6,19 +6,33 @@ LABEL maintainer="Robert Kaussow <mail@geeklabor.de>" \
org.label-schema.vendor="Robert Kaussow" \ org.label-schema.vendor="Robert Kaussow" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"
ENV PY_COLORS=1 ARG ANSIBLE_VERSION=2.9.0
ENV USER=root ARG MOLECULE_VERSION=latest
ENV PATH=/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
ENV PY_COLORS=1 \
USER=root \
PATH=/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
COPY overlay/ / COPY overlay/ /
RUN \ RUN apk add --update --no-cache --virtual .build-deps gcc make libffi-dev musl-dev \
apk add --update --no-cache --virtual .build-deps gcc make libffi-dev musl-dev \ openssl-dev python3-dev && \
openssl-dev python-dev && \
apk add --update --no-cache git openssh-client && \ apk add --update --no-cache git openssh-client && \
pip install --upgrade --no-cache-dir pip setuptools && \ # Required to fix hcloud dependency:
pip install --no-cache-dir ansible~=2.9.0 pycrypto boto boto3 botocore hcloud \ # hcloud 1.6.3 has requirement requests<2.23,>=2.20, but you'll have requests 2.23.0
apache-libcloud molecule && \ echo "Installing ansible 'v$ANSIBLE_VERSION' ..." && \
pip install -qq --upgrade --no-cache-dir pip setuptools requests~=2.22.0 && \
pip install -qq --no-cache-dir ansible~="$ANSIBLE_VERSION" && \
echo "Installing requirements ..." && \
MOLECULE_MAJOR="${MOLECULE_VERSION%%.*}" && \
pip install -qq --no-cache-dir -r /root/requirements.txt && \
if [ -z "${MOLECULE_MAJOR//[0-9]}" ] && [ -n "$MOLECULE_MAJOR" ]; then \
echo "Installing molecule 'v$MOLECULE_VERSION' ..." && \
pip install -qq --no-cache-dir molecule~="$MOLECULE_VERSION"; \
else \
echo "Installing latest molecule ..." && \
pip install -qq --no-cache-dir molecule; \
fi && \
apk del .build-deps && \ apk del .build-deps && \
rm -rf /var/cache/apk/* && \ rm -rf /var/cache/apk/* && \
rm -rf /tmp/* && \ rm -rf /tmp/* && \

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) <year> <copyright holders> Copyright (c) 2020 Robert Kaussow <mail@geeklabor.de>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,14 +1,26 @@
# molecule # [molecule](https://gitea.rknet.org/docker/molecule)
[![Build Status](https://drone.rknet.org/api/badges/docker/molecule/status.svg)](https://drone.rknet.org/docker/molecule/) [![Build Status](https://img.shields.io/drone/build/docker/molecule?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/docker/molecule)
[![](https://images.microbadger.com/badges/image/xoxys/molecule.svg)](https://microbadger.com/images/xoxys/molecule "Get your own image badge on microbadger.com") [![Docker Hub](https://img.shields.io/badge/docker-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/xoxys/molecule)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
Docker image to automate Ansible deployment tests with Molecule. The image was build to use with any docker based CI system. Docker image to automate Ansible deployment tests with Molecule. The image was build to use with any docker based CI system.
## Environment variables ## Environment variables
`MOLECULE_CUSTOM_MODULES_REPO` ```Shell
If you use custom modules you can specify a git repo containing these files. The repo will be cloned so ansible can use it. # If you use custom modules you can specify a git repo containing these files.
# The repo will be cloned so ansible can use it.
MOLECULE_CUSTOM_MODULES_REPO=
`MOLECULE_CUSTOM_FILTERS_REPO` # If you have custom filters you can specify a git repo containing these files.
If you have custom filters you can specify a git repo containing these files. MOLECULE_CUSTOM_FILTERS_REPO=
```
### License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
### Maintainers and Contributors
[Robert Kaussow](https://gitea.rknet.org/xoxys)

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env sh
set -eo pipefail set -eo pipefail
DIR=$(pwd) DIR=$(pwd)

View File

@ -0,0 +1,15 @@
# linter
testinfra
flake8
yamllint
ansible-lint
# cloud provider deps
boto
boto3
botocore
apache-libcloud
hcloud
# misc
pycrypto