~cprov/tanuki-continuous-deployer/local-provider

« back to all changes in this revision

Viewing changes to cd.py

  • Committer: Thomi Richards
  • Date: 2015-07-17 06:02:44 UTC
  • Revision ID: thomi.richards@canonical.com-20150717060244-jngqosrn11qcx8ns
RemoveĀ unusedĀ code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    )
58
58
    parser.add_argument('--branch', required=True)
59
59
    parser.add_argument('--stage', required=True)
60
 
    parser.add_argument('--use-project-pool',
61
 
                        action='store_true', default=False)
62
60
 
63
61
    # Parse known arguments, collect (and augment) the rest as 'mojo_args'.
64
62
    args, mojo_args = parser.parse_known_args()
65
 
    if args.use_project_pool and '--project' in mojo_args:
66
 
        print("Error: Cannot specify both --use-project-pool and --project")
67
 
        return 1
68
63
 
69
64
    mojo_args.extend([
70
65
        '--branch', args.branch,
76
71
    logger = logging.getLogger()
77
72
    logger.setLevel(logging.INFO)
78
73
 
79
 
    # Optional remote logging via logstash.
80
 
    logstash_host = os.environ.get('CI_LOGSTASH_HOST')
81
 
    if logstash_host is not None:
82
 
        try:
83
 
            import logstash
84
 
        except ImportError:
85
 
            print('Follow the README instructions for installing '
86
 
                  'python-logstash')
87
 
            return 1
88
 
        else:
89
 
            logger.addHandler(
90
 
                logstash.LogstashHandler(logstash_host, 5959, 1))
91
 
 
92
74
    # Deploy new environment if the stage identifier isn't recorded.
93
75
    idenfifier_dir = os.path.expanduser('~/ci-cd-identifiers/')
94
76
    if not os.path.exists(idenfifier_dir):
100
82
 
101
83
    identifier_path = os.path.join(idenfifier_dir, identifier)
102
84
    if os.path.exists(identifier_path):
103
 
        return 0
104
 
 
105
 
    # Thomi - 2015-05-28: Transitional code to use the mojo project pool code.
106
 
    # Once this is in production we can make this the default. Until then,
107
 
    # this giant if statement determines if we use the pool or a dedicated
108
 
    # project from the command line:
109
 
    if args.use_project_pool:
110
 
        # use the project pool:
111
 
        pool = MojoProjectPool(
112
 
            MOJO_PROJECT_POOL_DIR,
113
 
            MOJO_PROJECT_POOL_LOCK_DIR
114
 
        )
115
 
        try:
116
 
            with pool.acquire_mojo_project() as project_name:
117
 
                # Register deployment identifier regardless its deployment
118
 
                # status. We don't want to deploy it again.
119
 
                with open(identifier_path, 'w') as fd:
120
 
                    fd.write(info + '\n')
121
 
 
122
 
                mojo_args += ['--project', project_name]
123
 
                status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
124
 
        except NoProjectError:
125
 
            print("No available mojo projects, not deploying.")
126
 
            print("Deployment will be retried next run.")
127
 
            return 0
128
 
    else:
129
 
        # Don't use the project pool - use whatever was supplied on the CLI:
130
 
        # Register deployment identifier regardless its deployment status.
131
 
        # We don't want to deploy it again.
132
 
        with open(identifier_path, 'w') as fd:
133
 
            fd.write(info + '\n')
134
 
        # `mojo.py` prints additional information to stdout, which is only
135
 
        # recorded locally, for now ...
136
 
        status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
 
85
        print("Not deploying as this combination of branches has already been")
 
86
        print("deployed. Remove '%s' and retry to override this." % identifier_path)
 
87
        return 0
 
88
 
 
89
    # use the project pool:
 
90
    pool = MojoProjectPool(
 
91
        MOJO_PROJECT_POOL_DIR,
 
92
        MOJO_PROJECT_POOL_LOCK_DIR
 
93
    )
 
94
    try:
 
95
        with pool.acquire_mojo_project() as project_name:
 
96
            # Register deployment identifier regardless its deployment
 
97
            # status. We don't want to deploy it again.
 
98
            with open(identifier_path, 'w') as fd:
 
99
                fd.write(info + '\n')
 
100
 
 
101
            mojo_args += ['--project', project_name]
 
102
            status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
 
103
    except NoProjectError:
 
104
        print("No available mojo projects, not deploying.")
 
105
        print("Deployment will be retried next run.")
 
106
        return 0
137
107
 
138
108
    # We only log a sucint but descriptive message about the deployment
139
109
    # status. This content will be shipped to logstash and be handled