feat: support private git repositories with token auth
- Entity: added gitToken and gitBranch columns to Application
- DTO: added gitToken and gitBranch fields to Create/Update DTOs
- Build pipeline: git-clone init container now injects token into
HTTPS URL for private repo authentication (GitHub PAT, GitLab token, etc.)
- Build pipeline: supports cloning specific branch (default: main)
- Frontend deploy page: added Access Token (password field) and Branch
inputs when Git Repository source is selected
- Frontend deploy page: Review step shows branch and token status
- Frontend app detail: shows branch badge and 🔑 Private indicator
when git credentials are configured
- Works with: GitHub, GitLab, Bitbucket, any HTTPS-based git host
This commit is contained in:
@@ -149,13 +149,30 @@ export class BuildService {
|
||||
],
|
||||
});
|
||||
} else if (hasGitUrl) {
|
||||
// Build the git clone URL — inject token for private repos
|
||||
let cloneUrl = app.gitUrl!;
|
||||
if (app.gitToken) {
|
||||
// Convert https://github.com/user/repo.git → https://<token>@github.com/user/repo.git
|
||||
// Also works for GitLab, Bitbucket, etc.
|
||||
try {
|
||||
const url = new URL(cloneUrl);
|
||||
url.username = app.gitToken;
|
||||
url.password = ''; // Some providers use token as username, others as password
|
||||
cloneUrl = url.toString();
|
||||
} catch {
|
||||
// If URL parsing fails, try simple injection after protocol
|
||||
cloneUrl = cloneUrl.replace('https://', `https://${app.gitToken}@`);
|
||||
}
|
||||
}
|
||||
const branch = app.gitBranch || 'main';
|
||||
|
||||
// Clone git repo into /workspace/source, then copy our generated Dockerfile
|
||||
initContainers.push({
|
||||
name: 'git-clone',
|
||||
image: 'alpine/git:2.43.0',
|
||||
command: ['sh', '-c', `
|
||||
echo ">>> Cloning ${app.gitUrl}" &&
|
||||
git clone --depth 1 ${app.gitUrl} /workspace-out/source &&
|
||||
echo ">>> Cloning branch '${branch}' from ${app.gitUrl}" &&
|
||||
git clone --depth 1 --branch ${branch} ${cloneUrl} /workspace-out/source &&
|
||||
cp /dockerfile/Dockerfile /workspace-out/Dockerfile &&
|
||||
echo ">>> Workspace contents:" &&
|
||||
ls -la /workspace-out/source/
|
||||
|
||||
Reference in New Issue
Block a user