refactoring

This commit is contained in:
Robert Kaussow 2019-03-18 14:45:18 +01:00
parent 60f06ed18b
commit 22571374e2
6 changed files with 214 additions and 54 deletions

100
.drone.jsonnet Normal file
View File

@ -0,0 +1,100 @@
local PipelineBuild(os='linux', arch='amd64', version='gce') = {
local tag = version + '-' + os + '-' + arch,
local file_suffix = std.strReplace(tag, '-', '.'),
kind: "pipeline",
name: tag,
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'dryrun',
image: 'plugins/docker:' + tag,
pull: 'always',
settings: {
dry_run: true,
tags: tag,
dockerfile: 'docker/Dockerfile.' + file_suffix,
repo: ' xoxys/molecule',
username: { from_secret: "docker_username" },
password: { from_secret: "docker_password" },
},
},
{
name: 'publish',
image: 'plugins/docker:' + tag,
pull: 'always',
settings: {
auto_tag: true,
auto_tag_suffix: tag,
dockerfile: 'docker/Dockerfile.' + file_suffix,
repo: ' xoxys/molecule',
username: { from_secret: "docker_username" },
password: { from_secret: "docker_password" },
},
when: {
branch: [ "master" ],
},
},
],
};
local PipelineNotifications(depends_on=[]) = {
kind: "pipeline",
name: "notifications",
platform: {
os: "linux",
arch: "amd64",
},
steps: [
{
image: "plugins/manifest",
name: "manifest",
pull: "always",
settings: {
ignore_missing: true,
username: { from_secret: "docker_username" },
password: { from_secret: "docker_password" },
spec: "docker/manifest.tmpl",
},
when: {
branch: [ "master" ],
},
},
{
name: "microbadger",
image: "plugins/webhook",
pull: "always",
settings: {
urls: { from_secret: "microbadger_url" },
},
},
{
image: "plugins/matrix",
name: "matrix",
pull: 'always',
settings: {
homeserver: "https://matrix.rknet.org",
roomid: "MtidqQXWWAtQcByBhH:rknet.org",
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}",
username: { from_secret: "matrix_username" },
password: { from_secret: "matrix_password" },
},
when: {
status: [ "success", "failure" ],
},
},
],
trigger: {
status: [ "success", "failure" ],
},
depends_on: depends_on,
};
[
PipelineBuild(os='linux', arch='amd64', version='gce'),
PipelineNotifications(depends_on=[
"linux-amd64"
])
]

View File

@ -1,60 +1,93 @@
---
kind: pipeline
name: gce
name: gce-linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
image: plugins/docker:gce-linux-amd64
settings:
dockerfile: docker/Dockerfile.gce.linux.amd64
dry_run: true
password:
from_secret: docker_password
repo: xoxys/molecule
dockerfile: docker/Dockerfile.gce
tags: gce
tags: gce-linux-amd64
username:
from_secret: docker_username
when:
event:
- push
- tag
- name: publish
pull: always
image: plugins/docker:linux-amd64
image: plugins/docker:gce-linux-amd64
settings:
auto_tag: true
auto_tag_suffix: gce
dockerfile: docker/Dockerfile.gce
auto_tag_suffix: gce-linux-amd64
dockerfile: docker/Dockerfile.gce.linux.amd64
password:
from_secret: docker_password
repo: xoxys/molecule
username:
from_secret: docker_username
when:
event:
- push
- tag
branch:
- master
# ---
# kind: pipeline
# name: notifications
---
kind: pipeline
name: notifications
# steps:
# - name: notify
# image: plugins/matrix
# settings:
# homeserver: https://matrix.rknet.org
# roomid: MtidqQXWWAtQcByBhH:rknet.org
# template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
# username:
# from_secret: matrix_username
# password:
# from_secret: matrix_password
# when:
# status:
# - success
# - failure
platform:
os: linux
arch: amd64
# ...
steps:
- name: manifest
pull: always
image: plugins/manifest
settings:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
when:
branch:
- master
- name: microbadger
pull: always
image: plugins/webhook
settings:
urls:
from_secret: microbadger_url
- name: matrix
pull: always
image: plugins/matrix
settings:
homeserver: https://matrix.rknet.org
password:
from_secret: matrix_password
roomid: MtidqQXWWAtQcByBhH:rknet.org
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
username:
from_secret: matrix_username
when:
status:
- success
- failure
trigger:
status:
- success
- failure
depends_on:
- linux-amd64
...

View File

@ -1,2 +1,14 @@
# molecule
[![Build Status](https://drone.rknet.org/api/badges/docker/molecule/status.svg)](https://drone.rknet.org/docker/molecule/)
Docker image to automate Ansible deployment tests with Molecule. The image was build to use in any docker based CI pipeline. Currently only the image is only available for the Google Compute Engine (GCE) backend of Moldecule.
## Environment variables
```Shell
GCE_SSH_KEY: ssh key to authenticate to your GCE project vms
GCE_CREDENTIALS_JSON: json file which holds your credentials to talk to the GCE api (must be generetade and exportet in GCE web console)
GCE_CREDENTIALS_FILE: path to the cretendtials file inside the container to write your $GCE_CREDENTIALS_JSON to
MOLECULE_CUSTOM_MODULES_REPO: if you use custom modules you can specify a git repo containing these files. The repo will be cloned so ansible can use it
```

View File

@ -1,4 +1,8 @@
#!/usr/bin/env bash
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
if [ "$GCE_SSH_KEY" ]; then
echo "$GCE_SSH_KEY" > $HOME/.ssh/google_compute_engine

View File

@ -1,5 +1,10 @@
FROM python:3.7-alpine
LABEL maintainer "Robert Kaussow <mail@geeklabor.de>"
LABEL maintainer="Robert Kaussow <mail@geeklabor.de>" \
org.label-schema.name="molecule" \
org.label-schema.vcs-url="https://gitea.rknet.org/docker/molecule" \
org.label-schema.vendor="Robert Kaussow" \
org.label-schema.schema-version="1.0"
ENV PACKAGES="\
gcc \
@ -33,5 +38,4 @@ RUN \
&& chmod 700 /root/.ssh
USER root
ENV SHELL /bin/bash
ENTRYPOINT ["/docker-entrypoint.sh"]

7
docker/manifest.tmpl Normal file
View File

@ -0,0 +1,7 @@
image: xoxys/molecule:latest
manifests:
-
image: xoxys/molecule:gce-linux-amd64
platform:
architecture: amd64
os: linux