<commit_before>#!/usr/bin/env python3
# Skier docker container launcher.
# This file is licenced under the MIT Licence.
# For more information, view the LICENCE file.

import argparse
import copy
import os
import subprocess
import sys


green = "\033[0;32m"
red = "\033[0;31m"
blue = "\033[0;34m"
purple = "\033[0;35m"
normal = "\033[0m"

def _build_image(target, from_local: bool=False, local_image: str="skier-base"):
    # Build the desired image.
    command = ["docker", "build"]
    dir = target
    if not os.path.exists(dir):
        print(red + "STOP: Target {} does not exist.".format(target) + normal, file=sys.stderr)
        sys.exit(1)
    print(green + "LAUNCH: Beginning build of target {} {}".format(dir, "from local image {}".format(local_image) if from_local else "") + normal)
    # First, replace any FROM images if defined.
    with open(dir + "/Dockerfile", "r") as f:
        lines = f.readlines()
        nlines = copy.copy(lines)
        for num, line in enumerate(lines):
            if '#!~replace' in line:
                if from_local:
                    nlines[num+1] = "FROM {}\n".format(local_image)
                    break
        del lines
        nf = open("{t}/Dockerfile-temp-{t}".format(t=target), 'w')
        nf.write(''.join(nlines))
        nf.close()

    command.extend(["-t", "{}".format(target if target != "base" else "skier-base")])
    command.extend(["--no-cache"])
    command.extend(["--file={t}/Dockerfile-temp-{t}".format(t=target)])
    command.extend([dir])
    print(blue + "BUILD: Running command \"{}\"".format(' '.join(command)) + normal)
    proc = subprocess.Popen(command)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BUILD: Build failed with non-zero exit code {}".format(proc.returncode) + normal)
    else:
        print(green + "BUILD: Build completed successfully." + normal)

def _bootstrap(from_local: bool=False, local_image="skier"):
    currdir = os.getcwd() + "/" # Safety first!

    if not from_local:
        local_image = "skier"

    basecommand = ["docker", "run"]

    print(purple + "LAUNCH: Beginning bootstrap for new Skier app...")
    print("LAUNCH: Using base image {}".format(local_image) + normal)

    print(purple + "BOOTSTRAP: Building data-only container..." + normal)

    dataonlycmd = basecommand + ["--name", "skier-keyring", "-v", "{}:/var/skier/keyring".format(currdir + "keyring/"), "ubuntu:15.04", "true"]

    proc = subprocess.Popen(dataonlycmd)
    proc.wait()
    if proc.returncode != 0:
        print(blue + "BOOTSTRAP: Data-only container already exists.")

    print(purple + "BOOTSTRAP: Building redis container..." + normal)

    rediscmd = basecommand + ["--name", "skier-redis", "-d", "redis", "redis-server"]

    proc = subprocess.Popen(rediscmd)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BOOTSTRAP: Redis container failed to start." + normal, file=sys.stderr)
        sys.exit(1)

    print(purple + "BOOTSTRAP: Verifying first launch of Skier container..." + normal)
    skiercmd = basecommand + ["--name", "skier", "--volumes-from", "skier-keyring", local_image, "true"]
    proc = subprocess.Popen(skiercmd)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BOOTSTRAP: Building Skier container failed with non-zero exit code {}".format(proc.returncode) + normal, file=sys.stderr)<commit_msg>Remove sextion about data-only container.<commit_after>#!/usr/bin/env python3
# Skier docker container launcher.
# This file is licenced under the MIT Licence.
# For more information, view the LICENCE file.

import argparse
import copy
import os
import subprocess
import sys


green = "\033[0;32m"
red = "\033[0;31m"
blue = "\033[0;34m"
purple = "\033[0;35m"
normal = "\033[0m"

def _build_image(target, from_local: bool=False, local_image: str="skier-base"):
    # Build the desired image.
    command = ["docker", "build"]
    dir = target
    if not os.path.exists(dir):
        print(red + "STOP: Target {} does not exist.".format(target) + normal, file=sys.stderr)
        sys.exit(1)
    print(green + "LAUNCH: Beginning build of target {} {}".format(dir, "from local image {}".format(local_image) if from_local else "") + normal)
    # First, replace any FROM images if defined.
    with open(dir + "/Dockerfile", "r") as f:
        lines = f.readlines()
        nlines = copy.copy(lines)
        for num, line in enumerate(lines):
            if '#!~replace' in line:
                if from_local:
                    nlines[num+1] = "FROM {}\n".format(local_image)
                    break
        del lines
        nf = open("{t}/Dockerfile-temp-{t}".format(t=target), 'w')
        nf.write(''.join(nlines))
        nf.close()

    command.extend(["-t", "{}".format(target if target != "base" else "skier-base")])
    command.extend(["--no-cache"])
    command.extend(["--file={t}/Dockerfile-temp-{t}".format(t=target)])
    command.extend([dir])
    print(blue + "BUILD: Running command \"{}\"".format(' '.join(command)) + normal)
    proc = subprocess.Popen(command)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BUILD: Build failed with non-zero exit code {}".format(proc.returncode) + normal)
    else:
        print(green + "BUILD: Build completed successfully." + normal)

def _bootstrap(from_local: bool=False, local_image="skier"):
    currdir = os.getcwd() + "/" # Safety first!

    if not from_local:
        local_image = "skier"

    basecommand = ["docker", "run"]

    print(purple + "LAUNCH: Beginning bootstrap for new Skier app...")
    print("LAUNCH: Using base image {}".format(local_image) + normal)


    print(purple + "BOOTSTRAP: Building redis container..." + normal)

    rediscmd = basecommand + ["--name", "skier-redis", "-d", "redis", "redis-server"]

    proc = subprocess.Popen(rediscmd)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BOOTSTRAP: Redis container failed to start." + normal, file=sys.stderr)
        sys.exit(1)

    print(purple + "BOOTSTRAP: Verifying first launch of Skier container..." + normal)
    skiercmd = basecommand + ["--name", "skier", "--volumes-from", "skier-keyring", local_image, "true"]
    proc = subprocess.Popen(skiercmd)
    proc.wait()
    if proc.returncode != 0:
        print(red + "BOOTSTRAP: Building Skier container failed with non-zero exit code {}".format(proc.returncode) + normal, file=sys.stderr)
{'fraction_non_alphanumeric': 0.15961268155552086, 'fraction_numerical': 0.011713259409651726, 'mean_word_length': 3.0972488803582854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6218192', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2065, 'n_words': 544}