def main(args): config = Config() with repository_root(): with use_dir(Projects.BACKEND): log.info(f"Updating {args.environment} backend") run(["zappa", "update", args.environment]) log.info(f"Running migrations for {args.environment}") run(["zappa", "manage", args.environment, "migrate"]) with use_dir(Projects.FRONTEND): log.info(f"Updating {args.environment} frontend") run(["eb", "deploy", f"{config.name}-{args.environment}"])
def main(args): config = Config() ecs = boto3.client("ecs") with repository_root(): with use_dir(Projects.BACKEND): log.info(f"Updating {args.environment} backend") run(["zappa", "update", args.environment]) log.info(f"Running migrations for {args.environment}") run(["zappa", "manage", args.environment, "migrate"]) with use_dir(Projects.FRONTEND): log.info("Building frontend") image_name = f"{config.name}-frontend" latest = f"{image_name}:latest" git_commit_hash = get_git_commit_hash() tags = ["latest", f"{args.environment}", f"{git_commit_hash}"] run([ "docker", "build", "-t", f"{latest}", "-t", f"{image_name}:{args.environment}", "-t", f"{image_name}:{git_commit_hash}", ".", ]) for tag in tags: run([ "docker", "tag", f"{image_name}:{tag}", f"{ECR_REPO_PREFIX}/{image_name}:{tag}", ]) run([ "docker", "push", f"{ECR_REPO_PREFIX}/{image_name}:{tag}" ]) log.info( f"Updating service frontend-{args.environment} on {config.name} ECS cluster" ) ecs.update_service( cluster=f"{config.name}", service=f"frontend-{args.environment}", taskDefinition=f"{config.name}-frontend-{args.environment}", forceNewDeployment=True, )
def installed(self): with use_dir(Projects.FRONTEND): with open("package.json") as f: data = json.load(f) return ("pretty-quick" in data.get("devDependencies", {}) and "pretty-lint" in data["scripts"])
def installed(self): with use_dir(Projects.BACKEND): data = {} with open(zappa_settings) as f: data = json.load(f) return data["base"].get("project_name", None) is not None
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing frontend production dependencies") run(["yarn", "add", *self.dependencies]) log.info("Installing frontend dev dependencies") run(["yarn", "add", "--dev", *self.dev_dependencies])
def installed(self): with use_dir(Projects.FRONTEND): with open("package.json") as f: current = list(json.load(f).get("devDependencies", {}).keys()) return all(package in current for package in self.dependencies + self.plugins + self.configs)
def installed(self): with use_dir(Projects.BACKEND): return os.path.exists( os.path.join( Projects.BACKEND, "management", "commands", file_name, ), )
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing eslint dev dependencies to frontend") run(["yarn", "add", "--dev", *self.dependencies]) log.info("Installing eslint plugins to frontend") run(["yarn", "add", "--dev", *self.plugins]) log.info("Installing eslint configs to frontend") run(["yarn", "add", "--dev", *self.configs])
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing be-pretty into frontend project") run(["yarn", "add", "--dev", "[email protected]"]) log.info("Configuring be-pretty to use the correct RC file") run(["yarn", "run", "be-pretty", "setDefault"]) log.info("Formatting project with prettier") run(["yarn", "run", "be-pretty", "formatAll"])
def main(args): config = Config() with repository_root(): with use_dir(Projects.BACKEND): log.info(f"Updating {args.environment} backend") run(["zappa", "update", args.environment]) log.info(f"Running migrations for {args.environment}") run(["zappa", "manage", args.environment, "migrate"]) with use_dir(Projects.FRONTEND): log.info("Building frontend") image_name = f"{config.name}-frontend" latest = f"{image_name}:latest" run(["docker", "build", "-t", f"{image_name}", "."]) run([ "docker", "tag", f"{config.name}-frontend:latest", f"{ECR_REPO_PREFIX}/{latest}", ]) run(["docker", "push", f"{ECR_REPO_PREFIX}/{latest}"])
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing pretty-quick into frontend project") run(["yarn", "add", "--dev", "pretty-quick"]) log.info("Adding pretty-quick lint command") with open("package.json") as f: data = json.load(f) data["scripts"][ "pretty-lint"] = "pretty-quick --check --branch" log.info("Dumping new frontend package file") with open("package.json", "w") as f: json.dump(data, f)
def create(self): with use_dir(Projects.FRONTEND): log.info("Adding custom commands to package.json") data = {} with open("package.json") as package_file: data = json.load(package_file) data["scripts"][ "start"] = f"npm run build && NODE_ENV=production node {server_file}" data["scripts"]["dev"] = f"node {server_file}" log.info("Writing out custom commands") with open("package.json", "w") as package_file: json.dump(data, package_file)
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing frontend production dependencies") run(["yarn", "add", *self.dependencies]) log.info("Installing frontend dev dependencies") run(["yarn", "add", "--dev", *self.dev_dependencies]) log.info("Adding jest test commands") with open("package.json") as f: data = json.load(f) data["scripts"]["test"] = "jest" data["scripts"]["test-coverage"] = "jest --coverage" log.info("Dumping new frontend package file") with open("package.json", "w") as f: json.dump(data, f)
def installed(self): with use_dir(Projects.FRONTEND): with open("package.json") as f: data = json.load(f) def check(dependency_name, path): return dependency_name in data[path] for dep_set, path_key in [ [self.dependencies, "dependencies"], [self.dev_dependencies, "devDependencies"], ]: for dep in dep_set: if not check(dep, path_key): return False return True
def create(self): with use_dir(Projects.BACKEND): data = {} with open(zappa_settings) as f: data = json.load(f) log.info("Tweaking zappa settings to be specific to this app") data["base"]["project_name"] = f"{self.config.name}-backend" data["base"][ "s3_bucket"] = f"com.willing.{self.config.name}-deployments" data["base"]["certificate_arn"] = "REPLACE THIS TO DEPLOY" log.info("Writting out zappa settings") with open(zappa_settings, "w") as f: json.dump(data, f)
def create(self): with use_dir(Projects.BACKEND): log.info("Creating directory structure") os.makedirs(os.path.join(Projects.BACKEND, "management", "commands"), exist_ok=True) self._touch(os.path.join(Projects.BACKEND, "management", init_file)) self._touch( os.path.join(Projects.BACKEND, "management", "commands", init_file)) log.info("Copying command into project") with open( os.path.join(Projects.BACKEND, "management", "commands", file_name), "w") as f: f.write(il_resources.read_text(resources, file_name))
def create(self): with use_dir(Projects.BACKEND): log.info('Creating directory structure') os.makedirs(os.path.join(Projects.BACKEND, 'management', 'commands'), exist_ok=True) self._touch(os.path.join(Projects.BACKEND, 'management', init_file)) self._touch( os.path.join(Projects.BACKEND, 'management', 'commands', init_file)) log.info('Copying command into project') with open( os.path.join(Projects.BACKEND, 'management', 'commands', file_name), 'w') as f: f.write(il_resources.read_text(resources, file_name))
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing eslint dev dependencies to frontend") run(["yarn", "add", "--dev", *self.dependencies]) log.info("Installing eslint plugins to frontend") run(["yarn", "add", "--dev", *self.plugins]) log.info("Installing eslint configs to frontend") run(["yarn", "add", "--dev", *self.configs]) log.info("Adding eslint command") with open("package.json") as f: data = json.load(f) data["scripts"]["eslint"] = "node_modules/.bin/eslint --ext .js,.jsx ." log.info("Dumping new frontend package file") with open("package.json", "w") as f: json.dump(data, f)
def create(self): log.info('Installing django at a user level to generate the project') run(['pip', 'install', '--user', '--upgrade', 'django']) log.info('Creating the django project') run(['django-admin', 'startproject', 'backend']) with use_dir('backend'): log.info('Creating and activating a virtualenv for the project') virtualenv.cli_run(['venv']) # Programmatically activate the virtualenv in the current session venv_file = 'venv/bin/activate_this.py' exec(open(venv_file).read(), {'__file__': venv_file}) log.info( 'Installing project dependencies and creating a requirements file' ) run([ 'pip', 'install', '--upgrade', 'django', 'psycopg2-binary', 'django-cors-headers', 'djangorestframework', 'django-environ', ]) freeze_result = run([ 'pip', 'freeze', ], capture_output=True) with open('requirements.txt', 'w') as f: f.write(freeze_result.stdout.decode())
def create(self): log.info('Installing django at a user level to generate the project') run(['pip', 'install', '--user', '--upgrade', 'django']) log.info('Creating the django project') run(['django-admin', 'startproject', Projects.BACKEND]) with use_dir(Projects.BACKEND): log.info('Creating and activating a virtualenv for the project') run([ 'virtualenv', 'venv', ]) log.info( 'Installing project dependencies and creating a requirements file' ) pip = os.path.join('venv', 'bin', 'pip') run([ pip, 'install', '--upgrade', 'django', 'psycopg2-binary', 'django-cors-headers', 'djangorestframework', 'django-environ', ]) freeze_result = run([ pip, 'freeze', ], capture_output=True) with open('requirements.txt', 'w') as f: f.write(freeze_result.stdout.decode())
def create(self): log.info("Formatting package.json with prettier") with use_dir(Projects.FRONTEND): run(["yarn", "prettier", "-w", "package.json"])
def update(self): self.call_phase(Phases.CREATE, force_create=True) with use_dir(Projects.FRONTEND): log.info("Upgrading frontend dependencies") run(["yarn", "upgrade"])
def update(self): self.call_phase(Phases.CREATE, force_create=True) with use_dir(Projects.FRONTEND): log.info("Upgrading {self.package} via yarn") run(["yarn", "upgrade", self.package])
def installed(self): with use_dir(Projects.FRONTEND): with open("package.json") as f: return "be-pretty" in json.load(f).get("devDependencies", {})
def delete(self): self.call_phase(Phases.CREATE, force_create=True) with use_dir(Projects.FRONTEND): log.info("Removing {self.package} via yarn") run(["yarn", "remove", self.package])
def create(self): with use_dir(Projects.FRONTEND): with open(file_name, "w") as f: log.info("Writing frontend Dockerfile") f.write(il_resources.read_text(resources, file_name))
def create(self): with use_dir(Projects.BACKEND): black = which("black") if black is not None: run([black, "."])
def create(self): with use_dir(Projects.BACKEND): log.info( f"Installing Local Dockerfile for project {Projects.BACKEND}") with open(file_name, "w") as f: f.write(importlib.resources.read_text(resources, file_name))
def delete(self): with use_dir(Projects.BACKEND): log.info(f"Deleting {file_name}") os.remove(file_name)
def create(self): with use_dir(Projects.FRONTEND): log.info("Installing prettier dev dependency into the frontend project") run(["yarn", "add", "--dev", "prettier"])