Skip to content
Merged
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
10 changes: 5 additions & 5 deletions getdeck/deckfile/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from abc import ABC, abstractmethod
from typing import List, Dict, Union
from typing import List, Dict, Optional, Union

from pydantic import BaseModel

Expand Down Expand Up @@ -37,7 +37,7 @@ def get_provider(self, config) -> AbstractProvider:
class DeckfileHelmSource(BaseModel):
type: str = "helm"
ref: str
targetRevision: str = ""
targetRevision: Optional[str] = None
namespace: str = ""
path: str = None
chart: str = None # this is set when pulling directly from a Helm repo
Expand All @@ -56,21 +56,21 @@ class DeckfileInlineSource(BaseModel):
class DeckfileFileSource(BaseModel):
type: str = "file"
ref: str = None
targetRevision: str = ""
targetRevision: Optional[str] = None
path: str = ""


class DeckfileKustomizeSource(BaseModel):
type: str = "kustomize"
ref: str
targetRevision: str = ""
targetRevision: Optional[str] = None
path: str = ""


class DeckfileDirectorySource(BaseModel):
type: str = "directory"
ref: str
targetRevision: str = ""
targetRevision: Optional[str] = None
path: str
recursive: bool

Expand Down
16 changes: 11 additions & 5 deletions getdeck/fetch/source_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,31 @@ def fetch(self, data: SourceAux, *args, **kwargs) -> SourceAux:
ref, rev = location.split("#")
else:
ref = location
rev = "HEAD"
rev = None

rev = kwargs.get("targetRevision", rev)
path = kwargs.get("path", "")

temporary_folder = tempfile.mkdtemp()
path = os.path.join(temporary_folder, path)
data.path = os.path.dirname(path)
data.name = os.path.basename(path)
data.temporary_data = TemporaryData(data=temporary_folder, is_folder=True)

try:
repo = Repo.clone_from(ref, temporary_folder)
repo.git.checkout(rev)
if rev:
repo.git.checkout(rev)
except GitError as e:
raise FetchError(f"Cannot checkout {rev} from {ref}: {e}")
except Exception as e:
raise e

temporary_path = os.path.join(temporary_folder, path)
if os.path.isdir(temporary_path):
data.path = temporary_path
data.name = None
else:
data.name = os.path.basename(temporary_path)
data.path = os.path.dirname(temporary_path)

return data


Expand Down
11 changes: 8 additions & 3 deletions getdeck/sources/tooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,26 @@ class Tooler(RenderBehavior):
def render(self, deckfile_aux: DeckfileAux, source_aux: SourceAux, **kwargs):
cmd = self.build_command()
try:
if source_aux.path:
source_path = os.path.join(source_aux.path, source_aux.name or "")
logger.debug(f"Render {source_path}")
if source_aux.temporary_data:
source_path = source_aux.temporary_data.data
else:
source_path = source_aux.path

if source_path:
if not os.path.isabs(source_path):
source_path = os.path.join(
deckfile_aux.path, source_path.removeprefix("./")
)

# copy data
if os.path.isdir(source_path):
shutil.copytree(
source_path, self.tmp_source.name, dirs_exist_ok=True
)
else:
shutil.copy(source_path, self.tmp_source.name)

logger.debug(f"Render: {source_aux.location}")
self.run_tooler(cmd)
source_files = self.collect_workload_files()
return source_files
Expand Down
6 changes: 5 additions & 1 deletion test/sources/deck.file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ decks:
- type: file
ref: https://raw.githubusercontent.com/Getdeck/getdeck/main/test/beiboot/hello.yaml

- type: file
ref: git@github.com:Getdeck/getdeck.git
path: test/resources/test/hello.yaml

- type: file
ref: git@github.com:Getdeck/getdeck.git
targetRevision: main
path: test/beiboot/hello.yaml
path: test/resources/test/hello.yaml
2 changes: 1 addition & 1 deletion test/src/fetch/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_local_file(self):
data_aux = fetch_data(location)
self.assertIsNotNone(data_aux.deckfile)
self.assertIsNotNone(data_aux.deckfile_aux)
self.assertEqual(len(data_aux.source_auxs), 5)
self.assertEqual(len(data_aux.source_auxs), 6)

def test_local_helm(self):
location = "./test/sources/deck.helm.yaml"
Expand Down