From 41b0ec1b5c0349ec93b3b5bc41cb80c8659f2904 Mon Sep 17 00:00:00 2001 From: Giles Bradshaw Date: Fri, 28 Aug 2020 21:55:29 +0100 Subject: [PATCH] ci: jsonnet-drone@0.1.0 --- .drone-home.star | 14 --- .drone/build.sh | 1 + .drone/deploy.sh | 4 + .drone/drone-home.jsonnet | 30 ++++++ .drone/drone-home.yml | 143 ++++++++++++++++++++++++++++ .drone/lib/public-secrets.libsonnet | 1 + .drone/lib/secret-secrets.libsonnet | 4 + .drone/login.sh | 1 + .drone/logout.sh | 1 + .drone/package.json | 9 ++ .drone/pull.sh | 1 + .drone/push.sh | 1 + .drone/yarn.lock | 21 ++++ .gitignore | 2 + .versionrc | 3 + CHANGELOG.md | 5 + README.md | 5 +- docker-compose.yml | 14 +-- git-hooks/pre-commit | 3 + package.json | 19 ++++ 20 files changed, 258 insertions(+), 24 deletions(-) delete mode 100644 .drone-home.star create mode 100644 .drone/build.sh create mode 100644 .drone/deploy.sh create mode 100644 .drone/drone-home.jsonnet create mode 100644 .drone/drone-home.yml create mode 100644 .drone/lib/public-secrets.libsonnet create mode 100644 .drone/lib/secret-secrets.libsonnet create mode 100644 .drone/login.sh create mode 100644 .drone/logout.sh create mode 100644 .drone/package.json create mode 100644 .drone/pull.sh create mode 100644 .drone/push.sh create mode 100644 .drone/yarn.lock create mode 100644 .gitignore create mode 100644 .versionrc create mode 100644 CHANGELOG.md create mode 100755 git-hooks/pre-commit create mode 100644 package.json diff --git a/.drone-home.star b/.drone-home.star deleted file mode 100644 index d3c5053..0000000 --- a/.drone-home.star +++ /dev/null @@ -1,14 +0,0 @@ - -load("@this//matomo:drone.star", "drone") -load("@this//matomo:stack-name.star", "stackName") -load("@this//matomo:stack-root.star", "stackRoot") - -def main(ctx): - return drone( - ctx, - "home-deploy", - stackRoot, - stackName, - [] - ) - \ No newline at end of file diff --git a/.drone/build.sh b/.drone/build.sh new file mode 100644 index 0000000..e41d3f1 --- /dev/null +++ b/.drone/build.sh @@ -0,0 +1 @@ +echo 'nothing to build' diff --git a/.drone/deploy.sh b/.drone/deploy.sh new file mode 100644 index 0000000..ad868c3 --- /dev/null +++ b/.drone/deploy.sh @@ -0,0 +1,4 @@ +docker stack rm matomo +echo 'sleeping...60' +sleep 60 +docker stack deploy -c docker-compose.yml matomo diff --git a/.drone/drone-home.jsonnet b/.drone/drone-home.jsonnet new file mode 100644 index 0000000..20059c3 --- /dev/null +++ b/.drone/drone-home.jsonnet @@ -0,0 +1,30 @@ + +local secretSecrets = import 'lib/secret-secrets.libsonnet'; +local publicSecrets = import 'lib/public-secrets.libsonnet'; + +local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet'; +local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet'; +[ + register, + deploy( + 'matomo', + '/stack/', + [], + publicSecrets, + secretSecrets, + [ + 'REGISTRY_DOMAIN', + 'REGISTRY_PORT', + 'REGISTRY_PASSWORD', + ], + ) { + trigger +: { + event +: [ + 'promote', + ], + target +: [ + 'production', + ], + }, + }, +] diff --git a/.drone/drone-home.yml b/.drone/drone-home.yml new file mode 100644 index 0000000..3c73e6a --- /dev/null +++ b/.drone/drone-home.yml @@ -0,0 +1,143 @@ +--- +kind: pipeline +type: docker +name: register + +platform: + os: linux + arch: amd64 + +clone: + disable: true + +trigger: + event: + exclude: + - promote + +--- +kind: pipeline +type: docker +name: deploy + +platform: + os: linux + arch: amd64 + +steps: +- name: print env + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + - mysql_root_password + - mysql_password + host: ${SSH_HOST} + key: ${SSH_KEY} + passphrase: ${SSH_PASSPHRASE} + port: ${SSH_PORT} + script: + - rm -f env-matomo + - "echo \"export MYSQL_ROOT_PASSWORD='$${MYSQL_ROOT_PASSWORD}'\" >> env-matomo # \"mysql-root-password\"" + - "echo \"export MYSQL_PASSWORD='$${MYSQL_PASSWORD}'\" >> env-matomo # \"mysql-password\"" + username: ${SSH_USER} + environment: + MYSQL_PASSWORD: + from_secret: mysql-password + MYSQL_ROOT_PASSWORD: + from_secret: mysql-root-password + +- name: scp + image: appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47 + settings: + command_timeout: 2m + host: ${SSH_HOST} + key: ${SSH_KEY} + passphrase: ${SSH_PASSPHRASE} + port: ${SSH_PORT} + source: + - . + target: /stack/matomo + username: ${SSH_USER} + +- name: wait + image: alpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1 + commands: + - sleep 15 + +- name: "dockerbuild:" + image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f + commands: + - set -e + - sh .drone/login.sh + - sh .drone/build.sh + - sh .drone/push.sh + - sh .drone/logout.sh + volumes: + - name: dockersock + path: /var/run + +- name: deploy + image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea + settings: + envs: + - drone_tag + - drone_commit + - drone_build_number + - drone_repo_name + - drone_repo_namespace + - registry_domain + - registry_port + - registry_password + - mysql_root_password + - mysql_password + host: ${SSH_HOST} + key: ${SSH_KEY} + passphrase: ${SSH_PASSPHRASE} + port: ${SSH_PORT} + script: + - export MYSQL_ROOT_PASSWORD=$${MYSQL_ROOT_PASSWORD} + - export MYSQL_PASSWORD=$${MYSQL_PASSWORD} + - export REGISTRY_DOMAIN=$${REGISTRY_DOMAIN} + - export REGISTRY_PORT=$${REGISTRY_PORT} + - export REGISTRY_PASSWORD=$${REGISTRY_PASSWORD} + - set -e + - cd /stack/matomo + - sh .drone/login.sh + - sh .drone/pull.sh + - sh .drone/deploy.sh + username: ${SSH_USER} + environment: + MYSQL_PASSWORD: + from_secret: mysql-password + MYSQL_ROOT_PASSWORD: + from_secret: mysql-root-password + +services: +- name: docker + image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f + privileged: true + volumes: + - name: dockersock + path: /var/run + - name: ca + path: /etc/docker/certs.d + +volumes: +- name: dockersock + temp: {} +- name: ca + host: + path: /etc/docker/certs.d + +trigger: + event: + - promote + target: + - production + +... diff --git a/.drone/lib/public-secrets.libsonnet b/.drone/lib/public-secrets.libsonnet new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/.drone/lib/public-secrets.libsonnet @@ -0,0 +1 @@ +[] diff --git a/.drone/lib/secret-secrets.libsonnet b/.drone/lib/secret-secrets.libsonnet new file mode 100644 index 0000000..df5fc42 --- /dev/null +++ b/.drone/lib/secret-secrets.libsonnet @@ -0,0 +1,4 @@ +[ + 'mysql-root-password', + 'mysql-password', +] diff --git a/.drone/login.sh b/.drone/login.sh new file mode 100644 index 0000000..982ed2d --- /dev/null +++ b/.drone/login.sh @@ -0,0 +1 @@ +docker login ${REGISTRY_DOMAIN}:${REGISTRY_PORT} --username client --password "${REGISTRY_PASSWORD}" \ No newline at end of file diff --git a/.drone/logout.sh b/.drone/logout.sh new file mode 100644 index 0000000..2337c7c --- /dev/null +++ b/.drone/logout.sh @@ -0,0 +1 @@ +docker logout ${REGISTRY_DOMAIN}:${REGISTRY_PORT} \ No newline at end of file diff --git a/.drone/package.json b/.drone/package.json new file mode 100644 index 0000000..22cfdd2 --- /dev/null +++ b/.drone/package.json @@ -0,0 +1,9 @@ +{ + "private": true, + "scripts": { + "build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream" + }, + "dependencies": { + "@sigyl/jsonnet-drone": "^0.1.0" + } +} diff --git a/.drone/pull.sh b/.drone/pull.sh new file mode 100644 index 0000000..a3c2118 --- /dev/null +++ b/.drone/pull.sh @@ -0,0 +1 @@ +echo 'nothing to pull' diff --git a/.drone/push.sh b/.drone/push.sh new file mode 100644 index 0000000..8aa5b36 --- /dev/null +++ b/.drone/push.sh @@ -0,0 +1 @@ +echo 'nothing to push' diff --git a/.drone/yarn.lock b/.drone/yarn.lock new file mode 100644 index 0000000..44ab354 --- /dev/null +++ b/.drone/yarn.lock @@ -0,0 +1,21 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@sigyl/jsonnet-compose@^0.0.2": + version "0.0.2" + resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-compose/-/jsonnet-compose-0.0.2.tgz#8900a21e8cd8109929b6042703f8645aacb9bcda" + integrity sha512-wWS3CgPeNi/o1pcS6n/4pafxlMD0KC9/RKMZr/ySmzeGNRW++sPuKuxajYse2TNd47uNDdeUSnk4aEeEIKL0zA== + +"@sigyl/jsonnet-drone-environment@0.0.5": + version "0.0.5" + resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff" + integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw== + +"@sigyl/jsonnet-drone@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.1.0.tgz#feda1797e8e9ef799cad72e65f7163ca26a9e3a5" + integrity sha512-QY/ngucxFOtLfL8Mt0f2bxN4fQDUOGOFtaRpSH2cNyg84xADkzehT0ORZtbLitr+AwhyF5KN/zAGvzkyNAoqPw== + dependencies: + "@sigyl/jsonnet-compose" "^0.0.2" + "@sigyl/jsonnet-drone-environment" "0.0.5" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb03e3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.log diff --git a/.versionrc b/.versionrc new file mode 100644 index 0000000..37b4bcc --- /dev/null +++ b/.versionrc @@ -0,0 +1,3 @@ +{ + "tagMessageInChangeLog": true +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f4d352e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +### 0.0.1 "chore(release): 0.0.1" (2020-08-19) diff --git a/README.md b/README.md index 49eea49..7393619 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # matomo ## secrets -* matomo-mysql-password -* matomo-mysql-root-password -* registry-password +* mysql-password +* mysql-root-password diff --git a/docker-compose.yml b/docker-compose.yml index be239b5..8fe6b87 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.7" services: matomo: - image: matomo:fpm-alpine + image: matomo:3.14.0-fpm-alpine@sha256:850d3787a2ba475a1f3dd8f19e3b14fcc039543c885966a2bb00879b5d9359ff deploy: placement: constraints: [node.labels.com.sigyl.git-stack == yes] @@ -14,18 +14,18 @@ services: - matomo:/var/www/html environment: - MATOMO_DATABASE_HOST=matomo-mariadb - - MYSQL_PASSWORD=${MATOMO_MYSQL_PASSWORD} + - MYSQL_PASSWORD=${MYSQL_PASSWORD} - MYSQL_DATABASE=matomo - MYSQL_USER=matomo - MATOMO_DATABASE_ADAPTER=mysql - MATOMO_DATABASE_TABLES_PREFIX=matomo_ - MATOMO_DATABASE_USERNAME=matomo - - MATOMO_DATABASE_PASSWORD=${MATOMO_MYSQL_PASSWORD} + - MATOMO_DATABASE_PASSWORD=${MYSQL_PASSWORD} - MATOMO_DATABASE_DBNAME=matomo networks: - appnet matomo-web: - image: nginx:alpine + image: nginx:1.19.2-alpine@sha256:4635b632d2aaf8c37c8a1cf76a1f96d11b899f74caa2c6946ea56d0a5af02c0c deploy: placement: constraints: [node.labels.com.sigyl.git-stack == yes] @@ -46,17 +46,17 @@ services: replicas: 1 restart_policy: condition: any - image: mariadb:10 + image: mariadb:10.5.5@sha256:589c4347e21c2dd4292d8929091faf6d78e80acdcca6cb04aa0a1337f22765f1 command: --max-allowed-packet=128MB networks: - appnet volumes: - matomo-mariadb:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD: ${MATOMO_MYSQL_ROOT_PASSWORD} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_USER: matomo MYSQL_DATABASE: matomo - MYSQL_PASSWORD: ${MATOMO_MYSQL_PASSWORD} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} volumes: matomo: matomo-mariadb: diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit new file mode 100755 index 0000000..7161ae2 --- /dev/null +++ b/git-hooks/pre-commit @@ -0,0 +1,3 @@ +drone jsonnet --source .drone/drone-home.jsonnet --target .drone/drone-home.yml --stream \ +&& git add .drone/drone-home.yml \ +&& echo "jsonnet built" \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..c68754b --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "private": true, + "name": "matomo", + "version": "0.0.1", + "description": "analytics", + "scripts": { + "release": "standard-version", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://sigyl.com/git/stack/matomo" + }, + "author": "Giles Bradshaw", + "license": "ISC", + "devDependencies": { + "standard-version": "git+https://github.com/gilesbradshaw/standard-version.git" + } +}