Generate .gitlab.yaml via .gitlab.jsonnet
This commit is contained in:
parent
165486180d
commit
24044df945
6 changed files with 379 additions and 137 deletions
49
.gitlab-ci/base_jobs.libsonnet
Normal file
49
.gitlab-ci/base_jobs.libsonnet
Normal file
|
@ -0,0 +1,49 @@
|
|||
function(vars={})
|
||||
{
|
||||
dockerBuild: {
|
||||
// base job to manage containers (build / push)
|
||||
variables: {
|
||||
DOCKER_DRIVER: "aufs",
|
||||
},
|
||||
image: "docker:git",
|
||||
before_script: [
|
||||
"docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io",
|
||||
],
|
||||
services: [
|
||||
"docker:dind",
|
||||
],
|
||||
tags: [
|
||||
"docker",
|
||||
],
|
||||
},
|
||||
|
||||
QuayTest: {
|
||||
// base job to test the container
|
||||
image: vars.images.quayci.name,
|
||||
variables: {
|
||||
TEST: "true",
|
||||
PYTHONPATH: ".",
|
||||
GIT_STRATEGY: "none",
|
||||
},
|
||||
before_script: [
|
||||
"cd /",
|
||||
"source venv/bin/activate",
|
||||
],
|
||||
tags: [
|
||||
"kubernetes",
|
||||
],
|
||||
},
|
||||
|
||||
dbTest(scheme, image, env):: self.QuayTest {
|
||||
variables+: {
|
||||
SKIP_DB_SCHEMA: 'true',
|
||||
TEST_DATABASE_URI: '%s://quay:quay@localhost/quay' % scheme,
|
||||
} + env,
|
||||
services: [image],
|
||||
script: [
|
||||
"sleep 30",
|
||||
"alembic upgrade head",
|
||||
'PYTHONPATH="." TEST="true" py.test --timeout=7200 --verbose --show-count ./ --color=no --ignore=endpoints/appr/test/ -x',
|
||||
],
|
||||
},
|
||||
}
|
66
.gitlab-ci/utils.libsonnet
Normal file
66
.gitlab-ci/utils.libsonnet
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
local topSelf = self,
|
||||
# Generate a sequence array from 1 to i
|
||||
seq(i):: (
|
||||
[x for x in std.range(1, i)]
|
||||
),
|
||||
|
||||
objectFieldsHidden(obj):: (
|
||||
std.setDiff(std.objectFieldsAll(obj), std.objectFields(obj))
|
||||
),
|
||||
|
||||
objectFlatten(obj):: (
|
||||
// Merge 1 level dict depth into toplevel
|
||||
local visible = { [k]: obj[j][k]
|
||||
for j in std.objectFieldsAll(obj)
|
||||
for k in std.objectFieldsAll(obj[j]) };
|
||||
|
||||
visible
|
||||
),
|
||||
|
||||
compact(array):: (
|
||||
[x for x in array if x != null]
|
||||
),
|
||||
|
||||
objectValues(obj):: (
|
||||
local fields = std.objectFields(obj);
|
||||
[obj[key] for key in fields]
|
||||
),
|
||||
|
||||
objectMap(func, obj):: (
|
||||
local fields = std.objectFields(obj);
|
||||
{ [key]: func(obj[key]) for key in fields }
|
||||
),
|
||||
|
||||
capitalize(str):: (
|
||||
std.char(std.codepoint(str[0]) - 32) + str[1:]
|
||||
),
|
||||
|
||||
test: self.capitalize("test"),
|
||||
|
||||
set(array)::
|
||||
{ [key]: key for key in array },
|
||||
|
||||
containerName(repo, tag):: "%s:%s" % [repo, tag],
|
||||
|
||||
ci: {
|
||||
|
||||
mergeJob(base_job, jobs, stage=null):: {
|
||||
[job_name]: base_job + jobs[job_name] +
|
||||
if stage != null then { stage: stage } else {}
|
||||
for job_name in std.objectFields(jobs)
|
||||
},
|
||||
|
||||
only(key):: (
|
||||
if key == "master"
|
||||
then { only: ['master', 'tags'] }
|
||||
else { only: ['branches'] }
|
||||
),
|
||||
|
||||
setManual(key, values):: (
|
||||
if std.objectHas(topSelf.set(values), key)
|
||||
then { when: 'manual' }
|
||||
else { only: ['branches'] }
|
||||
),
|
||||
},
|
||||
}
|
27
.gitlab-ci/vars.libsonnet
Normal file
27
.gitlab-ci/vars.libsonnet
Normal file
|
@ -0,0 +1,27 @@
|
|||
local utils = import "utils.libsonnet";
|
||||
|
||||
{
|
||||
global: {
|
||||
// .gitlab-ci.yaml top `variables` key
|
||||
FAILFASTCI_NAMESPACE: "quay",
|
||||
},
|
||||
|
||||
// internal variables
|
||||
images: {
|
||||
// Quay initial image, used in the FROM clause
|
||||
base: { repo: "quay.io/quay/quay-base", tag: "latest",
|
||||
name: utils.containerName(self.repo, self.tag),
|
||||
},
|
||||
|
||||
// @TODO(ant31) release should use quay/quay
|
||||
// release is a copy of the quayci image to the 'prod' repository
|
||||
release: { repo: "quay.io/quay/quay-ci",
|
||||
tag: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}",
|
||||
name: utils.containerName(self.repo, self.tag),
|
||||
},
|
||||
|
||||
quayci: { repo: "quay.io/quay/quay-ci", tag: "${CI_COMMIT_REF_SLUG}",
|
||||
name: utils.containerName(self.repo, self.tag),
|
||||
},
|
||||
},
|
||||
}
|
Reference in a new issue