예제 #1
0
def setenvironment(c, cmd):
    """The task writes the local environment variables for django and docker, for example: development"""
    inv_logging.task(setenvironment.__name__)
    inv_logging.cmd(cmd)
    
    settings = inv_base.read_settings(cmd)
    development_dir = os.getcwd()
    if cmd == "production":
        filename = ".env.production"
    else:
        filename = ".env"

    dict_env = {
        "django": os.path.join(development_dir, f"django/djangoVue/{filename}"),
        "docker": os.path.join(development_dir, f"{filename}")
    }

    for dict_env_key, dict_env_file in dict_env.items():
        try:
            with open(dict_env_file, "w") as f:
                for key, value in settings[dict_env_key].items():                          
                    f.write(f"{key}={value}\n")
                f.close()
            logging.info(f"The environment variable for '{dict_env_key}'' from the settings.json file was successfully written to the .env file.: '{dict_env_file}'")

        except:
            logging.error(
                f"It was not possible to write to the file: '{dict_env_file}'")
            sys.exit(1)

    inv_logging.success(setenvironment.__name__)
    return dict_env
예제 #2
0
def run(c, cmd):
    """Start a service from the Docker Compose file, for example: docker django"""
    inv_logging.task(run.__name__)
    user, group = inv_base.uid_gid(c)
    inv_logging.cmd(cmd)
    inv_base.docker_compose(c, f"run -u {user}:{group} {cmd}", pty=True)
    inv_logging.success(run.__name__)
예제 #3
0
def npm(c, cmd):
    """This task is used to respond to the packet manager npm, for example: npm install date-fns"""
    inv_logging.task(npm.__name__)
    user, group = inv_base.uid_gid(c)
    inv_logging.cmd(cmd)
    inv_base.docker_compose(c, f"run -u {user}:{group} node npm {cmd}", pty=True)
    inv_logging.success(npm.__name__)
예제 #4
0
def logs(c, cmd):
    """Show the log files from the Docker Services, for example: django"""
    inv_logging.task(logs.__name__)
    inv_base.docker_compose(c, 'logs -f {}'.format(cmd))
    inv_logging.cmd(cmd)
    inv_logging.success(logs.__name__)
예제 #5
0
def docker(c, cmd):
    """The Task can execute a Docker command including cmd: docker ps"""
    inv_logging.task(restart.__name__)
    inv_logging.cmd(cmd)
    inv_base.dockerdaemon(c, cmd)
    inv_logging.success(restart.__name__)