diff --git a/.drone/drone-home.jsonnet b/.drone/drone-home.jsonnet index bcafcff..e7f60a3 100644 --- a/.drone/drone-home.jsonnet +++ b/.drone/drone-home.jsonnet @@ -4,9 +4,28 @@ 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'; +local registry = import 'node_modules/@sigyl/jsonnet-drone/registry.libsonnet'; + +local config = { + registry: '', +}; [ register, - deploy( + registry( + config { + script: 'sh .drone/scripts/initialise-images.sh', + }, + ) { + trigger +: { + event +: [ + 'promote', + ], + target +: [ + 'registry', + ], + }, + }, + deploy(config)( 'drone', '/stack/', [ diff --git a/.drone/drone-home.yml b/.drone/drone-home.yml index 1d6b56b..138e540 100644 --- a/.drone/drone-home.yml +++ b/.drone/drone-home.yml @@ -15,6 +15,59 @@ trigger: exclude: - promote +--- +kind: pipeline +type: docker +name: registry + +platform: + os: linux + arch: amd64 + +steps: +- name: "dockerpull and save docker images:" + image: docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f + commands: + - set -e + - export REGISTRY=$${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ + - sh .drone/scripts/initialise-images.sh $${REGISTRY} $${REGISTRY_PASSWORD} + environment: + REGISTRY_DOMAIN: + from_secret: registry-domain + REGISTRY_PASSWORD: + from_secret: registry-password + REGISTRY_PORT: + from_secret: registry-port + 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 + +volumes: +- name: dockersock + temp: {} +- name: ca + host: + path: /etc/docker/certs.d + +image_pull_secrets: +- dockerconfigjson + +trigger: + event: + - promote + target: + - registry + --- kind: pipeline type: docker diff --git a/.drone/package.json b/.drone/package.json index 33bc5f1..33fb902 100644 --- a/.drone/package.json +++ b/.drone/package.json @@ -4,6 +4,6 @@ "build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream" }, "dependencies": { - "@sigyl/jsonnet-drone": "^0.1.1" + "@sigyl/jsonnet-drone": "^0.3.0" } } diff --git a/.drone/scripts/initialise-image.sh b/.drone/scripts/initialise-image.sh new file mode 100644 index 0000000..08adf61 --- /dev/null +++ b/.drone/scripts/initialise-image.sh @@ -0,0 +1,11 @@ +n=0 +while : +do + docker pull $2 \ + && docker tag $2 $1$2 \ + && docker push $1$2 && break # substitute your command here + n=$((n+1)) + echo "retrying..$n" + sleep 1 +done + diff --git a/.drone/scripts/initialise-images.sh b/.drone/scripts/initialise-images.sh new file mode 100644 index 0000000..5cb7acb --- /dev/null +++ b/.drone/scripts/initialise-images.sh @@ -0,0 +1,3 @@ +sh $(dirname $0)/login.sh $1 "$2" \ +&& sh $(dirname $0)/initialise-image.sh $1 drone/drone:1.9.0 \ +&& sh $(dirname $0)/initialise-image.sh $1 drone/drone-runner-docker:1.5.0 \ No newline at end of file diff --git a/.drone/scripts/login.sh b/.drone/scripts/login.sh new file mode 100644 index 0000000..5a3fe4f --- /dev/null +++ b/.drone/scripts/login.sh @@ -0,0 +1,12 @@ +n=0 +while : +do + docker login $1 --username client --password $2 \ + && break # substitute your command here + n=$((n+1)) + echo "retrying login..$n" + sleep 1 +done + +sh $(dirname $0)/initialise-image.sh $1 drone/drone:1.9.0 \ +&& sh $(dirname $0)/initialise-image.sh $1 drone/drone-runner-docker:1.5.0 \ No newline at end of file diff --git a/.drone/yarn.lock b/.drone/yarn.lock index 35ba3cd..75560d6 100644 --- a/.drone/yarn.lock +++ b/.drone/yarn.lock @@ -12,10 +12,10 @@ 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.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.1.1.tgz#37afda650e8420a664e89c762236a1e59aa485d9" - integrity sha512-GR7LXYaUJYjkcWRyyLlwrBX9Jw04Vlcc/XS32rNaSz4wtrD9opvnmESxNC1UTWXsT/3ybuQhLhCboEb2GiTWmw== +"@sigyl/jsonnet-drone@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone/-/jsonnet-drone-0.3.0.tgz#19a8ed693a040fee33d25f2ca0eec5d88b741a4a" + integrity sha512-c60nAupJ1eRQABKBwO8L9bHohkw6qlEWhPA9IthhHSCOFOzhkx/0N32aFdlSh6400nrieYZMYtQJ/28R9I3Wgg== dependencies: "@sigyl/jsonnet-compose" "^0.0.2" "@sigyl/jsonnet-drone-environment" "0.0.5" diff --git a/docker-compose.yml b/docker-compose.yml index 8856834..3cb708e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: replicas: 1 restart_policy: condition: any - image: drone/drone:1.9.0 + image: ${LOCAL_DOCKER_REGISTRY}drone/drone:1.9.0 volumes: - drone:/var/lib/drone - drone-data:/data @@ -37,7 +37,7 @@ services: replicas: 1 restart_policy: condition: any - image: drone/drone-runner-docker:1.5.0 + image: ${LOCAL_DOCKER_REGISTRY}drone/drone-runner-docker:1.5.0 volumes: - /var/run/docker.sock:/var/run/docker.sock environment: