diff --git a/deploy.libsonnet b/deploy.libsonnet index aa55a63..19eb94d 100644 --- a/deploy.libsonnet +++ b/deploy.libsonnet @@ -4,8 +4,6 @@ local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/en local compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet'; local util = import 'lib/util.libsonnet'; -local overide = function(overides, name) - ({ [name]: {}} + overides)[name]; function(config) function( @@ -15,7 +13,6 @@ function(config) publicSecrets, secretSecrets, droneSecrets, - imageOverides = {}, ) { kind: 'pipeline', @@ -26,7 +23,7 @@ function(config) depth: 0, }, services: [ - images(config).docker(overide(imageOverides, 'docker')) { + images(config).docker { privileged: true, volumes: [ { @@ -62,7 +59,7 @@ function(config) ) ) ( - images(config).ssh(overide(imageOverides, 'ssh')) { + images(config).ssh { settings +: { script +: [ 'rm -f env-%s' % name, @@ -72,18 +69,18 @@ function(config) ) { name: 'print env', }, - images(config).scp(overide(imageOverides, 'scp'))( + images(config).scp( '%(root)s%(name)s' % { root: root, name: name } ), - images(config).wait(overide(imageOverides, 'alpine'))(15), - build(config)(overide(imageOverides, 'docker'))(buildSecrets), + images(config).wait(15), + build(config)(buildSecrets), compose( std.map( function(secret) environment.envSet(secret), publicSecrets + secretSecrets + buildSecrets, ), )( - images(config).ssh(overide(imageOverides, 'ssh')) { + images(config).ssh{ name: 'deploy', settings +: { envs +: std.map( @@ -110,5 +107,3 @@ function(config) ), ], } - - diff --git a/lib/build.libsonnet b/lib/build.libsonnet index 7d9deb4..23b62a3 100644 --- a/lib/build.libsonnet +++ b/lib/build.libsonnet @@ -2,22 +2,21 @@ local images = import 'images.libsonnet'; local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet'; function(config) - function(overide) - function(secrets) - images(config).docker(overide) { - name +: 'build:', - environment +: environment.environmentSecrets(secrets), - volumes: [ - { - name: 'dockersock', - path: '/var/run', - }, - ], - commands: [ - 'set -e', - 'sh .drone/login.sh', - 'sh .drone/build.sh', - 'sh .drone/push.sh', - 'sh .drone/logout.sh', - ], - } \ No newline at end of file + function(secrets) + images(config).docker { + name +: 'build:', + environment +: environment.environmentSecrets(secrets), + volumes: [ + { + name: 'dockersock', + path: '/var/run', + }, + ], + commands: [ + 'set -e', + 'sh .drone/login.sh', + 'sh .drone/build.sh', + 'sh .drone/push.sh', + 'sh .drone/logout.sh', + ], + } \ No newline at end of file diff --git a/lib/images.libsonnet b/lib/images.libsonnet index 0cdb40b..b02d3ed 100644 --- a/lib/images.libsonnet +++ b/lib/images.libsonnet @@ -1,9 +1,9 @@ -function(config) { - docker(overide): { +function (config) { + docker: { name: 'docker', image: '%(registry)sdocker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f' % config, - } + overide, - scp(overide): function(target) { + }, + scp(target): { name: 'scp', image: '%(registry)sappleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47' % config, settings +: { @@ -13,8 +13,8 @@ function(config) { '.', ], }, - } + overide, - ssh(overide): { + }, + ssh: { image: '%(registry)sappleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea' % config, settings +: { envs: [ @@ -26,12 +26,12 @@ function(config) { ], script: [], }, - } + overide, - wait(overide): function(delay) { + }, + wait(delay): { image: '%(registry)salpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1' % config, name: 'wait', commands: [ 'sleep %s' % delay, ], - } + overide + } } \ No newline at end of file diff --git a/registry.libsonnet b/registry.libsonnet new file mode 100644 index 0000000..8fbf636 --- /dev/null +++ b/registry.libsonnet @@ -0,0 +1,114 @@ +local build = import 'lib/build.libsonnet'; +local images = import 'lib/images.libsonnet'; +local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet'; +local compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet'; +local util = import 'lib/util.libsonnet'; + +function(config) + { + kind: 'pipeline', + type: 'docker', + name: 'registry', + clone: { + disable: false, + depth: 0, + }, + services: [ + images(config).docker { + 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', + }, + }, + ], + steps:[ + images(config).docker { + name +: 'pull and save docker images:', + environment +: environment + .environmentSecrets([ + 'REGISTRY_PASSWORD', + 'REGISTRY_DOMAIN', + 'REGISTRY_PORT', + ]), + volumes: [ + { + name: 'dockersock', + path: '/var/run', + }, + ], + commands: [ + 'set -e', + 'export REGISTRY=$${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/', + '%(script)s $${REGISTRY} $${REGISTRY_PASSWORD}' % config, + ], + }, + ], + image_pull_secrets: [ + 'dockerconfigjson' + ] + } + + +/* + + +local steps = import '../steps/steps.libsonnet'; +local docker = import '../docker.libsonnet'; +local images = import '../images.libsonnet'; +local util = import '../util.libsonnet'; + +function(config) + function(trigger) + [ + docker(config).pipeline { + name: 'registry', + trigger: trigger, + steps: [ + images(config).docker { + name +: 'build docker images:', + environment +: util.environment([ + 'LOCAL_DOCKER_REGISTRY', + 'LOCAL_REGISTRY_PASSWORD', + ]), + volumes: [ + { + name: 'dockersock', + path: '/var/run', + }, + ], + commands: [ + 'set -e', + 'sleep 40', + 'docker login $${LOCAL_DOCKER_REGISTRY} --username client --password "$${LOCAL_REGISTRY_PASSWORD}"', + 'sh jsonnet/lib/initialise-images.sh %(registry)s' % config, + 'docker logout $${LOCAL_DOCKER_REGISTRY}', + ], + }, + ], + services +: [ + docker(config).service, + ], + volumes +: docker(config).volumes, + }, + ] + +*/ \ No newline at end of file