mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-17 01:15:19 +00:00
feat(gitlab): add optional internal URL for GitLab integration
- Introduced a new field `gitlabInternalUrl` in the GitLab provider settings to allow users to specify an internal URL for OAuth token exchange when GitLab runs on the same instance as Dokploy. - Updated the GitLab provider forms to include the new field with appropriate descriptions. - Modified the token exchange logic to utilize the internal URL if provided, enhancing connectivity options for users.
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
|||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
|
FormDescription,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
@@ -35,6 +36,10 @@ const Schema = z.object({
|
|||||||
gitlabUrl: z.string().min(1, {
|
gitlabUrl: z.string().min(1, {
|
||||||
message: "GitLab URL is required",
|
message: "GitLab URL is required",
|
||||||
}),
|
}),
|
||||||
|
gitlabInternalUrl: z
|
||||||
|
.union([z.string().url(), z.literal("")])
|
||||||
|
.optional()
|
||||||
|
.transform((v) => (v === "" ? undefined : v)),
|
||||||
applicationId: z.string().min(1, {
|
applicationId: z.string().min(1, {
|
||||||
message: "Application ID is required",
|
message: "Application ID is required",
|
||||||
}),
|
}),
|
||||||
@@ -66,6 +71,7 @@ export const AddGitlabProvider = () => {
|
|||||||
redirectUri: webhookUrl,
|
redirectUri: webhookUrl,
|
||||||
name: "",
|
name: "",
|
||||||
gitlabUrl: "https://gitlab.com",
|
gitlabUrl: "https://gitlab.com",
|
||||||
|
gitlabInternalUrl: "",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(Schema),
|
resolver: zodResolver(Schema),
|
||||||
});
|
});
|
||||||
@@ -80,6 +86,7 @@ export const AddGitlabProvider = () => {
|
|||||||
redirectUri: webhookUrl,
|
redirectUri: webhookUrl,
|
||||||
name: "",
|
name: "",
|
||||||
gitlabUrl: "https://gitlab.com",
|
gitlabUrl: "https://gitlab.com",
|
||||||
|
gitlabInternalUrl: "",
|
||||||
});
|
});
|
||||||
}, [form, isOpen]);
|
}, [form, isOpen]);
|
||||||
|
|
||||||
@@ -92,6 +99,7 @@ export const AddGitlabProvider = () => {
|
|||||||
name: data.name || "",
|
name: data.name || "",
|
||||||
redirectUri: data.redirectUri || "",
|
redirectUri: data.redirectUri || "",
|
||||||
gitlabUrl: data.gitlabUrl || "https://gitlab.com",
|
gitlabUrl: data.gitlabUrl || "https://gitlab.com",
|
||||||
|
gitlabInternalUrl: data.gitlabInternalUrl || undefined,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await utils.gitProvider.getAll.invalidate();
|
await utils.gitProvider.getAll.invalidate();
|
||||||
@@ -192,6 +200,31 @@ export const AddGitlabProvider = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="gitlabInternalUrl"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
Internal URL (Optional)
|
||||||
|
</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
placeholder="http://gitlab:80"
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Use when GitLab runs on the same instance as Dokploy.
|
||||||
|
Used for OAuth token exchange to reach GitLab via
|
||||||
|
internal network (e.g. Docker service name).
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="redirectUri"
|
name="redirectUri"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
|
FormDescription,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
@@ -33,6 +34,10 @@ const Schema = z.object({
|
|||||||
gitlabUrl: z.string().url({
|
gitlabUrl: z.string().url({
|
||||||
message: "Invalid Gitlab URL",
|
message: "Invalid Gitlab URL",
|
||||||
}),
|
}),
|
||||||
|
gitlabInternalUrl: z
|
||||||
|
.union([z.string().url(), z.literal("")])
|
||||||
|
.optional()
|
||||||
|
.transform((v) => (v === "" ? undefined : v)),
|
||||||
groupName: z.string().optional(),
|
groupName: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,6 +66,7 @@ export const EditGitlabProvider = ({ gitlabId }: Props) => {
|
|||||||
groupName: "",
|
groupName: "",
|
||||||
name: "",
|
name: "",
|
||||||
gitlabUrl: "https://gitlab.com",
|
gitlabUrl: "https://gitlab.com",
|
||||||
|
gitlabInternalUrl: "",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(Schema),
|
resolver: zodResolver(Schema),
|
||||||
});
|
});
|
||||||
@@ -72,6 +78,7 @@ export const EditGitlabProvider = ({ gitlabId }: Props) => {
|
|||||||
groupName: gitlab?.groupName || "",
|
groupName: gitlab?.groupName || "",
|
||||||
name: gitlab?.gitProvider.name || "",
|
name: gitlab?.gitProvider.name || "",
|
||||||
gitlabUrl: gitlab?.gitlabUrl || "",
|
gitlabUrl: gitlab?.gitlabUrl || "",
|
||||||
|
gitlabInternalUrl: gitlab?.gitlabInternalUrl || "",
|
||||||
});
|
});
|
||||||
}, [form, isOpen]);
|
}, [form, isOpen]);
|
||||||
|
|
||||||
@@ -82,6 +89,7 @@ export const EditGitlabProvider = ({ gitlabId }: Props) => {
|
|||||||
groupName: data.groupName || "",
|
groupName: data.groupName || "",
|
||||||
name: data.name || "",
|
name: data.name || "",
|
||||||
gitlabUrl: data.gitlabUrl || "",
|
gitlabUrl: data.gitlabUrl || "",
|
||||||
|
gitlabInternalUrl: data.gitlabInternalUrl ?? null,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await utils.gitProvider.getAll.invalidate();
|
await utils.gitProvider.getAll.invalidate();
|
||||||
@@ -151,6 +159,31 @@ export const EditGitlabProvider = ({ gitlabId }: Props) => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="gitlabInternalUrl"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
Internal URL (Optional)
|
||||||
|
</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
placeholder="http://gitlab:80"
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Use when GitLab runs on the same instance as Dokploy.
|
||||||
|
Used for OAuth token exchange to reach GitLab via
|
||||||
|
internal network (e.g. Docker service name).
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="groupName"
|
name="groupName"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "gitlab" ADD COLUMN "gitlabInternalUrl" text;
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -981,6 +981,13 @@
|
|||||||
"when": 1770442690721,
|
"when": 1770442690721,
|
||||||
"tag": "0139_brave_bloodstorm",
|
"tag": "0139_brave_bloodstorm",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 140,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1770489900075,
|
||||||
|
"tag": "0140_lame_mattie_franklin",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,9 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gitlab = await findGitlabById(gitlabId as string);
|
const gitlab = await findGitlabById(gitlabId as string);
|
||||||
const gitlabUrl = new URL(gitlab.gitlabUrl);
|
// Use internal URL for token exchange when GitLab is on same instance as Dokploy
|
||||||
|
const baseUrl = gitlab.gitlabInternalUrl || gitlab.gitlabUrl;
|
||||||
|
const gitlabUrl = new URL(baseUrl);
|
||||||
|
|
||||||
const headers: HeadersInit = {
|
const headers: HeadersInit = {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ export const gitlab = pgTable("gitlab", {
|
|||||||
.primaryKey()
|
.primaryKey()
|
||||||
.$defaultFn(() => nanoid()),
|
.$defaultFn(() => nanoid()),
|
||||||
gitlabUrl: text("gitlabUrl").default("https://gitlab.com").notNull(),
|
gitlabUrl: text("gitlabUrl").default("https://gitlab.com").notNull(),
|
||||||
|
gitlabInternalUrl: text("gitlabInternalUrl"),
|
||||||
applicationId: text("application_id"),
|
applicationId: text("application_id"),
|
||||||
redirectUri: text("redirect_uri"),
|
redirectUri: text("redirect_uri"),
|
||||||
secret: text("secret"),
|
secret: text("secret"),
|
||||||
@@ -41,6 +42,7 @@ export const apiCreateGitlab = createSchema.extend({
|
|||||||
authId: z.string().min(1),
|
authId: z.string().min(1),
|
||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
gitlabUrl: z.string().min(1),
|
gitlabUrl: z.string().min(1),
|
||||||
|
gitlabInternalUrl: z.string().optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiFindOneGitlab = createSchema
|
export const apiFindOneGitlab = createSchema
|
||||||
@@ -70,4 +72,5 @@ export const apiUpdateGitlab = createSchema.extend({
|
|||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
gitlabId: z.string().min(1),
|
gitlabId: z.string().min(1),
|
||||||
gitlabUrl: z.string().min(1),
|
gitlabUrl: z.string().min(1),
|
||||||
|
gitlabInternalUrl: z.string().optional().nullable(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ table github {
|
|||||||
table gitlab {
|
table gitlab {
|
||||||
gitlabId text [pk, not null]
|
gitlabId text [pk, not null]
|
||||||
gitlabUrl text [not null, default: 'https://gitlab.com']
|
gitlabUrl text [not null, default: 'https://gitlab.com']
|
||||||
|
gitlabInternalUrl text
|
||||||
application_id text
|
application_id text
|
||||||
redirect_uri text
|
redirect_uri text
|
||||||
secret text
|
secret text
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ export const refreshGitlabToken = async (gitlabProviderId: string) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${gitlabProvider.gitlabUrl}/oauth/token`, {
|
// Use internal URL for token refresh when GitLab is on same instance as Dokploy
|
||||||
|
const baseUrl = gitlabProvider.gitlabInternalUrl || gitlabProvider.gitlabUrl;
|
||||||
|
const response = await fetch(`${baseUrl}/oauth/token`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
|||||||
-1205
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user