Commit 4a3d5311 authored by Afraz Ahmadzadeh's avatar Afraz Ahmadzadeh

Multiple files simultaniously

parent 9da383ef
Pipeline #2024 passed with stages
in 1 minute and 27 seconds
stages:
- python
# - docker
- docker
build_and_upload_python_package:
image: python:3.7.3
......@@ -13,22 +13,22 @@ build_and_upload_python_package:
only:
- tags
# build_and_upload_image:
# image: docker:stable
# stage: docker
# services:
# - docker:dind
# dependencies:
# - build_and_upload_python_package
# variables:
# DOCKER_HOST: tcp://docker:2375
# DOCKER_DRIVER: overlay2
# AKINAKA_VERSION: $CI_COMMIT_TAG
# script:
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.olindata.com
# - docker build --build-arg AKINAKA_VERSION=${AKINAKA_VERSION} -t registry.olindata.com/olindata/akinaka/akinaka:$CI_COMMIT_TAG .
# - docker push registry.olindata.com/olindata/akinaka/akinaka:$CI_COMMIT_TAG
# when: delayed
# start_in: 5 seconds
# only:
# - tags
build_and_upload_image:
image: docker:stable
stage: docker
services:
- docker:dind
dependencies:
- build_and_upload_python_package
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
AKINAKA_VERSION: $CI_COMMIT_TAG
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.olindata.com
- docker build --build-arg AKINAKA_VERSION=${AKINAKA_VERSION} -t registry.olindata.com/olindata/akinaka/akinaka:$CI_COMMIT_TAG .
- docker push registry.olindata.com/olindata/akinaka/akinaka:$CI_COMMIT_TAG
when: delayed
start_in: 5 seconds
only:
- tags
......@@ -11,13 +11,13 @@ def k8s():
pass
@k8s.command()
@click.option("--application", required=True, help="The container to update")
@click.option("--applications", required=True, help="Comma separated list of containers to update")
@click.option("--new-image", help="Full image path, minus the tag")
@click.option("--new-tag", help="Tag to update the container's image to")
@click.option("--file-path", default="kubernetes/deployment.yml", help="Alternative path to deployment spec. Defaults to 'kubernetes/deployment.yml'")
@click.option("--file-paths", required=True, help="Comma separated string with paths to deployment specs")
@click.option("--dry-run", is_flag=True, help="If passed, then the new config is written to stdout instead of the originating file")
def update_deployment(application, new_image, new_tag, file_path, dry_run):
def update_deployment(applications, new_image, new_tag, file_paths, dry_run):
from .update_deployment import update_deployment
k8s_update = update_deployment.UpdateDeployment(application, new_image, new_tag, file_path, dry_run)
k8s_update = update_deployment.UpdateDeployment(applications, new_image, new_tag, file_paths, dry_run)
k8s_update.write_new_spec()
......@@ -9,22 +9,22 @@ import logging
class UpdateDeployment():
"""Modify a Kubernetes YAML deployment spec"""
def __init__(self, application, new_image=None, new_tag=None, file_path=None, dry_run=False):
self.application = application
def __init__(self, applications, new_image=None, new_tag=None, file_paths=None, dry_run=False):
self.applications = [x.strip() for x in applications.split(',')]
self.new_image = new_image
self.new_tag = new_tag
self.file_path = file_path
self.file_paths = [x.strip() for x in file_paths.split(',')]
self.dry_run = dry_run
if not self.new_image and not self.new_tag:
logging.error("At least --new-image or --new-tag need to be given")
exit(1)
def read_specs(self):
def read_specs(self, file_path):
yammies = []
try:
with open(self.file_path, 'r') as stream:
with open(file_path, 'r') as stream:
try:
for yammy in yaml.safe_load_all(stream):
yammies.append(yammy)
......@@ -37,8 +37,8 @@ class UpdateDeployment():
logging.error(exception)
exit(1)
def update_spec(self):
specs = self.read_specs()
def update_spec(self, file_path):
specs = self.read_specs(file_path)
for spec in specs:
if spec['kind'] == 'Deployment' or spec['kind'] == 'Pod':
......@@ -50,7 +50,7 @@ class UpdateDeployment():
exit(1)
for container in spec_path:
if container['name'] == self.application:
if container['name'] in self.applications:
if self.new_image:
image = self.new_image
else:
......@@ -66,11 +66,13 @@ class UpdateDeployment():
return specs
def write_new_spec(self):
new_spec = yaml.dump_all(self.update_spec(), default_flow_style=False)
if not self.dry_run:
spec_file = open(self.file_path, "w")
spec_file.write(new_spec)
spec_file.close()
else:
print(new_spec)
for file_path in self.file_paths:
new_spec = yaml.dump_all(self.update_spec(file_path), default_flow_style=False)
if not self.dry_run:
spec_file = open(file_path, "w")
spec_file.write(new_spec)
spec_file.close()
else:
print(new_spec)
......@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="akinaka",
python_requires='>=3.3.0',
version="0.2.21",
version="0.2.22",
author="Afraz",
author_email="afraz@olindata.com",
description="OlinData's aws cli Extras",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment