Add delete preview-env / auto-deploy a staging

This commit is contained in:
Antoine Legrand 2017-07-20 00:34:08 +02:00
parent 1d0313229e
commit a55693f967
10 changed files with 136 additions and 91 deletions

View file

@ -6,13 +6,13 @@ local baseJob = (import '.gitlab-ci/base_jobs.libsonnet')(vars);
local stages_list = [ local stages_list = [
// gitlab-ci stages // gitlab-ci stages
'deploy',
'docker_build',
'docker_base', 'docker_base',
'docker_build',
'deploy_preview',
'unit_tests', 'unit_tests',
'integration', 'integration',
'docker_release', 'docker_release',
'deploy_staging',
'teardown', 'teardown',
]; ];
@ -94,12 +94,39 @@ local jobs = {
'MYSQL_USER', 'MYSQL_PASSWORD'] }), 'MYSQL_USER', 'MYSQL_PASSWORD'] }),
"deploy-preview": baseJob.QuayDeploy { "deploy-preview": baseJob.QuayDeploy {
environment+: {on_stop: "stop-preview"}, local _vars = self.localvars,
stage: stages.deploy_preview,
when: "manual",
environment+: {
on_stop: "stop-preview",
},
} + onlyBranch, } + onlyBranch,
"stop-preview": baseJob.QuayDeployStop { "stop-preview": baseJob.QuayDeployStop {
when: "manual",
stage: stages.deploy_preview,
script: [
"kubectl delete ns $K8S_NAMESPACE",
"kubectl get pods -o wide -n $K8S_NAMESPACE"
]
} + onlyBranch, } + onlyBranch,
"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']
},
}; };
{ {

View file

@ -50,6 +50,10 @@ container-release:
deploy-preview: deploy-preview:
before_script: before_script:
- appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io - appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io
- cd deploy/quay-ci-app
- echo -n 1.0.0-${CI_COMMIT_REF_SLUG} > VERSION
- 'echo "{\"domain\": \"$QUAY_DOMAIN\", \"image\": \"quay.io/quay/quay-ci:${CI_COMMIT_REF_SLUG}\", \"tag\": \"${CI_COMMIT_REF_SLUG}\"}" > params.json'
- cat params.json
environment: environment:
name: review/${CI_COMMIT_REF_SLUG} name: review/${CI_COMMIT_REF_SLUG}
on_stop: stop-preview on_stop: stop-preview
@ -58,17 +62,42 @@ deploy-preview:
only: only:
- branches - branches
script: script:
- cd deploy/quay-demo-app - appr push quay.io/quay/quay-ci-app -f
- echo -n 1.0.0-${CI_COMMIT_REF_SLUG} > VERSION - appr deploy quay.io/quay/quay-ci-app@1.0.0-${CI_COMMIT_REF_SLUG} --namespace ci-quay-${CI_COMMIT_REF_SLUG} -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS
- 'echo "{\"image\": \"quay.io/quay/quay-ci:${CI_COMMIT_REF_SLUG}\", \"tag\": \"${CI_COMMIT_REF_SLUG}\"}" > params.json'
- cat params.json
- appr push quay.io/quay -f
- appr deploy quay.io/quay/quay-demo-app@1.0.0-${CI_COMMIT_REF_SLUG} --namespace ci-quay-${CI_COMMIT_REF_SLUG} -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS
- kubectl get ingresses -n ci-quay-${CI_COMMIT_REF_SLUG} -o wide - kubectl get ingresses -n ci-quay-${CI_COMMIT_REF_SLUG} -o wide
stage: deploy stage: deploy_preview
tags: tags:
- kubernetes - kubernetes
variables:
K8S_NAMESPACE: ci-quay-${CI_COMMIT_REF_SLUG}
QUAY_DOMAIN: quay-${CI_COMMIT_REF_SLUG}.k8s.devtable.com
when: manual when: manual
deploy-staging:
before_script:
- appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io
- cd deploy/quay-ci-app
- echo -n 1.0.0-${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA} > VERSION
- 'echo "{\"domain\": \"$QUAY_DOMAIN\", \"image\": \"quay.io/quay/quay:${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}\", \"tag\": \"${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}\"}" > params.json'
- cat params.json
environment:
name: staging
url: https://quay-staging.k8s.devtable.com
image: quay.io/appr/appr:kubectl
only:
- master
script:
- appr push quay.io/quay/quay-ci-app -f
- appr push quay.io/quay/quay-ci-app -c master
- appr push quay.io/quay/quay-ci-app -c beta
- appr push quay.io/quay/quay-ci-app -c latest
- appr deploy quay.io/quay/quay-ci-app@1.0.0-${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA} --namespace ci-staging -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS
- kubectl get ingresses -n ci-staging -o wide
stage: deploy_staging
tags:
- kubernetes
variables:
K8S_NAMESPACE: ci-staging
QUAY_DOMAIN: quay-staging.k8s.devtable.com
karma-tests: karma-tests:
before_script: before_script:
- cd $QUAYDIR - cd $QUAYDIR
@ -152,16 +181,16 @@ registry-tests:
QUAYDIR: /quay-registry QUAYDIR: /quay-registry
TEST: 'true' TEST: 'true'
stages: stages:
- deploy
- docker_build
- docker_base - docker_base
- docker_build
- deploy_preview
- unit_tests - unit_tests
- integration - integration
- docker_release - docker_release
- deploy_staging
- teardown - teardown
stop-preview: stop-preview:
before_script: before_script: []
- appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io
environment: environment:
action: stop action: stop
name: review/${CI_COMMIT_REF_SLUG} name: review/${CI_COMMIT_REF_SLUG}
@ -170,15 +199,15 @@ stop-preview:
only: only:
- branches - branches
script: script:
- 'echo "{\"image\": \"quay.io/quay/quay-ci:${CI_COMMIT_REF_SLUG}\", \"tag\": \"${CI_COMMIT_REF_SLUG}\"}" > params.json' - kubectl delete ns $K8S_NAMESPACE
- cat params.json - kubectl get pods -o wide -n $K8S_NAMESPACE
- appr remove quay.io/quay/quay-demo-app@1.0.0-${CI_COMMIT_REF_SLUG} --namespace ci-quay-${CI_COMMIT_REF_SLUG} -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS -x params.json stage: deploy_preview
- kubectl get pods -n ci-quay-${CI_COMMIT_REF_SLUG} -o wide
stage: deploy
tags: tags:
- kubernetes - kubernetes
variables: variables:
GIT_STRATEGY: none GIT_STRATEGY: none
K8S_NAMESPACE: ci-quay-${CI_COMMIT_REF_SLUG}
QUAY_DOMAIN: quay-${CI_COMMIT_REF_SLUG}.k8s.devtable.com
when: manual when: manual
unit-tests: unit-tests:
before_script: before_script:

View file

@ -35,44 +35,70 @@ function(vars={})
], ],
}, },
local appversion = "1.0.0-%s" % vars.images.quayci.tag,
local namespace = "ci-quay-%s" % vars.images.quayci.tag,
QuayDeploy: { 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", image: "quay.io/appr/appr:kubectl",
when: "manual",
environment: { environment: {
name: "review/%s" % vars.images.quayci.tag, name: "review/%s" % _vars.image.tag,
url: "https://quay-%s.k8s.devtable.com" % vars.images.quayci.tag, url: "https://%s" % _vars.domain,
}, },
tags: [ tags: [
"kubernetes", "kubernetes",
], ],
stage: "deploy",
before_script: [ before_script: [
"appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io", "appr login -u $DOCKER_USER -p $DOCKER_PASS quay.io",
], "cd deploy/%s" % _vars.appname,
script: [ ] + _vars.buildParams(),
"cd deploy/quay-demo-app",
"echo -n %s > VERSION" % appversion, script:
'echo "{\\"image\\": \\"%s\\", \\"tag\\": \\"%s\\"}" > params.json' % [vars.images.quayci.name, vars.images.quayci.tag], _vars.pushApp(_vars.apprepo, _vars.pushargs, _vars.channels) +
"cat params.json", [
"appr push quay.io/quay -f", "appr deploy %s@%s --namespace %s -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS" % [
"appr deploy quay.io/quay/quay-demo-app@%s --namespace %s -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS" % [appversion, namespace], _vars.apprepo,
"kubectl get ingresses -n %s -o wide" % namespace, _vars.appversion,
_vars.namespace],
"kubectl get ingresses -n %s -o wide" % _vars.namespace,
], ],
}, },
QuayDeployStop: self.QuayDeploy { QuayDeployStop: self.QuayDeploy {
variables: {GIT_STRATEGY: "none"}, variables+: {GIT_STRATEGY: "none"},
environment+: { environment+: {
action: "stop" action: "stop"
}, },
script: [ before_script: [],
'echo "{\\"image\\": \\"%s\\", \\"tag\\": \\"%s\\"}" > params.json' % [vars.images.quayci.name, vars.images.quayci.tag], script: [],
"cat params.json",
"appr remove quay.io/quay/quay-demo-app@%s --namespace %s -x docker_user=$DOCKER_USER -x docker_pass=$DOCKER_PASS -x params.json" % [appversion, namespace],
"kubectl get pods -n %s -o wide" % namespace,
],
}, },
dbTest(scheme, image, env):: self.QuayTest { dbTest(scheme, image, env):: self.QuayTest {

View file

@ -8,12 +8,11 @@ local utils = import "utils.libsonnet";
// internal variables // internal variables
images: { images: {
// Quay initial image, used in the FROM clause // Quay initial image, used in the Dockerfile FROM clause
base: { repo: "quay.io/quay/quay-base", tag: "latest", base: { repo: "quay.io/quay/quay-base", tag: "latest",
name: utils.containerName(self.repo, self.tag), 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 is a copy of the quayci image to the 'prod' repository
release: { repo: "quay.io/quay/quay", release: { repo: "quay.io/quay/quay",
tag: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}", tag: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}",

View file

@ -1,37 +0,0 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: quay-dev-initdb
spec:
activeDeadlineSeconds: 100
template:
metadata:
name: quay-dev-initdb
spec:
containers:
- name: quay
image: quay.io/quay/quay-ci:master
env:
- name: TEST_DATABASE_URI
value: "postgres://"
- name: SKIP_DB_SCHEMA
value: "true"
command:
- venv/bin/python
- initdb.py
volumeMounts:
- name: configvolume
readOnly: false
mountPath: /conf/stack
resources:
limits:
cpu: 500m
memory: 500Mi
imagePullSecrets:
- name: coreos-pull-secret
volumes:
- name: configvolume
secret:
secretName: quay-enterprise-config-secret
restartPolicy: Never

View file

@ -12,10 +12,10 @@ local local_stack_config = (
); );
# Merge all config together # Merge all config together
# Precedence: package-config (vars.config) < local stack/config.yaml < base-config (vars.base-config) # Precedence: local stack/config.yaml < package-config (vars.config) < base-config (vars.base-config)
local config_yaml = {'config.yaml': appr.b64encode(appr.to_yaml( local config_yaml = {'config.yaml': appr.b64encode(appr.to_yaml(
vars.config +
local_stack_config + local_stack_config +
vars.config +
vars.base_config))}; vars.base_config))};
# Merge stack files # Merge stack files

View file

@ -56,7 +56,8 @@ deploy: [
{ {
name: "quay/quay-app", name: "quay/quay-app",
variables: $.variables variables: $.variables,
version: ":stable"
}, },
# Deploy the initdb script # Deploy the initdb script

Binary file not shown.

View file

@ -109,7 +109,7 @@ class BaseProvider(object):
indicating that this container requires a restart. indicating that this container requires a restart.
""" """
raise NotImplementedError raise NotImplementedError
def get_volume_path(self, directory, filename): def get_volume_path(self, directory, filename):
""" Helper for constructing file paths, which may differ between providers. For example, """ Helper for constructing file paths, which may differ between providers. For example,
kubernetes can't have subfolders in configmaps """ kubernetes can't have subfolders in configmaps """

View file

@ -54,20 +54,20 @@ class KubernetesConfigProvider(FileConfigProvider):
self._update_secret_file(filename, contents) self._update_secret_file(filename, contents)
except IOError as ioe: except IOError as ioe:
raise CannotWriteConfigException(str(ioe)) raise CannotWriteConfigException(str(ioe))
def volume_file_exists(self, filename): def volume_file_exists(self, filename):
secret = self._lookup_secret() secret = self._lookup_secret()
if not secret or not secret.get('data'): if not secret or not secret.get('data'):
return False return False
return filename in secret['data'] return filename in secret['data']
def list_volume_directory(self, path): def list_volume_directory(self, path):
secret = self._lookup_secret() secret = self._lookup_secret()
if not secret: if not secret:
return [] return []
paths = [] paths = []
for filename in secret.get('data', {}): for filename in secret.get('data', {}):
if filename.startswith(path): if filename.startswith(path):
@ -150,4 +150,4 @@ class KubernetesConfigProvider(FileConfigProvider):
return session.send(request.prepare(), verify=False, timeout=2) return session.send(request.prepare(), verify=False, timeout=2)
def get_volume_path(self, directory, filename): def get_volume_path(self, directory, filename):
return "_".join([directory.rstrip('/'), filename]) return "_".join([directory.rstrip('/'), filename])