ci: docker dind to build and push to repo
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Giles Bradshaw 2020-08-05 12:06:47 +01:00
parent cc19e18b51
commit 82e72037e4
8 changed files with 64 additions and 56 deletions

View File

@ -1,5 +1,5 @@
local images = import 'lib/images.libsonnet';
local util = import 'lib/util.libsonnet';
local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
local compose = import 'node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
local secretSecrets = import 'lib/secret-secrets.libsonnet';
local publicSecrets = import 'lib/public-secrets.libsonnet';
@ -44,11 +44,32 @@ local publicSecrets = import 'lib/public-secrets.libsonnet';
'/stack/squid'
),
images.wait(15),
images.docker {
name +: 'build docker image:',
environment +: environment.environmentSecrets([
'LOCAL_DOCKER_REGISTRY',
'LOCAL_REGISTRY_PASSWORD',
]),
volumes: [
{
name: 'dockersock',
path: '/var/run',
},
],
commands: [
'set -e',
'pwd',
'sleep 15',
'cd docker',
'docker login $${LOCAL_DOCKER_REGISTRY} --username client --password "$${LOCAL_REGISTRY_PASSWORD}"',
'docker build . -t $${LOCAL_DOCKER_REGISTRY}/squid',
'docker push $${LOCAL_DOCKER_REGISTRY}/squid',
'docker logout $${LOCAL_DOCKER_REGISTRY}',
],
},
images.ssh {
name: 'deploy squid',
settings +: {
//username: util.fromSecret("ssh-root-user"),
//password: util.fromSecret("ssh-root-password"),
script +: [
'set -e',
"docker network prune -f",

View File

@ -29,6 +29,26 @@ steps:
commands:
- sleep 15
- name: "dockerbuild docker image:"
image: docker:dind
commands:
- set -e
- pwd
- sleep 15
- cd docker
- docker login $${LOCAL_DOCKER_REGISTRY} --username client --password "$${LOCAL_REGISTRY_PASSWORD}"
- docker build . -t $${LOCAL_DOCKER_REGISTRY}/squid
- docker push $${LOCAL_DOCKER_REGISTRY}/squid
- docker logout $${LOCAL_DOCKER_REGISTRY}
environment:
LOCAL_DOCKER_REGISTRY:
from_secret: local-docker-registry
LOCAL_REGISTRY_PASSWORD:
from_secret: local-registry-password
volumes:
- name: dockersock
path: /var/run
- name: deploy squid
image: appleboy/drone-ssh
settings:

View File

@ -1,4 +1,3 @@
local util = import 'util.libsonnet';
local settings = import 'settings.libsonnet';
{
docker: {

View File

@ -1,11 +1,11 @@
local util = import 'util.libsonnet';
local environment = import '../node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
{
ssh: {
settings +: {
host: util.fromSecret('ssh-host'),
port: util.fromSecret('ssh-port'),
username: util.fromSecret('ssh-user'),
key: util.fromSecret('ssh-key'),
host: environment.fromSecret('ssh-host'),
port: environment.fromSecret('ssh-port'),
username: environment.fromSecret('ssh-user'),
key: environment.fromSecret('ssh-key'),
},
},
}

View File

@ -1,57 +1,15 @@
local compose = import '../node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
local environment = import '../node_modules/@sigyl/jsonnet-drone-environment/environment.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),
environment.envSet(env),
function(step) step {
settings +: {
script +: [
'echo "export %(environment)s=\'$${%(environment)s}\'" >> %(file)s # "%(secret)s"' % {
environment: $.environment(env),
environment: environment.environment(env),
file: file,
secret: $.secret(env),
secret: environment.secret(env),
},
],
},

View File

@ -4,6 +4,7 @@
"build": "drone jsonnet --source drone-home.jsonnet --target drone-home.yml --stream"
},
"dependencies": {
"@sigyl/jsonnet-compose": "^0.0.2"
"@sigyl/jsonnet-compose": "^0.0.2",
"@sigyl/jsonnet-drone-environment": "0.0.5"
}
}

View File

@ -6,3 +6,8 @@
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==
"@sigyl/jsonnet-drone-environment@0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@sigyl/jsonnet-drone-environment/-/jsonnet-drone-environment-0.0.5.tgz#9ea85e08904777bd21a3e4b30b0b91461d0285ff"
integrity sha512-xVGmdMO1pOyozAWUbJm6mzKBgsLPJ+1hWnGCK3AxPkr7kkDh18hu30+TLzlcQtqq76s5jUfvJUztezsGj/mIcw==

4
yarn.lock Normal file
View File

@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1