def install(kubeb, version): """ Install current application to Kubernetes Generate Helm chart value file with docker image version If version is not specified, will get the latest version """ if not file_util.config_file_exist(): kubeb.log('Kubeb config file not found') return if config.get_local(): deploy_version = config.get_version(version) if not deploy_version: kubeb.log('No deployable version found') return kubeb.log('Deploying version: %s', deploy_version["tag"]) file_util.generate_helm_file(config.get_template(), config.get_image(), config.get_ext_template(), deploy_version["tag"], config.get_current_environment()) else: file_util.generate_helm_file(config.get_template(), config.get_image(), config.get_ext_template(), "latest", config.get_current_environment()) status, output, err = command.run(command.install_command()) if status != 0: kubeb.log('Install application failed', err) return kubeb.log(output) kubeb.log('Install application succeed.')
def build(kubeb, message): """ Build current application Build Dockerfile image Add release note, tag to config file """ if not file_util.config_file_exist(): kubeb.log('Kubeb config file not found in %s', file_util.kubeb_directory) exit(1) if not message: marker = '# Add release note:' hint = ['', '', marker] message = click.edit('\n'.join(hint)) msg = message.split(marker)[0].rstrip() if not msg: msg = "" else: msg = '\n'.join(message) if config.get_local(): image = config.get_image() tag = 'v' + str(int(round(time.time() * 1000))) status, output, err = command.run(command.build_command(image, tag)) if status != 0: kubeb.log('Docker image build failed', err) return kubeb.log(output) kubeb.log('Docker image build succeed.') config.add_version(tag, msg)
def build(self, message, push): if not file_util.config_file_exist(): self.log('Kubeb config file not found in %s', file_util.kubeb_directory) exit(1) if not message: marker = '# Add release note:' hint = ['', '', marker] message = click.edit('\n'.join(hint)) msg = message.split(marker)[0].rstrip() if not msg: msg = "" else: msg = '\n'.join(message) image = config.get_image() tag = 'v' + str(int(round(time.time() * 1000))) self.log('Building docker image {}:{}...'.format(image, tag)) spinner.start() status = util.run_docker_build(image, tag, os.getcwd()) spinner.stop() if status != 0: self.log('Docker image build failed') return else: self.log('Docker image build succeed.') if push: spinner.start() status = util.run_docker_push(image, tag) spinner.stop() if status != 0: self.log('Docker image push failed') return else: self.log('Docker image push succeed.') config.add_version(tag, msg)
def deploy(self, version, options, dry_run, rollback=True): if not file_util.config_file_exist(): self.log('Kubeb config file not found') return deploy_version = config.get_version(version) if not deploy_version: self.log('No deployable version found') return self.log('Deploying version: %s', deploy_version["tag"]) file_util.generate_helm_file(config.get_template(), config.get_ext_template(), config.get_image(), deploy_version["tag"], config.get_current_environment()) if options and not dry_run: self.log('Saving deploy options ...') file_util.save_deploy_options(options) self.log('Installing application ...') spinner.start() status = util.run_helm_install(config.get_name(), config.get_template(), dry_run, options) spinner.stop() if status != 0: self.log('Install application failed.') if dry_run is False and rollback: last_working_revision = util.get_last_working_revision( config.get_name()) if not last_working_revision: self.log('Last working revision not found. Skip rollback') return self.log( 'Rollback application to last working revision {}'.format( last_working_revision)) self.rollback(last_working_revision) else: self.log('Install application succeed.')
def push(self, version=None): if not file_util.config_file_exist(): self.log('Kubeb config file not found') return deploy_version = config.get_version(version) if not deploy_version: self.log('No deploy version found') return image = config.get_image() self.log('docker push {}:{}'.format(image, deploy_version["tag"])) spinner.start() status = util.run_docker_push(image, deploy_version["tag"]) spinner.stop() if status != 0: self.log('Docker image push failed') else: self.log('Docker image push succeed.')