2017-06-13 03:55:12 +00:00
|
|
|
local utils = import '.gitlab-ci/utils.libsonnet';
|
|
|
|
local vars = import '.gitlab-ci/vars.libsonnet';
|
|
|
|
local mergeJob = utils.ci.mergeJob;
|
|
|
|
local images = vars.images;
|
|
|
|
local baseJob = (import '.gitlab-ci/base_jobs.libsonnet')(vars);
|
|
|
|
|
|
|
|
local stages_list = [
|
|
|
|
// gitlab-ci stages
|
2017-07-16 23:24:31 +00:00
|
|
|
'docker_base',
|
2017-07-28 11:04:28 +00:00
|
|
|
'docker_build',
|
2017-07-19 22:34:08 +00:00
|
|
|
'deploy_preview',
|
2017-07-28 11:23:31 +00:00
|
|
|
'tests',
|
2017-07-28 15:13:52 +00:00
|
|
|
'integration',
|
2017-06-13 03:55:12 +00:00
|
|
|
'docker_release',
|
2017-07-19 22:34:08 +00:00
|
|
|
'deploy_staging',
|
2017-06-13 03:55:12 +00:00
|
|
|
'teardown',
|
|
|
|
];
|
2017-06-26 13:21:59 +00:00
|
|
|
|
2017-06-13 03:55:12 +00:00
|
|
|
local stages = utils.set(stages_list);
|
|
|
|
|
|
|
|
// List CI jobs
|
|
|
|
local jobs = {
|
|
|
|
// Helpers
|
|
|
|
local onlyMaster = {
|
|
|
|
only: ['master', 'tags'],
|
|
|
|
},
|
2017-07-28 11:23:31 +00:00
|
|
|
|
2017-06-13 03:55:12 +00:00
|
|
|
local onlyBranch = {
|
|
|
|
only: ['branches'],
|
2017-07-20 13:15:20 +00:00
|
|
|
except: ['master']
|
2017-06-13 03:55:12 +00:00
|
|
|
},
|
|
|
|
|
2017-07-28 11:07:42 +00:00
|
|
|
'container-base-build': baseJob.dockerBuild {
|
2017-06-13 03:55:12 +00:00
|
|
|
// ! Only master/tags
|
|
|
|
// Update the base container
|
|
|
|
stage: stages.docker_base,
|
|
|
|
script: [
|
2017-07-27 09:53:23 +00:00
|
|
|
'docker build --no-cache' +
|
2017-06-13 03:55:12 +00:00
|
|
|
' -t %s -f quay-base.dockerfile .' % images.base.name,
|
|
|
|
'docker push %s' % images.base.name,
|
|
|
|
],
|
2017-07-28 11:07:42 +00:00
|
|
|
only: ["schedules"]
|
2017-06-13 03:55:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'container-build': baseJob.dockerBuild {
|
|
|
|
// Build and push the quay container.
|
|
|
|
// Docker Tag is the branch/tag name
|
|
|
|
stage: stages.docker_build,
|
|
|
|
script: [
|
2017-07-27 15:42:23 +00:00
|
|
|
'docker build --no-cache -t %s -f Dockerfile .' % images.quayci.name,
|
2017-07-27 09:53:23 +00:00
|
|
|
'docker run --rm %s cat ALEMBIC_HEAD > /tmp/ALEMBIC_HEAD' % images.quayci.name,
|
|
|
|
'export MIGRATION_HEAD=`cat /tmp/ALEMBIC_HEAD | cut -d" " -f1`',
|
|
|
|
'echo $MIGRATION_HEAD',
|
|
|
|
'docker build --label db-schema-head=$MIGRATION_HEAD -t %s -f Dockerfile .' % images.quayci.name,
|
2017-06-13 03:55:12 +00:00
|
|
|
'docker push %s' % images.quayci.name],
|
|
|
|
},
|
|
|
|
|
|
|
|
'container-release': baseJob.dockerBuild + onlyMaster {
|
|
|
|
// ! Only master/tags
|
|
|
|
// push the container to the 'prod' repository
|
|
|
|
local repo_with_sha = images.release.name,
|
|
|
|
stage: stages.docker_release,
|
|
|
|
script: [
|
|
|
|
'docker pull %s' % images.quayci.name,
|
|
|
|
'docker tag %s %s' % [images.quayci.name, repo_with_sha],
|
|
|
|
'docker push %s' % [repo_with_sha], # @TODO(ant31) add signing
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
// Unit-tests
|
|
|
|
local unittest_stage = baseJob.QuayTest {
|
2017-07-28 11:23:31 +00:00
|
|
|
stage: stages.tests },
|
2017-06-20 09:30:27 +00:00
|
|
|
local pytest_cmd = 'py.test --cov="." --cov-report=html --cov-report=term-missing' +
|
|
|
|
' --timeout=3600 --verbose -x --color=no --show-count ',
|
2017-06-13 03:55:12 +00:00
|
|
|
'unit-tests': unittest_stage {
|
2017-06-20 09:30:27 +00:00
|
|
|
coverage: @"/^TOTAL.*\s+(\d+\%)\s*$/",
|
2017-06-13 03:55:12 +00:00
|
|
|
script: [
|
2017-06-20 09:30:27 +00:00
|
|
|
pytest_cmd + ' ./',],
|
|
|
|
after_script: [
|
|
|
|
'cp -r $QUAYDIR/htmlcov/ $CI_PROJECT_DIR/coverage'
|
|
|
|
],
|
|
|
|
artifacts: {
|
|
|
|
paths: ['coverage',]
|
|
|
|
}
|
|
|
|
},
|
2017-06-13 03:55:12 +00:00
|
|
|
|
|
|
|
'registry-tests': unittest_stage {
|
2018-05-01 10:52:35 +00:00
|
|
|
script: [ pytest_cmd + ' ./test/registry/registry_tests.py'],
|
2017-06-20 09:30:27 +00:00
|
|
|
coverage: @"/^TOTAL.*\s+(\d+\%)\s*$/",
|
|
|
|
},
|
2017-06-13 03:55:12 +00:00
|
|
|
|
|
|
|
// UI tests
|
|
|
|
'karma-tests': unittest_stage {
|
|
|
|
script: [
|
|
|
|
'curl -Ss https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -',
|
|
|
|
'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list',
|
|
|
|
'apt-get update -yqqq',
|
|
|
|
'apt-get install -y google-chrome-stable',
|
|
|
|
'yarn test'
|
|
|
|
] },
|
|
|
|
|
2017-07-14 08:28:19 +00:00
|
|
|
// Integration API
|
|
|
|
local integration_test = baseJob.EndToEndTest {
|
2017-07-18 07:08:33 +00:00
|
|
|
stage: stages.integration
|
2017-07-14 08:28:19 +00:00
|
|
|
},
|
|
|
|
|
2017-07-28 11:23:31 +00:00
|
|
|
'protractor_e2e': integration_test {
|
|
|
|
initDb:: true,
|
2017-07-18 07:08:33 +00:00
|
|
|
variables+: {"APP_HOST": "http://localhost:80"},
|
2017-07-28 15:13:52 +00:00
|
|
|
services+: [{name: "selenium/standalone-chrome:3.4.0"}],
|
2017-07-18 07:08:33 +00:00
|
|
|
before_script+: [
|
|
|
|
"curl -sL https://deb.nodesource.com/setup_8.x | bash -",
|
2017-07-28 11:04:28 +00:00
|
|
|
"apt-get install -y nodejs",
|
|
|
|
"./node_modules/.bin/webdriver-manager update",
|
2017-07-18 07:08:33 +00:00
|
|
|
],
|
2017-07-28 11:23:31 +00:00
|
|
|
allow_failure: true,
|
|
|
|
script+: [
|
2017-07-18 07:08:33 +00:00
|
|
|
"yarn e2e",
|
2017-07-14 08:28:19 +00:00
|
|
|
]
|
|
|
|
},
|
2017-07-18 07:08:33 +00:00
|
|
|
|
2017-07-28 11:04:28 +00:00
|
|
|
'appr_e2e': integration_test {
|
2017-07-28 11:23:31 +00:00
|
|
|
initDb:: true,
|
|
|
|
image: {name: "quay.io/appr/appr:kubectl"},
|
|
|
|
before_script: [],
|
|
|
|
script+: [
|
|
|
|
"appr version localhost:80",
|
|
|
|
"appr list localhost:80",
|
|
|
|
],
|
|
|
|
allow_failure: true,
|
2017-07-28 11:04:28 +00:00
|
|
|
},
|
|
|
|
|
2017-07-28 15:13:52 +00:00
|
|
|
'docker_e2e': integration_test {
|
|
|
|
initDb:: true,
|
|
|
|
image: {name: "docker"},
|
|
|
|
services+: [{name: "docker:dind"}],
|
|
|
|
variables+: {
|
|
|
|
DOCKER_DRIVER: "overlay2",
|
|
|
|
DOCKER_HOST: "tcp://localhost:2375"
|
|
|
|
},
|
|
|
|
before_script: [],
|
|
|
|
script+: [
|
|
|
|
"docker login localhost:80 -u devtable -p password",
|
|
|
|
"docker pull nginx",
|
|
|
|
"docker tag nginx localhost:80/devtable/nginx",
|
|
|
|
"docker push localhost:80/devtable/nginx",
|
|
|
|
"sleep 1",
|
|
|
|
"docker pull localhost:80/devtable/nginx",
|
|
|
|
],
|
|
|
|
allow_failure: true,
|
|
|
|
},
|
|
|
|
|
2017-06-13 03:55:12 +00:00
|
|
|
// Unit-tests with real databases
|
2017-07-28 11:23:31 +00:00
|
|
|
local db_stage = { stage: stages.tests },
|
2017-06-13 03:55:12 +00:00
|
|
|
local dbname = 'quay',
|
2017-06-20 09:30:27 +00:00
|
|
|
|
2017-06-13 03:55:12 +00:00
|
|
|
postgres: db_stage + baseJob.dbTest('postgresql',
|
|
|
|
image='postgres:9.6',
|
|
|
|
env={ POSTGRES_PASSWORD: dbname, POSTGRES_USER: dbname }),
|
|
|
|
|
|
|
|
mysql: db_stage + baseJob.dbTest('mysql+pymysql',
|
|
|
|
image='mysql:latest',
|
|
|
|
env={ [key]: dbname for key in ['MYSQL_ROOT_PASSWORD', 'MYSQL_DATABASE',
|
|
|
|
'MYSQL_USER', 'MYSQL_PASSWORD'] }),
|
|
|
|
|
2017-07-16 23:24:31 +00:00
|
|
|
"deploy-preview": baseJob.QuayDeploy {
|
2017-07-19 22:34:08 +00:00
|
|
|
local _vars = self.localvars,
|
|
|
|
stage: stages.deploy_preview,
|
|
|
|
when: "manual",
|
|
|
|
environment+: {
|
|
|
|
on_stop: "stop-preview",
|
|
|
|
},
|
2017-07-16 23:24:31 +00:00
|
|
|
} + onlyBranch,
|
|
|
|
|
|
|
|
"stop-preview": baseJob.QuayDeployStop {
|
2017-07-19 22:34:08 +00:00
|
|
|
when: "manual",
|
|
|
|
stage: stages.deploy_preview,
|
|
|
|
script: [
|
|
|
|
"kubectl delete ns $K8S_NAMESPACE",
|
|
|
|
"kubectl get pods -o wide -n $K8S_NAMESPACE"
|
|
|
|
]
|
2017-07-16 23:24:31 +00:00
|
|
|
} + onlyBranch,
|
|
|
|
|
2017-07-19 22:34:08 +00:00
|
|
|
"deploy-staging": baseJob.QuayDeploy {
|
|
|
|
local _vars = self.localvars,
|
|
|
|
localvars+:: {
|
|
|
|
image: images.release,
|
|
|
|
domain: "quay-staging.k8s.devtable.com",
|
|
|
|
namespace: "ci-staging",
|
|
|
|
channels: ['master' , 'beta', 'latest'],
|
|
|
|
},
|
|
|
|
stage: stages.deploy_staging,
|
|
|
|
script+: [],
|
|
|
|
environment+: {
|
|
|
|
name: "staging",
|
|
|
|
},
|
|
|
|
only: ['master']
|
|
|
|
},
|
|
|
|
|
2017-06-13 03:55:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
stages: stages_list,
|
|
|
|
variables: vars.global,
|
|
|
|
} + jobs
|