Exemple #1
0
def test(debug, sbt_cmd, user, user_home):
    print("=========================================")
    print("CI environment detected [" + OS_TYPE + "]")
    print("Running container user as " + user)
    print("Test commencing")
    print("=========================================")

    try:
        postgres = PostgresContainer("postgres:9.6")
        postgres.POSTGRES_DB = environ.get("POSTGRES_DB")
        postgres.POSTGRES_USER = environ.get("POSTGRES_USER")
        postgres.POSTGRES_PASSWORD = environ.get("POSTGRES_PASSWORD")
        with postgres.with_name("random_menu_selector_db") as db:
            system("docker network create random_menu_selector_network")
            system(
                "docker network connect random_menu_selector_network random_menu_selector_db"
            )
            system("mkdir -p ${HOME}/.sbt && mkdir -p ${HOME}/.ivy2")
            test = " && ".join([
                "sbt compile",  # Liquibase requires db jar dependency
                "db/evolve.sh",
                "sbt " + ["", "-jvm-debug 5005"][debug] + " \\\"" + sbt_cmd +
                "\\\"",
            ])
            system(" ".join([
                "docker run",
                "--name",
                "random_menu_selector_build",
                "--network",
                "random_menu_selector_network",
                "--env-file",
                "${PWD}/test.env",
                ["", "-p 5005:5005"][debug],
                "-u",
                user,
                "-w",
                user_home + "/random_menu_selector",
                "-v",
                "/var/run/docker.sock:/var/run/docker.sock",
                "-v",
                "${HOME}/.ivy2:" + user_home + "/.ivy2",
                "-v",
                "${HOME}/.sbt:" + user_home + "/.sbt",
                "-v",
                "${PWD}/..:" + user_home + "/random_menu_selector",
                "fsw0422/random_menu_selector/cicd:latest",
                "bash -c \"{cmd}\"".format(cmd=test),
            ]))
    finally:
        system("docker rm -f random_menu_selector_build")
        system("docker rm -f random_menu_selector_db")
        system("printf 'y\n' | docker network prune")
        system("printf 'y\n' | docker volume prune")
Exemple #2
0
def psql():
    """
    We need to modify the Flask Application to accept a seperate
    sessionmaker for testing. !TODO
    """
    psql_container = PostgresContainer("postgres:9.6")
    psql_container.POSTGRES_USER = "******"
    psql_container.POSTGRES_PASSWORD = "******"
    psql_container.POSTGRES_DB = "test"
    psql_container.start()

    engine = sqlalchemy.create_engine(psql_container.get_connection_url())

    session = sessionmaker(bind=engine)()

    # alert webservice to port for this database
    port = psql_container.get_connection_url().split(":")[-1].split("/")[0]
    header = copy.copy(TEST_HEADER)
    header["port"] = port

    return {"container": psql_container, "session": session, "header": header}