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 kind: pipeline
name: gce name: gce-linux-amd64
platform:
os: linux
arch: amd64
steps: steps:
- name: dryrun - name: dryrun
pull: always pull: always
image: plugins/docker:linux-amd64 image: plugins/docker:gce-linux-amd64
settings: settings:
dry_run: true dockerfile: docker/Dockerfile.gce.linux.amd64
password: dry_run: true
from_secret: docker_password password:
repo: xoxys/molecule from_secret: docker_password
dockerfile: docker/Dockerfile.gce repo: xoxys/molecule
tags: gce tags: gce-linux-amd64
username: username:
from_secret: docker_username from_secret: docker_username
when:
event:
- push
- tag
- name: publish - name: publish
pull: always pull: always
image: plugins/docker:linux-amd64 image: plugins/docker:gce-linux-amd64
settings: settings:
auto_tag: true auto_tag: true
auto_tag_suffix: gce auto_tag_suffix: gce-linux-amd64
dockerfile: docker/Dockerfile.gce dockerfile: docker/Dockerfile.gce.linux.amd64
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: when:
event: branch:
- push - master
- tag
# --- ---
# kind: pipeline kind: pipeline
# name: notifications name: notifications
# steps: platform:
# - name: notify os: linux
# image: plugins/matrix arch: amd64
# 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
# ... 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 # 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 #!/usr/bin/env bash
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
if [ "$GCE_SSH_KEY" ]; then if [ "$GCE_SSH_KEY" ]; then
echo "$GCE_SSH_KEY" > $HOME/.ssh/google_compute_engine echo "$GCE_SSH_KEY" > $HOME/.ssh/google_compute_engine

View File

@ -1,5 +1,10 @@
FROM python:3.7-alpine 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="\ ENV PACKAGES="\
gcc \ gcc \
@ -33,5 +38,4 @@ RUN \
&& chmod 700 /root/.ssh && chmod 700 /root/.ssh
USER root USER root
ENV SHELL /bin/bash
ENTRYPOINT ["/docker-entrypoint.sh"] 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