function(vars={}) { dockerBuild: { // base job to manage containers (build / push) variables: { DOCKER_DRIVER: "overlay2", DOCKER_HOST: "tcp://docker-host.gitlab-runner.svc.cluster.local:2375" }, image: "docker:git", before_script: [ "docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io", ], tags: [ "kubernetes", ], }, QuayTest: { // base job to test the container image: vars.images.quayci.name, variables: { TEST: "true", PYTHONPATH: ".", QUAYDIR: "/quay-registry", GIT_STRATEGY: "none", }, before_script: [ "cd $QUAYDIR", "source $QUAYDIR/venv/bin/activate", ], tags: [ "kubernetes", ], }, QuayDeploy: { local this = self, local _vars = self.localvars, localvars:: { appversion: "1.0.0-%s" % self.image.tag, apprepo: "quay.io/quay/%s" % self.appname, appname: "quay-ci-app", domain: "quay-%s.k8s.devtable.com" % self.image.tag, namespace: "ci-quay-%s" % self.image.tag, image: vars.images.quayci, channels: [], pushargs: ["-f"], buildParams(extra_params={}):: ( local params = {image: _vars.image.name, tag: _vars.image.tag, domain: "$QUAY_DOMAIN"} + extra_params; [ "echo -n %s > VERSION" % _vars.appversion, 'echo %s > params.json' % std.escapeStringJson(params), "cat params.json" ]), pushApp(repo="quay.io/quay", extra_args=['-f'], channels=[]):: ( ["appr push %s %s" % [repo, std.join(" ", extra_args)]] + ["appr push %s -c %s" % [repo, channel] for channel in channels] ), }, variables: {K8S_NAMESPACE: _vars.namespace, QUAY_DOMAIN: _vars.domain}, image: "quay.io/appr/appr:kubectl", environment: { name: "review/%s" % _vars.image.tag, url: "https://%s" % _vars.domain, }, tags: [ "kubernetes", ], before_script: [ "appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io", "cd deploy/%s" % _vars.appname, ] + _vars.buildParams(), script: _vars.pushApp(_vars.apprepo, _vars.pushargs, _vars.channels) + [ "appr deploy %s@%s --namespace %s -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS" % [ _vars.apprepo, _vars.appversion, _vars.namespace], "kubectl get ingresses -n %s -o wide" % _vars.namespace, ], }, QuayDeployStop: self.QuayDeploy { variables+: {GIT_STRATEGY: "none"}, environment+: { action: "stop" }, before_script: [], script: [], }, EndToEndTest: self.QuayTest { initDb:: true, services: [ {name: "postgres:9.6"}, {name: vars.images.quayci.name, alias: 'quay'} ] + if self.initDb == true then [ {name: vars.images.quayci.name, alias: 'db-init', command: ["/bin/sh", "-c", "sleep 30" + "&& /quay-registry/venv/bin/python initdb.py" + "&& sleep 3600",]}, ] else [], before_script: if self.image == vars.images.quayci.name then super.before_script else [], script: ['sleep 150'], variables+: { APP_HOST: "localhost:80", POSTGRES_PASSWORD: "quay", POSTGRES_USER: "quay", SKIP_DB_SCHEMA: 'true', TEST_DATABASE_URI: self['DB_URI'], QUAY_OVERRIDE_CONFIG: '' + {"SERVER_HOSTNAME": "localhost:80"}, DB_URI: 'postgresql://quay:quay@localhost/quay' }, }, dbTest(scheme, image, env):: self.QuayTest { variables+: { SKIP_DB_SCHEMA: 'true', TEST_DATABASE_URI: '%s://quay:quay@localhost/quay' % scheme, } + env, coverage: @"/^TOTAL.*\s+(\d+\%)\s*$/", 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', ], }, }