feat: promotions print, registry, build, save, deploy
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Giles Bradshaw 2020-10-23 09:51:18 +01:00
parent 36e4f27928
commit e608b707fc
9 changed files with 252 additions and 100 deletions

View File

@ -5,31 +5,55 @@ local publicSecrets = import 'lib/public-secrets.libsonnet';
local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet'; local deploy = import 'node_modules/@sigyl/jsonnet-drone/deploy.libsonnet';
local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet'; local register = import 'node_modules/@sigyl/jsonnet-drone/register.libsonnet';
local registry = import 'node_modules/@sigyl/jsonnet-drone/registry.libsonnet'; local registry = import 'node_modules/@sigyl/jsonnet-drone/registry.libsonnet';
local save = import 'node_modules/@sigyl/jsonnet-drone/save.libsonnet';
local build = import 'node_modules/@sigyl/jsonnet-drone/build.libsonnet';
local print = import 'node_modules/@sigyl/jsonnet-drone/print.libsonnet';
local config = { local config = {
registry: '', registry: '',
name: 'ghost',
root: 'stack'
}; };
local defs = [
{
load: 'alpine/git:v2.26.2@sha256:8715680f27333935bb384a678256faf8e8832a5f2a0d4a00c9d481111c5a29c0',
save: 'alpine/git:v2.26.2'
},
{
load: 'ghost:3.14.0@sha256:38fb60af996dca89632e848c32e8c155d6dd20578c129752bd5449f99028fa92',
save: 'ghost:3.14.0'
},
{
load: 'mysql:5.7@sha256:ce6815027949d0b48e3097a94fa3ec062866a78868d50c7900c697c13574599f',
save: 'mysql:5.7'
},
];
[ [
register, register,
registry( registry(
config { config {
script: 'sh .drone/scripts/initialise-images.sh', script: 'sh .drone/scripts/initialise-images.sh',
secrets: [], secrets: [],
images: defs,
}, },
) { ),
trigger +: { save(config)(
event +: [ defs,
'promote', [
], 'my-ghost',
target +: [ ],
'registry', ),
], print(config)(
}, [],
}, publicSecrets,
secretSecrets,
),
build(config)(
['THEME'],
),
deploy(config)( deploy(config)(
'ghost',
'/stack/',
[ [
'THEME', 'THEME',
], ],

View File

@ -24,13 +24,36 @@ platform:
os: linux os: linux
arch: amd64 arch: amd64
clone:
disable: true
steps: steps:
- name: "dockerpull and save docker images:" - name: alpine/git:v2.26.2
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
commands: commands:
- set -e - set -e
- export REGISTRY=$${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- sh .drone/scripts/initialise-images.sh $${REGISTRY} "$${REGISTRY_PASSWORD}" - "n=0\nwhile :\ndo\n docker pull alpine/git:v2.26.2@sha256:8715680f27333935bb384a678256faf8e8832a5f2a0d4a00c9d481111c5a29c0 \\\\\n && docker tag alpine/git:v2.26.2@sha256:8715680f27333935bb384a678256faf8e8832a5f2a0d4a00c9d481111c5a29c0 $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/alpine/git:v2.26.2 \\\\\n && docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/alpine/git:v2.26.2 && break\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"initialise failed\"\n exit 1\n fi\n echo \"retrying..$n\"\n sleep 5\ndone\n"
volumes:
- name: dockersock
path: /var/run
- name: ghost:3.14.0
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
commands:
- set -e
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- "n=0\nwhile :\ndo\n docker pull ghost:3.14.0@sha256:38fb60af996dca89632e848c32e8c155d6dd20578c129752bd5449f99028fa92 \\\\\n && docker tag ghost:3.14.0@sha256:38fb60af996dca89632e848c32e8c155d6dd20578c129752bd5449f99028fa92 $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/ghost:3.14.0 \\\\\n && docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/ghost:3.14.0 && break\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"initialise failed\"\n exit 1\n fi\n echo \"retrying..$n\"\n sleep 5\ndone\n"
volumes:
- name: dockersock
path: /var/run
- name: mysql:5.7
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
commands:
- set -e
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- "n=0\nwhile :\ndo\n docker pull mysql:5.7@sha256:ce6815027949d0b48e3097a94fa3ec062866a78868d50c7900c697c13574599f \\\\\n && docker tag mysql:5.7@sha256:ce6815027949d0b48e3097a94fa3ec062866a78868d50c7900c697c13574599f $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/mysql:5.7 \\\\\n && docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/mysql:5.7 && break\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"initialise failed\"\n exit 1\n fi\n echo \"retrying..$n\"\n sleep 5\ndone\n"
volumes: volumes:
- name: dockersock - name: dockersock
path: /var/run path: /var/run
@ -69,7 +92,116 @@ trigger:
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: deploy name: save
platform:
os: linux
arch: amd64
clone:
disable: true
steps:
- name: mkdir
image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea
settings:
envs:
- drone_tag
- drone_commit
- drone_build_number
- drone_repo_name
- drone_repo_namespace
script:
- mkdir -p /stack/.images/ghost/built
- rm -f /stack/.images/ghost/*.*
- rm -f /stack/.images/ghost/built/*.*
- name: alpine/git:v2.26.2
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
script:
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/alpine/git:v2.26.2
- docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/alpine/git:v2.26.2 -o /stack/.images/ghost/alpine_git:v2.26.2.tar
- echo "docker load alpine_git:v2.26.2.tar" >> /stack/.images/ghost/load.sh
- echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/alpine/git:v2.26.2 /stack/DOLLAR1/alpine/git:v2.26.2" >> /stack/.images/ghost/load.sh
- name: ghost:3.14.0
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
script:
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/ghost:3.14.0
- docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/ghost:3.14.0 -o /stack/.images/ghost/ghost:3.14.0.tar
- echo "docker load ghost:3.14.0.tar" >> /stack/.images/ghost/load.sh
- echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/ghost:3.14.0 /stack/DOLLAR1/ghost:3.14.0" >> /stack/.images/ghost/load.sh
- name: mysql:5.7
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
script:
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/mysql:5.7
- docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/mysql:5.7 -o /stack/.images/ghost/mysql:5.7.tar
- echo "docker load mysql:5.7.tar" >> /stack/.images/ghost/load.sh
- echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/mysql:5.7 /stack/DOLLAR1/mysql:5.7" >> /stack/.images/ghost/load.sh
- name: my-ghost
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
script:
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/my-ghost
- docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/my-ghost -o /stack/.images/ghost/built/my-ghost.tar
- echo "docker load my-ghost.tar" >> /stack/.images/ghost/built/load.sh
- echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/stack/ghost/my-ghost /stack/DOLLAR1/my-ghost" >> /stack/.images/ghost/built/load.sh
trigger:
event:
- promote
target:
- save
---
kind: pipeline
type: docker
name: print
platform: platform:
os: linux os: linux
@ -85,7 +217,6 @@ steps:
- drone_build_number - drone_build_number
- drone_repo_name - drone_repo_name
- drone_repo_namespace - drone_repo_namespace
- theme
- mail_service - mail_service
- mail_user - mail_user
- commento_origin - commento_origin
@ -93,7 +224,6 @@ steps:
- mysql_root_password - mysql_root_password
script: script:
- rm -f env-ghost - rm -f env-ghost
- "echo \"export THEME='$${THEME}'\" >> env-ghost # \"theme\""
- "echo \"export MAIL_SERVICE='$${MAIL_SERVICE}'\" >> env-ghost # \"mail-service\"" - "echo \"export MAIL_SERVICE='$${MAIL_SERVICE}'\" >> env-ghost # \"mail-service\""
- "echo \"export MAIL_USER='$${MAIL_USER}'\" >> env-ghost # \"mail-user\"" - "echo \"export MAIL_USER='$${MAIL_USER}'\" >> env-ghost # \"mail-user\""
- "echo \"export COMMENTO_ORIGIN='$${COMMENTO_ORIGIN}'\" >> env-ghost # \"commento-origin\"" - "echo \"export COMMENTO_ORIGIN='$${COMMENTO_ORIGIN}'\" >> env-ghost # \"commento-origin\""
@ -111,6 +241,76 @@ steps:
THEME: THEME:
from_secret: theme from_secret: theme
trigger:
event:
- promote
target:
- print
---
kind: pipeline
type: docker
name: build
platform:
os: linux
arch: amd64
steps:
- name: "dockerbuild:"
image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f
commands:
- set -e
- export NAME=ghost
- export ROOT=stack
- "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- sh .drone/build.sh
- sh .drone/push.sh
environment:
THEME:
from_secret: theme
volumes:
- name: dockersock
path: /var/run
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
- name: daemonjson
path: /etc/docker/daemon.json
volumes:
- name: dockersock
temp: {}
- name: ca
host:
path: /etc/docker/certs.d
- name: daemonjson
host:
path: /etc/docker/daemon.json
trigger:
event:
- promote
target:
- build
---
kind: pipeline
type: docker
name: deploy
platform:
os: linux
arch: amd64
steps:
- name: scp - name: scp
image: appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47 image: appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47
settings: settings:
@ -119,26 +319,6 @@ steps:
- . - .
target: /stack/ghost target: /stack/ghost
- 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
environment:
THEME:
from_secret: theme
volumes:
- name: dockersock
path: /var/run
- name: deploy - name: deploy
image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea image: appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea
settings: settings:
@ -172,8 +352,10 @@ steps:
- export REGISTRY_PORT=$${REGISTRY_PORT} - export REGISTRY_PORT=$${REGISTRY_PORT}
- export REGISTRY_PASSWORD=$${REGISTRY_PASSWORD} - export REGISTRY_PASSWORD=$${REGISTRY_PASSWORD}
- set -e - set -e
- export NAME=ghost
- export ROOT=stack
- cd /stack/ghost - cd /stack/ghost
- sh .drone/login.sh - "n=0\nwhile :\ndo\n docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password \"$${REGISTRY_PASSWORD}\" \\\\\n && break # substitute your command here\n n=$((n+1))\n if [ $n -ge 10 ]; then\n echo \"login failed\"\n exit 1\n fi\n echo \"retrying login..$n\"\n sleep 5\ndone\n"
- sh .drone/pull.sh - sh .drone/pull.sh
- sh .drone/deploy.sh - sh .drone/deploy.sh
environment: environment:
@ -188,32 +370,12 @@ steps:
THEME: THEME:
from_secret: theme from_secret: theme
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
- name: daemonjson
path: /etc/docker/daemon.json
volumes:
- name: dockersock
temp: {}
- name: ca
host:
path: /etc/docker/certs.d
- name: daemonjson
host:
path: /etc/docker/daemon.json
trigger: trigger:
event: event:
- promote - promote
- promote
target: target:
- deploy
- production - production
... ...

View File

@ -1 +0,0 @@
docker login ${REGISTRY_DOMAIN}:${REGISTRY_PORT} --username client --password "${REGISTRY_PASSWORD}"

View File

@ -1 +0,0 @@
docker logout ${REGISTRY_DOMAIN}:${REGISTRY_PORT}

View File

@ -1,6 +1,6 @@
{ {
"private": true, "private": true,
"dependencies": { "dependencies": {
"@sigyl/jsonnet-drone": "^0.4.0" "@sigyl/jsonnet-drone": "^0.4.5"
} }
} }

View File

@ -1,15 +0,0 @@
n=0
while :
do
docker pull $2 \
&& docker tag $2 $1$2 \
&& docker push $1$2 && break # substitute your command here
n=$((n+1))
if [ $n -ge 10 ]; then
echo "initialise failed"
exit 1
fi
echo "retrying..$n"
sleep 5
done

View File

@ -1,4 +0,0 @@
sh $(dirname $0)/login.sh $1 "$2" \
&& sh $(dirname $0)/initialise-image.sh $1 alpine/git:v2.26.2 \
&& sh $(dirname $0)/initialise-image.sh $1 ghost:3.14.0 \
&& sh $(dirname $0)/initialise-image.sh $1 mysql:5.7

View File

@ -1,13 +0,0 @@
n=0
while :
do
docker login $1 --username client --password "$2" \
&& break # substitute your command here
n=$((n+1))
if [ $n -ge 10 ]; then
echo "login failed"
exit 1
fi
echo "retrying login..$n"
sleep 5
done

View File

@ -12,10 +12,10 @@
resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff" resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff"
integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw== integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw==
"@sigyl/jsonnet-drone@^0.4.1": "@sigyl/jsonnet-drone@^0.4.5":
version "0.4.1" version "0.4.5"
resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.4.1.tgz#3527edb00f8bb860de1658f4c9fa6f81f932d3b7" resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.4.5.tgz#deb45b3fa837650d518b651044e993266c7386ac"
integrity sha512-+TOx51KJG1RxrPRZ2lPpia7a6Ms5UvkyLIuXuumPtenyxJ/pivY1TdcLvSAvFgVZHMjh9CxBCuOu8vNT1fPy2A== integrity sha512-s7/QHlT4YydwDPz/puR4iy7rcTl5vqR4YQmqlXCMA7VlcYPT4tC3GOb38njwZfNN4mxNa6oDKaM6eZEJX4SpiQ==
dependencies: dependencies:
"@sigyl/jsonnet-compose" "^0.0.2" "@sigyl/jsonnet-compose" "^0.0.2"
"@sigyl/jsonnet-drone-environment" "0.0.5" "@sigyl/jsonnet-drone-environment" "0.0.5"