fix: split jsonnet into libaries
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Giles Bradshaw 2020-08-05 08:30:16 +01:00
parent f11b192cbd
commit 240addaf02
11 changed files with 195 additions and 143 deletions

View File

@ -1,142 +1,8 @@
local publicSecrets = [ local images = import 'lib/images.libsonnet';
'ssh-host', local util = import 'lib/util.libsonnet';
'ssh-user', local compose = import 'node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
'ssh-root-user', local secretSecrets = import 'lib/secret-secrets.libsonnet';
]; local publicSecrets = import 'lib/public-secrets.libsonnet';
local secretSecrets = [
'ssh-password',
];
local util = {
// the head of an array
head(array): array[0],
// the tail of an array
tail(array): std.makeArray(
std.length(array) -1,
function(x) array[x + 1],
),
// compose an array of functions
compose(functions):
local compose(functions) =
if std.length(functions) == 0
then
local ret(object) = object;
ret
else
local ret(object) = compose(
util.tail(
functions,
)
)(
util.head(
functions,
)(object)
);
ret;
compose(functions),
fromSecret(secret): {
from_secret: secret,
},
secret(secret): std.asciiLower(
std.strReplace(
secret,
'_',
'-',
),
),
environment(secret): std.asciiUpper(
std.strReplace(
secret,
'-',
'_',
),
),
env(secret): std.asciiLower(
std.strReplace(
secret,
'-',
'_',
),
),
envSet(env): function(step) step {
environment +: {
[util.environment(env)]: util.fromSecret(
util.secret(env)
),
},
settings +: {
envs +: [
util.env(env),
],
},
},
printEnv(file, env): function(step) util.compose([
util.envSet(env),
function(step) step {
settings +: {
script +: [
'echo "export %(environment)s=\'$${%(environment)s}\'" >> %(file)s # "%(secret)s"' % {
environment: util.environment(env),
file: file,
secret: util.secret(env),
},
],
},
},
])(step),
};
local images = {
docker: {
name: 'docker',
image: 'docker:dind',
},
scp(target): {
name: 'scp',
image: 'appleboy/drone-scp',
settings: {
host: {
from_secret: 'ssh-host',
},
username: {
from_secret: 'ssh-user',
},
password: {
from_secret: 'ssh-password',
},
port: {
from_secret: 'ssh-port',
},
command_timeout: '2m',
target: target,
source: [
'.',
],
},
},
ssh: {
image: 'appleboy/drone-ssh',
settings: {
host: util.fromSecret("ssh-host"),
port: util.fromSecret("ssh-port"),
username: util.fromSecret("ssh-user"),
password: util.fromSecret("ssh-password"),
envs: [
'drone_tag',
'drone_commit',
'drone_build_number',
'drone_repo_name',
'drone_repo_namespace',
],
script: [],
},
},
wait(delay): {
image: 'alpine',
name: 'wait',
commands: [
'sleep %s' % delay,
],
}
};
[ [
{ {
kind: 'pipeline', kind: 'pipeline',
@ -178,7 +44,7 @@ local images = {
'/stack/squid' '/stack/squid'
), ),
images.wait(15), images.wait(15),
util.compose( compose(
std.map( std.map(
function(s) util.envSet(s), function(s) util.envSet(s),
publicSecrets + secretSecrets publicSecrets + secretSecrets

View File

@ -14,8 +14,8 @@ steps:
command_timeout: 2m command_timeout: 2m
host: host:
from_secret: ssh-host from_secret: ssh-host
password: key:
from_secret: ssh-password from_secret: ssh-key
port: port:
from_secret: ssh-port from_secret: ssh-port
source: source:
@ -42,6 +42,7 @@ steps:
- ssh_user - ssh_user
- ssh_root_user - ssh_root_user
- ssh_password - ssh_password
- ssh_key
host: host:
from_secret: ssh-host from_secret: ssh-host
password: password:
@ -66,11 +67,15 @@ steps:
- echo "$${SSH_ROOT_USER}" - echo "$${SSH_ROOT_USER}"
- export SSH_PASSWORD="$${SSH_PASSWORD}" - export SSH_PASSWORD="$${SSH_PASSWORD}"
- echo "$${SSH_PASSWORD}" - echo "$${SSH_PASSWORD}"
- export SSH_KEY="$${SSH_KEY}"
- echo "$${SSH_KEY}"
username: username:
from_secret: ssh-user from_secret: ssh-user
environment: environment:
SSH_HOST: SSH_HOST:
from_secret: ssh-host from_secret: ssh-host
SSH_KEY:
from_secret: ssh-key
SSH_PASSWORD: SSH_PASSWORD:
from_secret: ssh-password from_secret: ssh-password
SSH_ROOT_USER: SSH_ROOT_USER:

View File

@ -0,0 +1,57 @@
local util = import 'util.libsonnet';
{
docker: {
name: 'docker',
image: 'docker:dind',
},
scp(target): {
name: 'scp',
image: 'appleboy/drone-scp',
settings: {
host: {
from_secret: 'ssh-host',
},
username: {
from_secret: 'ssh-user',
},
/*password: {
from_secret: 'ssh-password',
},*/
key: {
from_secret: 'ssh-key',
},
port: {
from_secret: 'ssh-port',
},
command_timeout: '2m',
target: target,
source: [
'.',
],
},
},
ssh: {
image: 'appleboy/drone-ssh',
settings: {
host: util.fromSecret("ssh-host"),
port: util.fromSecret("ssh-port"),
username: util.fromSecret("ssh-user"),
password: util.fromSecret("ssh-password"),
envs: [
'drone_tag',
'drone_commit',
'drone_build_number',
'drone_repo_name',
'drone_repo_namespace',
],
script: [],
},
},
wait(delay): {
image: 'alpine',
name: 'wait',
commands: [
'sleep %s' % delay,
],
}
}

View File

@ -0,0 +1,5 @@
[
'ssh-host',
'ssh-user',
'ssh-root-user',
]

View File

@ -0,0 +1,4 @@
[
'ssh-password',
'ssh-key',
]

60
.drone/lib/util.libsonnet Normal file
View File

@ -0,0 +1,60 @@
local compose = import '../node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
{
// the head of an array
head(array): array[0],
// the tail of an array
tail(array): std.makeArray(
std.length(array) -1,
function(x) array[x + 1],
),
fromSecret(secret): {
from_secret: secret,
},
secret(secret): std.asciiLower(
std.strReplace(
secret,
'_',
'-',
),
),
environment(secret): std.asciiUpper(
std.strReplace(
secret,
'-',
'_',
),
),
env(secret): std.asciiLower(
std.strReplace(
secret,
'-',
'_',
),
),
envSet(env): function(step) step {
environment +: {
[$.environment(env)]: $.fromSecret(
$.secret(env)
),
},
settings +: {
envs +: [
$.env(env),
],
},
},
printEnv(file, env): function(step) compose([
$.envSet(env),
function(step) step {
settings +: {
script +: [
'echo "export %(environment)s=\'$${%(environment)s}\'" >> %(file)s # "%(secret)s"' % {
environment: $.environment(env),
file: file,
secret: $.secret(env),
},
],
},
},
])(step),
}

9
.drone/package.json Normal file
View File

@ -0,0 +1,9 @@
{
"private": true,
"scripts": {
"build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream"
},
"dependencies": {
"@sigyl/jsonnet-compose": "^0.0.2"
}
}

37
.drone/yarn-error.log Normal file
View File

@ -0,0 +1,37 @@
Arguments:
/usr/bin/node /home/giles/.yarn/bin/yarn.js
PATH:
/home/giles/.yarn/bin:/home/giles/.config/yarn/global/node_modules/.bin:/home/giles/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin
Yarn version:
1.22.4
Node version:
11.14.0
Platform:
linux x64
Trace:
Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1176:34)
at TLSSocket.emit (events.js:193:13)
at TLSSocket._finishInit (_tls_wrap.js:667:8)
npm manifest:
{
"private": true,
"scripts": {
"build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream"
},
"dependencies": {
"@sigyl/jsonnet-compose": "^0.0.2"
}
}
yarn manifest:
No manifest
Lockfile:
No lockfile

8
.drone/yarn.lock Normal file
View File

@ -0,0 +1,8 @@
# 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==

1
.gitignore vendored
View File

@ -1 +1,2 @@
myCA/*.pem myCA/*.pem
node_modules

View File

@ -16,7 +16,7 @@ ADD . /apps/
RUN chown -R nobody:nogroup /apps/ RUN chown -R nobody:nogroup /apps/
RUN mkdir -p /apps/squid/var/lib/ RUN mkdir -p /apps/squid/var/lib/
RUN /apps/squid/libexec/ssl_crtd -c -s /apps/squid/var/lib/ssl_db -M 4MB RUN /apps/squid/libexec/ssl_crtd -c -s /apps/squid/var/lib/ssl_db -M 4MB
RUN /apps/squid/sbin/squid -N -f /apps/squid.cache.conf -f RUN /apps/squid/sbin/squid -N -f /apps/squid.cache.conf -z
RUN chown -R nobody:nogroup /apps/ RUN chown -R nobody:nogroup /apps/
EXPOSE 3128 EXPOSE 3128