Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement initialization with copier-org/copier #1229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion kapitan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,21 @@ def build_parser():

init_parser.add_argument(
"--directory",
default=from_dot_kapitan("init", "directory", "."),
default="./",
help="set path, in which to generate the project skeleton,"
'assumes directory already exists. default is "./"',
)

init_parser.add_argument(
"--template_git_url",
default=from_dot_kapitan("init", "template_git_url ", defaults.COPIER_TEMPLATE_REPOSITORY),
help=f"Cruft template_git_url, default is {defaults.COPIER_TEMPLATE_REPOSITORY}",
)
init_parser.add_argument(
"--checkout_ref",
default=from_dot_kapitan("init", "checkout_ref ", defaults.COPIER_TEMPLATE_REF),
help=f"Cruft checkout_ref, default is {defaults.COPIER_TEMPLATE_REF}",
)
return parser


Expand Down
2 changes: 2 additions & 0 deletions kapitan/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@

# default path from where user defined custom filters are read
DEFAULT_JINJA2_FILTERS_PATH = os.path.join("lib", "jinja2_filters.py")
COPIER_TEMPLATE_REPOSITORY = "https://github.com/kapicorp/kapitan-reference.git"
COPIER_TEMPLATE_REF = "copier"
35 changes: 16 additions & 19 deletions kapitan/initialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@

"initialiser module"

import glob
import logging
import os

from kapitan.utils import copy_tree
from copier import run_copy

logger = logging.getLogger(__name__)


def initialise_skeleton(args):
"""Initialises a directory with a recommended skeleton structure
"""Initialises a directory with a recommended skeleton structure using cruft
Args:
args.directory (string): path which to initialise, directory is assumed to exist
args.template_git_url (string): path or url that contains the cruft repository template
args.checkout_ref (string): branch, tag or commit to checkout from the template repository
args.directory (string): directory to initialise the skeleton in (default is current directory)
"""

current_pwd = os.path.dirname(__file__)
templates_directory = os.path.join(current_pwd, "inputs", "templates")
populated = copy_tree(templates_directory, args.directory)
logger.info("Populated %s with:", args.directory)
for directory, subs, file_list in os.walk(args.directory):
# In order to avoid adding the given directory itself in listing.
if directory == args.directory:
continue
if any([path.startswith(directory) for path in populated]):
level = directory.replace(args.directory, "").count(os.sep) - 1
indent = " " * 4 * (level)
logger.info("%s%s", indent, os.path.basename(directory))
for fname in file_list:
if os.path.join(directory, fname) in populated:
sub_indent = " " * 4 * (level + 1)
logger.info("%s%s", sub_indent, fname)
template_git_url = args.template_git_url
checkout_ref = args.checkout_ref
directory = os.path.abspath(args.directory)

if set(glob.iglob(os.path.join(directory, "./*"))):
logger.error(f"Directory {directory} is not empty. Please initialise in an empty directory.")
return

logger.info(f"Initialising skeleton from {template_git_url}@{checkout_ref} in {directory}")
run_copy(template_git_url, vcs_ref=args.checkout_ref, unsafe=True, dst_path=directory)

This file was deleted.

13 changes: 0 additions & 13 deletions kapitan/inputs/templates/components/other_component/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions kapitan/inputs/templates/inventory/classes/common.yml

This file was deleted.

29 changes: 0 additions & 29 deletions kapitan/inputs/templates/inventory/classes/my_component.yml

This file was deleted.

6 changes: 0 additions & 6 deletions kapitan/inputs/templates/inventory/targets/my_target.yml

This file was deleted.

14 changes: 0 additions & 14 deletions kapitan/inputs/templates/templates/docs/my_readme.md

This file was deleted.

7 changes: 0 additions & 7 deletions kapitan/inputs/templates/templates/scripts/my_script.sh

This file was deleted.

Loading
Loading