From 22571374e212e4d2977aa98801ef483bbb83be27 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 18 Mar 2019 14:45:18 +0100 Subject: [PATCH] refactoring --- .drone.jsonnet | 100 ++++++++++++ .drone.yml | 145 +++++++++++------- README.md | 12 ++ docker-entrypoint.sh | 4 + ...kerfile.gce => Dockerfile.gce.linux.amd64} | 8 +- docker/manifest.tmpl | 7 + 6 files changed, 218 insertions(+), 58 deletions(-) create mode 100644 .drone.jsonnet rename docker/{Dockerfile.gce => Dockerfile.gce.linux.amd64} (71%) create mode 100644 docker/manifest.tmpl diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..6cdb584 --- /dev/null +++ b/.drone.jsonnet @@ -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 }}**
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" }, + }, + when: { + status: [ "success", "failure" ], + }, + }, + ], + trigger: { + status: [ "success", "failure" ], + }, + depends_on: depends_on, +}; + +[ + PipelineBuild(os='linux', arch='amd64', version='gce'), + PipelineNotifications(depends_on=[ + "linux-amd64" + ]) +] diff --git a/.drone.yml b/.drone.yml index 01a8483..84cc826 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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 - settings: - dry_run: true - password: - from_secret: docker_password - repo: xoxys/molecule - dockerfile: docker/Dockerfile.gce - tags: gce - username: - from_secret: docker_username - when: - event: - - push - - tag - - - name: publish - pull: always - image: plugins/docker:linux-amd64 - settings: - auto_tag: true - auto_tag_suffix: gce - dockerfile: docker/Dockerfile.gce - password: - from_secret: docker_password - repo: xoxys/molecule - username: - from_secret: docker_username - when: - event: - - push - - tag - -# --- -# kind: pipeline -# name: notifications - -# steps: -# - name: notify -# 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 -# when: -# status: -# - success -# - failure - -# ... +- name: dryrun + pull: always + image: plugins/docker:gce-linux-amd64 + settings: + dockerfile: docker/Dockerfile.gce.linux.amd64 + dry_run: true + password: + from_secret: docker_password + repo: xoxys/molecule + tags: gce-linux-amd64 + username: + from_secret: docker_username + +- name: publish + pull: always + image: plugins/docker:gce-linux-amd64 + settings: + auto_tag: true + 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: + branch: + - master + +--- +kind: pipeline +name: notifications + +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 }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}" + username: + from_secret: matrix_username + when: + status: + - success + - failure + +trigger: + status: + - success + - failure + +depends_on: +- linux-amd64 + +... diff --git a/README.md b/README.md index 67de163..e7b0936 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4c26f15..ce413c8 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -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 diff --git a/docker/Dockerfile.gce b/docker/Dockerfile.gce.linux.amd64 similarity index 71% rename from docker/Dockerfile.gce rename to docker/Dockerfile.gce.linux.amd64 index bffe351..faed80b 100644 --- a/docker/Dockerfile.gce +++ b/docker/Dockerfile.gce.linux.amd64 @@ -1,5 +1,10 @@ FROM python:3.7-alpine -LABEL maintainer "Robert Kaussow " + +LABEL maintainer="Robert Kaussow " \ + 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"] diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl new file mode 100644 index 0000000..cb90bdb --- /dev/null +++ b/docker/manifest.tmpl @@ -0,0 +1,7 @@ +image: xoxys/molecule:latest +manifests: + - + image: xoxys/molecule:gce-linux-amd64 + platform: + architecture: amd64 + os: linux