GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

_image_version()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
import copy
2
import os
3
4
from fabric.api import local, prompt
5
from fabric.contrib.console import confirm
6
import yaml
7
from git import repo
8
9
10
11
def _image_version(config):
12
    """
13
    Returns the image and version from a Kubernetes config
14
    """
15
    image_version = config['spec']['template']['spec']['containers'][0]['image']
16
    image, version = image_version.split(':')
17
    return image, version
18
19
def _tag(image, version):
20
    return image + ':' + str(version)
21
22
def _build(image, version, directory):
23
    """
24
    Builds a docker image from directory after confirmation
25
    """
26
    tag = _tag(image, version)
27
    if confirm('Build new {t}?'.format(t=tag)):
28
        print('')
29
        local('docker build -t {t} {d}'.format(t=tag, d=directory))
30
31
def _push(image, version):
32
    """
33
    Pushes image to gcloud
34
    """
35
    tag = _tag(image, version)
36
    if confirm('Push image {t} to gcloud?'.format(t=tag)):
37
        print('')
38
        local('gcloud docker -- push {t}'.format(t=tag))
39
40
41
def deploy_web():
42
    """
43
    Deploy the updated web container to kubernetes
44
    """
45
    config_path = 'k8s/web.yaml'
46
47
    with open(config_path) as f:
48
        config = yaml.safe_load(f)
49
        image, version = _image_version(config)
50
    
51
    print('Current version {v} for image {i}'.format(v=version, i=image))
52
53
    new_version = prompt('New version:')
54
    print('')
55
56
    _build(image, new_version, '.')
57
    print('')
58
    
59
    _push(image, new_version)
60
    print('')