Compare commits

..

14 Commits

Author SHA1 Message Date
Giles Bradshaw e6f6783df2 chore(release): 1.0.0 2020-10-24 12:16:25 +01:00
Giles Bradshaw 2342b9a6fc feat: destination_registry parameter for save 2020-10-24 12:13:30 +01:00
Giles Bradshaw 9a5228e4be chore(release): 0.4.6 2020-10-23 20:20:47 +01:00
Giles Bradshaw 22d87f9487 feat:drone-images 2020-10-23 20:20:40 +01:00
Giles Bradshaw da35cfd775 chore(release): 0.4.5 2020-10-23 09:18:57 +01:00
Giles Bradshaw 3f87049590 fix: sve to save 2020-10-23 09:18:51 +01:00
Giles Bradshaw 314f2220e8 chore(release): 0.4.4 2020-10-23 09:04:53 +01:00
Giles Bradshaw cdc3e811f4 fix:minor 2020-10-23 09:04:48 +01:00
Giles Bradshaw 323b41a667 chore(release): 0.4.3 2020-10-23 08:56:54 +01:00
Giles Bradshaw b2e38605fd fix:step names too long 2020-10-23 08:56:44 +01:00
Giles Bradshaw 708eb3f32d chore(release): 0.4.2 2020-10-23 01:04:10 +01:00
Giles Bradshaw fd13fe0e03 feat: print, build, save
BREAKING_CHANGE: function parameters chaged
2020-10-23 01:03:07 +01:00
Giles Bradshaw 0aaec64873 chore(release): 0.4.1 2020-10-22 13:10:46 +01:00
Giles Bradshaw cce93724fe feat: docker service uses daemon.json from host 2020-10-22 13:10:13 +01:00
12 changed files with 427 additions and 1716 deletions

View File

@ -2,6 +2,40 @@
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. 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.
## [1.0.0](https://sigyl.com///compare/v0.4.6...v1.0.0) (2020-10-24)
### Features
* destination_registry parameter for save ([2342b9a](https://sigyl.com///commit/2342b9a6fc1f7927ba93938b0233092c1fe1f844))
### [0.4.6](https://sigyl.com///compare/v0.4.5...v0.4.6) (2020-10-23)
### [0.4.5](https://sigyl.com///compare/v0.4.4...v0.4.5) (2020-10-23)
### Bug Fixes
* sve to save ([3f87049](https://sigyl.com///commit/3f87049590036054844998b5b5e93c58757961af))
### [0.4.4](https://sigyl.com///compare/v0.4.3...v0.4.4) (2020-10-23)
### [0.4.3](https://sigyl.com///compare/v0.4.2...v0.4.3) (2020-10-23)
### [0.4.2](https://sigyl.com///compare/v0.4.1...v0.4.2) (2020-10-23)
### Features
* print, build, save ([fd13fe0](https://sigyl.com///commit/fd13fe0e03711f0a67be11f72736b056ab9bb4c4))
### [0.4.1](https://sigyl.com///compare/v0.4.0...v0.4.1) (2020-10-22)
### Features
* docker service uses daemon.json from host ([cce9372](https://sigyl.com///commit/cce93724fee636e32846870a8fe3e43f60d22c84))
## [0.4.0](https://sigyl.com///compare/v0.1.1...v0.4.0) (2020-10-06) ## [0.4.0](https://sigyl.com///compare/v0.1.1...v0.4.0) (2020-10-06)

70
build.libsonnet Normal file
View File

@ -0,0 +1,70 @@
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';
local login = import 'lib/login.libsonnet';
function(config)
function(
buildSecrets,
)
{
kind: 'pipeline',
type: 'docker',
name: 'build',
clone: {
disable: false,
depth: 0,
},
services: [
images(config).docker() {
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',
},
},
],
steps:[
build(config)(buildSecrets),
],
} {
trigger +: {
event +: [
'promote',
],
target +: [
'build',
],
},
}

View File

@ -3,12 +3,11 @@ local images = import 'lib/images.libsonnet';
local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/environment.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 compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
local util = import 'lib/util.libsonnet'; local util = import 'lib/util.libsonnet';
local login = import 'lib/login.libsonnet';
function(config) function(config)
function( function(
name,
root,
buildSecrets, buildSecrets,
publicSecrets, publicSecrets,
secretSecrets, secretSecrets,
@ -22,65 +21,17 @@ function(config)
disable: false, disable: false,
depth: 0, 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:[ steps:[
compose(
std.map(
function(secret) util.printEnv('env-%s' % name, secret),
buildSecrets +
publicSecrets +
secretSecrets
)
)
(
images(config).ssh {
settings +: {
script +: [
'rm -f env-%s' % name,
],
},
},
) {
name: 'print env',
},
images(config).scp( images(config).scp(
'%(root)s%(name)s' % { root: root, name: name } '/%(root)s/%(name)s' % config
), ),
images(config).wait(15),
build(config)(buildSecrets),
compose( compose(
std.map( std.map(
function(secret) environment.envSet(secret), function(secret) environment.envSet(secret),
publicSecrets + secretSecrets + buildSecrets, publicSecrets + secretSecrets + buildSecrets,
), ),
)( )(
images(config).ssh{ images(config).ssh() {
name: 'deploy', name: 'deploy',
settings +: { settings +: {
envs +: std.map( envs +: std.map(
@ -97,8 +48,10 @@ function(config)
) + ) +
[ [
'set -e', 'set -e',
'cd %(root)s%(name)s' % { root: root, name: name }, 'export NAME=%s' % config.name,
'sh .drone/login.sh', 'export ROOT=%s' % config.root,
'cd /%(root)s/%(name)s' % config,
login,
'sh .drone/pull.sh', 'sh .drone/pull.sh',
'sh .drone/deploy.sh', 'sh .drone/deploy.sh',
] ]
@ -106,4 +59,13 @@ function(config)
}, },
), ),
], ],
} } {
trigger +: {
event +: [
'promote',
],
target +: [
'deploy',
],
},
}

63
drone-images.libsonnet Normal file
View File

@ -0,0 +1,63 @@
local images = import 'lib/images.libsonnet';
function(config)
{
kind: 'pipeline',
type: 'docker',
name: 'drone-images',
clone: {
disable: true,
},
steps: [
images(config).ssh() {
settings +: {
script +: [
'mkdir -p /%(root)s/.images/%(name)s/drone-images' % config,
'rm -f /%(root)s/.images/%(name)s/drone-images/*.*' % config,
],
},
}
{
name: 'mkdir',
},
] +
std.map(
function(key)
images(config).ssh() {
settings +: {
envs +: [
'registry_domain',
'registry_port',
'registry_password',
],
script +: [
'docker pull %s' % images(config)[key]().image,
'docker save %(image)s -o /%(root)s/.images/%(name)s/drone-images/%(key)s.tar' % (
config +
{
image: images(config)[key]().image,
key: key,
}
),
'echo "docker load %(key)s.tar" >> /%(root)s/.images/%(name)s/drone-images/load.sh' % (
config +
{
key: key,
}
)
],
},
name: key,
},
std.objectFields(images(config)),
)
} {
trigger +: {
event +: [
'promote',
],
target +: [
'drone-images',
],
},
}

View File

@ -1,9 +1,10 @@
local images = import 'images.libsonnet'; local images = import 'images.libsonnet';
local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet'; local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
local login = import 'login.libsonnet';
function(config) function(config)
function(secrets) function(secrets)
images(config).docker { images(config).docker() {
name +: 'build:', name +: 'build:',
environment +: environment.environmentSecrets(secrets), environment +: environment.environmentSecrets(secrets),
volumes: [ volumes: [
@ -14,9 +15,10 @@ function(config)
], ],
commands: [ commands: [
'set -e', 'set -e',
'sh .drone/login.sh', 'export NAME=%s' % config.name,
'export ROOT=%s' % config.root,
login,
'sh .drone/build.sh', 'sh .drone/build.sh',
'sh .drone/push.sh', 'sh .drone/push.sh',
'sh .drone/logout.sh',
], ],
} }

View File

@ -1,9 +1,9 @@
function (config) { function (config) {
docker: { docker(): {
name: 'docker', name: 'docker',
image: '%(registry)sdocker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f' % config, image: '%(registry)sdocker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f' % config,
}, },
scp(target): { scp(target = ''): {
name: 'scp', name: 'scp',
image: '%(registry)sappleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47' % config, image: '%(registry)sappleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47' % config,
settings +: { settings +: {
@ -14,7 +14,7 @@ function (config) {
], ],
}, },
}, },
ssh: { ssh(): {
image: '%(registry)sappleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea' % config, image: '%(registry)sappleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea' % config,
settings +: { settings +: {
envs: [ envs: [
@ -27,11 +27,4 @@ function (config) {
script: [], script: [],
}, },
}, },
wait(delay): {
image: '%(registry)salpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1' % config,
name: 'wait',
commands: [
'sleep %s' % delay,
],
}
} }

15
lib/login.libsonnet Normal file
View File

@ -0,0 +1,15 @@
|||
n=0
while :
do
docker login $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/ --username client --password "$${REGISTRY_PASSWORD}" \\
&& 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

@ -1,7 +1,7 @@
{ {
"name": "@sigyl/jsonnet-drone", "name": "@sigyl/jsonnet-drone",
"main": "deploy.libsonnet", "main": "deploy.libsonnet",
"version": "0.4.0", "version": "1.0.0",
"description": "jsonnet to build and deploy with drone", "description": "jsonnet to build and deploy with drone",
"scripts": { "scripts": {
"publish-npm": "git push --follow-tags origin master && npm publish", "publish-npm": "git push --follow-tags origin master && npm publish",

53
print.libsonnet Normal file
View File

@ -0,0 +1,53 @@
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';
local login = import 'lib/login.libsonnet';
function(config)
function(
buildSecrets,
publicSecrets,
secretSecrets,
)
{
kind: 'pipeline',
type: 'docker',
name: 'print',
clone: {
disable: false,
depth: 0,
},
steps:[
compose(
std.map(
function(secret) util.printEnv('env-%s' % config.name, secret),
buildSecrets +
publicSecrets +
secretSecrets
)
)
(
images(config).ssh() {
settings +: {
script +: [
'rm -f env-%s' % config.name,
],
},
},
) {
name: 'print env',
},
],
} {
trigger +: {
event +: [
'promote',
],
target +: [
'print',
],
},
}

View File

@ -3,6 +3,7 @@ local images = import 'lib/images.libsonnet';
local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/environment.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 compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
local util = import 'lib/util.libsonnet'; local util = import 'lib/util.libsonnet';
local login = import 'lib/login.libsonnet';
function(config) function(config)
{ {
@ -10,11 +11,10 @@ function(config)
type: 'docker', type: 'docker',
name: 'registry', name: 'registry',
clone: { clone: {
disable: false, disable: true,
depth: 0,
}, },
services: [ services: [
images(config).docker { images(config).docker() {
privileged: true, privileged: true,
volumes: [ volumes: [
{ {
@ -25,6 +25,10 @@ function(config)
name: 'ca', name: 'ca',
path: '/etc/docker/certs.d', path: '/etc/docker/certs.d',
}, },
{
name: 'daemonjson',
path: '/etc/docker/daemon.json',
},
], ],
}, },
], ],
@ -39,10 +43,17 @@ function(config)
path: '/etc/docker/certs.d', path: '/etc/docker/certs.d',
}, },
}, },
{
name: 'daemonjson',
host: {
path: '/etc/docker/daemon.json',
},
},
], ],
steps:[ steps:
images(config).docker { std.map(
name +: 'pull and save docker images:', function(def) images(config).docker() {
name: def.save,
environment +: environment environment +: environment
.environmentSecrets(config.secrets), .environmentSecrets(config.secrets),
volumes: [ volumes: [
@ -53,58 +64,37 @@ function(config)
], ],
commands: [ commands: [
'set -e', 'set -e',
'export REGISTRY=$${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/', login,
'%(script)s $${REGISTRY} "$${REGISTRY_PASSWORD}"' % config, |||
n=0
while :
do
docker pull %(load)s \\
&& docker tag %(load)s $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s \\
&& docker push $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s && break
n=$((n+1))
if [ $n -ge 10 ]; then
echo "initialise failed"
exit 1
fi
echo "retrying..$n"
sleep 5
done
||| % (config + def),
], ],
}, },
], config.images,
),
image_pull_secrets: [ image_pull_secrets: [
'dockerconfigjson' 'dockerconfigjson'
] ]
} {
trigger +: {
event +: [
'promote',
],
target +: [
'registry',
],
},
} }
/*
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,
},
]
*/

121
save.libsonnet Normal file
View File

@ -0,0 +1,121 @@
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';
local login = import 'lib/login.libsonnet';
function(config)
function(
defs,
builtDefs,
)
{
kind: 'pipeline',
type: 'docker',
name: 'save',
clone: {
disable: true,
},
steps: [
images(config).ssh() {
settings +: {
script +: [
'mkdir -p /%(root)s/.images/%(name)s/built' % config,
'rm -f /%(root)s/.images/%(name)s/*.*' % config,
'rm -f /%(root)s/.images/%(name)s/built/*.*' % config,
],
},
}
{
name: 'mkdir',
},
] +
std.map(
function(def)
images(config).ssh() {
settings +: {
envs +: [
'registry_domain',
'registry_port',
'registry_password',
'destination_registry'
],
script +: [
login,
'docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s' % (config + def),
'docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s -o /%(root)s/.images/%(name)s/%(out)s.tar' % (
config + def +
{
out: std.strReplace(def.save, '/', '_'),
}
),
'echo "docker load < %(out)s.tar" >> /%(root)s/.images/%(name)s/load.sh' % (
config + {
out: std.strReplace(def.save, '/', '_'),
}
),
'echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(pull)s $${DESTINATION_REGISTRY}/%(root)s/%(name)s/%(pull)s" >> /%(root)s/.images/%(name)s/load.sh' % (
config +
{
pull: def.save,
}
),
],
},
} +
{
name: def.save,
},
defs
) +
std.map(
function(def)
images(config).ssh() {
settings +: {
envs +: [
'registry_domain',
'registry_port',
'registry_password',
'destination_registry',
],
script +: [
login,
'docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s' % (config + { save: def }),
'docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s -o /%(root)s/.images/%(name)s/built/%(out)s.tar' % (
config +
{
save: def,
out: std.strReplace(def, '/', '_'),
}
),
'echo "docker load %(out)s.tar" >> /%(root)s/.images/%(name)s/built/load.sh' % (
config + {
out: std.strReplace(def, '/', '_'),
}
),
'echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(pull)s ${DESINATION_REGISTRY}/%(root)s/%(name)s/%(pull)s" >> /%(root)s/.images/%(name)s/built/load.sh' % (
config +
{
pull: def,
}
),
],
},
} +
{
name: def,
},
builtDefs
),
} {
trigger +: {
event +: [
'promote',
],
target +: [
'save',
],
},
}

1592
yarn.lock

File diff suppressed because it is too large Load Diff