Skip to content
Open
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
22 changes: 19 additions & 3 deletions app/workers/tasks/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ async def deploy_start(ctx, deployment_id: str):
}
# env_vars_dict["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"

# Get configuration values
image = deployment.config.get("image")
root_directory = deployment.config.get("root_directory") or "/app"

# Always start in /app where the repository is cloned
# Custom root directory is handled via cd command in the script
working_dir = "/app"

# Prepare commands
commands = []

Expand All @@ -98,12 +106,22 @@ async def deploy_start(ctx, deployment_id: str):
deployment.project.github_installation_id, db
)
)

# Handle root directory properly
# Clone to /app (repository root) first, then handle subdirectory
commands.append(
"git init -q && "
f"git fetch -q --depth 1 https://x-access-token:{github_installation.token}@github.com/{deployment.repo_full_name}.git {deployment.commit_sha} && "
f"git checkout -q FETCH_HEAD"
)

# If custom root directory is specified, cd into it for subsequent commands
if root_directory != "/app":
# Create the subdirectory if it doesn't exist
commands.append(f"mkdir -p {root_directory}")
# Change to the subdirectory for subsequent commands
commands.append(f"cd {root_directory}")

# Step 2: Install dependencies
if deployment.config.get("build_command"):
commands.append("echo 'Installing dependencies...'")
Expand Down Expand Up @@ -159,16 +177,14 @@ async def deploy_start(ctx, deployment_id: str):
f"{log_prefix} Invalid CPU/memory values in config, using defaults."
)

image = deployment.config.get("image")

# Create and start container
container = await docker_client.containers.create_or_replace(
name=container_name,
config={
"Image": f"runner-{image}",
"Cmd": ["/bin/sh", "-c", " && ".join(commands)],
"Env": [f"{k}={v}" for k, v in env_vars_dict.items()],
"WorkingDir": "/app",
"WorkingDir": working_dir,
"Labels": labels,
"NetworkingConfig": {"EndpointsConfig": {"devpush_runner": {}}},
"HostConfig": {
Expand Down