<commit_before>#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
Builds a docker image for a simple project

Usage:
  build_docker_image.py --project=<name> [--variant=<variant>]
  build_docker_image.py -h | --help

Options:
  -h --help                Show this screen.
  --project=<project>      Name of the project (e.g. api, loris).  Assumes
                           there's a folder containing a Dockerfile with the
                           same name.
  --variant=<variant>      The optional variant of this project (e.g. nginx).
                           Relies on the Dockerfile accepting a variant ENV.
"""

import os
import sys

import docopt
import docker

from tooling import write_release_id, CURRENT_COMMIT, ROOT


if __name__ == '__main__':
    args = docopt.docopt(__doc__)

    variant = args['--variant']
    project = args['--project']

    print('*** Building image for %s' % project)

    release_id = CURRENT_COMMIT

    if variant is not None:
        tag = '%s_%s:%s' % (project, variant, release_id)
    else:
        tag = '%s:%s' % (project, release_id)

    print('*** Image will be tagged %s' % tag)

    print('*** Building the new image')
    client = docker.from_env()
    client.images.build(
        path=os.path.join(ROOT, 'docker', project),
        buildargs={'variant': variant},
        tag=tag
    )

    print('*** Saving the release ID to .releases')
    write_release_id(project=project, release_id=release_id)<commit_msg>fix variant project name in build_docker_image.py<commit_after>#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
Builds a docker image for a simple project

Usage:
  build_docker_image.py --project=<name> [--variant=<variant>]
  build_docker_image.py -h | --help

Options:
  -h --help                Show this screen.
  --project=<project>      Name of the project (e.g. api, loris).  Assumes
                           there's a folder containing a Dockerfile with the
                           same name.
  --variant=<variant>      The optional variant of this project (e.g. nginx).
                           Relies on the Dockerfile accepting a variant ENV.
"""

import os

import docopt
import docker

from tooling import write_release_id, CURRENT_COMMIT, ROOT


if __name__ == '__main__':
    args = docopt.docopt(__doc__)

    variant = args['--variant']
    project = args['--project']

    print('*** Building image for %s' % project)

    release_id = CURRENT_COMMIT

    if variant is not None:
        tag = '%s_%s:%s' % (project, variant, release_id)
        release_name = '%s_%s' % (project, variant)
    else:
        tag = '%s:%s' % (project, release_id)
        release_name = project

    print('*** Image will be tagged %s' % tag)

    print('*** Building the new image')
    client = docker.from_env()
    client.images.build(
        path=os.path.join(ROOT, 'docker', project),
        buildargs={'variant': variant},
        tag=tag
    )

    print('*** Saving the release ID to .releases')
    write_release_id(project=release_name, release_id=release_id)
{'fraction_non_alphanumeric': 0.12471358428805238, 'fraction_numerical': 0.001309328968903437, 'mean_word_length': 2.4648526077097506, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855663', 'n_tokens_mistral': 975, 'n_tokens_neox': 922, 'n_words': 282}