From 0f7c526b74b6b6ecec97792624ba74adb83991ec Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 11 Jul 2019 10:49:56 +0200 Subject: [PATCH] ci: add build docker image tasks Always build a docker image to test if build works. When on a tag also publish the image. --- .agola/config.jsonnet | 81 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/.agola/config.jsonnet b/.agola/config.jsonnet index 77dc847..55e44ff 100644 --- a/.agola/config.jsonnet +++ b/.agola/config.jsonnet @@ -12,13 +12,12 @@ local task_build(version, arch) = { runtime: node_runtime(version, arch), environment: {}, steps: [ - { type: 'run', command: 'env' }, { type: 'clone' }, - { type: 'restore_cache', keys: ['cache-node'+version+'-sum-{{ md5sum "package.json" }}', 'cache-node'+version+'-date-'], dest_dir: './node_modules' }, + { type: 'restore_cache', keys: ['cache-node' + version + '-sum-{{ md5sum "package.json" }}', 'cache-node' + version + '-date-'], dest_dir: './node_modules' }, { type: 'run', command: 'npm install' }, { type: 'run', command: 'npm run build' }, - { type: 'save_cache', key: 'cache-node'+version+'-sum-{{ md5sum "package.json" }}', contents: [{ source_dir: './node_modules' }] }, - { type: 'save_cache', key: 'cache-node'+version+'-date-{{ year }}-{{ month }}-{{ day }}', contents: [{ source_dir: './node_modules' }] }, + { type: 'save_cache', key: 'cache-node' + version + '-sum-{{ md5sum "package.json" }}', contents: [{ source_dir: './node_modules' }] }, + { type: 'save_cache', key: 'cache-node' + version + '-date-{{ year }}-{{ month }}-{{ day }}', contents: [{ source_dir: './node_modules' }] }, ], }; @@ -32,7 +31,79 @@ local task_build(version, arch) = { ] for version in ['11', '12'] for arch in ['amd64'] - ]) + ]) + [ + { + name: 'checkout code and save to workspace', + runtime: { + arch: 'amd64', + containers: [ + { + image: 'alpine/git', + }, + ], + }, + steps: [ + { type: 'clone' }, + { type: 'save_to_workspace', contents: [{ source_dir: '.', dest_dir: '.', paths: ['**'] }] }, + ], + depends: [], + }, + { + name: 'test build docker image', + runtime: { + arch: 'amd64', + containers: [ + { + image: 'gcr.io/kaniko-project/executor:debug', + }, + ], + }, + shell: '/busybox/sh', + working_dir: '/workspace', + steps: [ + { type: 'restore_workspace', dest_dir: '.' }, + { type: 'run', command: '/kaniko/executor --no-push' }, + ], + depends: ['checkout code and save to workspace'], + }, + { + name: 'build and push docker image', + runtime: { + arch: 'amd64', + containers: [ + { + image: 'gcr.io/kaniko-project/executor:debug', + }, + ], + }, + environment: { + DOCKERAUTH: { from_variable: 'dockerauth' }, + }, + shell: '/busybox/sh', + working_dir: '/workspace', + steps: [ + { type: 'restore_workspace', dest_dir: '.' }, + { + type: 'run', + name: 'generate docker auth', + command: ||| + cat << EOF > /kaniko/.docker/config.json + { + "auths": { + "https://index.docker.io/v1/": { "auth" : "$DOCKERAUTH" } + } + } + EOF + |||, + }, + { type: 'run', command: '/kaniko/executor --destination sorintlab/agola:$AGOLA_GIT_TAG' }, + ], + depends: ['checkout code and save to workspace'], + when: { + tag: '#v.*#', + }, + }, + ], }, ], }