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: 9 additions & 1 deletion src/fastapi_cloud_cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ def _get_app_name(path: Path) -> str:


def _should_exclude_entry(path: Path) -> bool:
parts_to_exclude = [".venv", "__pycache__", ".mypy_cache", ".pytest_cache"]
parts_to_exclude = [
".venv",
"__pycache__",
".mypy_cache",
".pytest_cache",
".gitignore",
".fastapicloudignore",
]

if any(part in path.parts for part in parts_to_exclude):
return True
Expand All @@ -51,6 +58,7 @@ def archive(path: Path, tar_path: Path) -> Path:
path,
should_exclude_entry=_should_exclude_entry,
additional_ignore_paths=[".fastapicloudignore"],
ignore_hidden=False,
)

logger.debug("Archive will be created at: %s", tar_path)
Expand Down
32 changes: 23 additions & 9 deletions tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,16 @@ def test_archive_preserves_relative_paths(src_path: Path, tar_path: Path) -> Non

def test_archive_respects_fastapicloudignore(src_path: Path, tar_path: Path) -> None:
"""Should exclude files specified in .fastapicloudignore."""
# Create test files
(src_path / "main.py").write_text("print('hello')")
(src_path / "config.py").write_text("CONFIG = 'value'")
(src_path / "secrets.env").write_text("SECRET_KEY=xyz")
(src_path / "data").mkdir()
(src_path / "data" / "file.txt").write_text("data")

# Create .fastapicloudignore file
(src_path / ".fastapicloudignore").write_text("secrets.env\ndata/\n")

# Create archive
archive(src_path, tar_path)

# Verify ignored files are excluded
with tarfile.open(tar_path, "r") as tar:
names = tar.getnames()
assert set(names) == {
Expand All @@ -98,21 +94,39 @@ def test_archive_respects_fastapicloudignore_unignore(
src_path: Path, tar_path: Path
) -> None:
"""Test we can use .fastapicloudignore to unignore files inside .gitignore"""
# Create test files
(src_path / "main.py").write_text("print('hello')")

(src_path / "ignore_me.txt").write_text("You should ignore me")

(src_path / "static/build").mkdir(exist_ok=True, parents=True)
(src_path / "static/build/style.css").write_text("body { background: #bada55 }")

# Rignore needs a .git folder to make .gitignore work
(src_path / ".git").mkdir(exist_ok=True, parents=True)
(src_path / ".gitignore").write_text("build/")
(src_path / ".gitignore").write_text("ignore_me.txt\nbuild/")

# Create .fastapicloudignore file
(src_path / ".fastapicloudignore").write_text("!static/build")

# Create archive
archive(src_path, tar_path)

# Verify ignored files are excluded
with tarfile.open(tar_path, "r") as tar:
names = tar.getnames()
assert set(names) == {"main.py", "static/build/style.css"}


def test_archive_includes_hidden_files(src_path: Path, tar_path: Path) -> None:
"""Should include hidden files in the archive by default."""
(src_path / "main.py").write_text("print('hello')")
(src_path / ".env").write_text("SECRET_KEY=xyz")
(src_path / ".config").mkdir()
(src_path / ".config" / "settings.json").write_text('{"setting": "value"}')

archive(src_path, tar_path)

with tarfile.open(tar_path, "r") as tar:
names = tar.getnames()
assert set(names) == {
"main.py",
".env",
".config/settings.json",
}