-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtasks.py
More file actions
51 lines (42 loc) · 1.59 KB
/
tasks.py
File metadata and controls
51 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Invoke tasks."""
import json
import os
import shutil
import webbrowser
from invoke import task
HERE = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(HERE, "cookiecutter.json"), "r") as fp:
COOKIECUTTER_SETTINGS = json.load(fp)
# Match default value of project_slug from cookiecutter.json
COOKIECUTTER_SETTINGS["project_name"] = "Project Name"
COOKIECUTTER_SETTINGS["project_slug"] = "project_name"
COOKIE = os.path.join(HERE, COOKIECUTTER_SETTINGS["project_slug"])
REQUIREMENTS = os.path.join(COOKIE, "backend", "requirements", "development.txt")
@task
def build(ctx):
"""Build the cookiecutter."""
print('Making sure running cookiecutter with this folder works')
ctx.run(f"cookiecutter {HERE} --no-input")
@task
def clean(ctx):
"""Clean out generated cookiecutter."""
print('Cleaning out the generated cookiecutter')
if os.path.exists(COOKIE):
shutil.rmtree(COOKIE)
def _run_docker_compose(ctx, command, *args):
docker_compose_command = f"docker-compose {command}"
ctx.run(docker_compose_command, echo=True)
def _build_production_image(ctx):
print('Building production image')
ctx.run("docker build -t production:latest .")
@task(pre=[clean, build])
def test(ctx):
"""Run lint commands and tests."""
os.chdir(COOKIE)
_run_docker_compose(ctx, "build")
_run_docker_compose(ctx, "run --rm django pytest")
_run_docker_compose(ctx, 'run --rm react bash -c "node --version"')
_run_docker_compose(ctx, 'run --rm react bash -c "CI=true npm test"')
_build_production_image(ctx)