|
@@ -108,19 +108,31 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
parsedYaml = yaml.load(yamlString);
|
|
parsedYaml = yaml.load(yamlString);
|
|
|
const parsedData = PorterYamlSchema.parse(parsedYaml);
|
|
const parsedData = PorterYamlSchema.parse(parsedYaml);
|
|
|
const porterYamlToJson = parsedData as z.infer<typeof PorterYamlSchema>;
|
|
const porterYamlToJson = parsedData as z.infer<typeof PorterYamlSchema>;
|
|
|
- setPorterJson(porterYamlToJson)
|
|
|
|
|
- console.log(porterYamlToJson)
|
|
|
|
|
|
|
+ setPorterJson(porterYamlToJson);
|
|
|
|
|
+ console.log(porterYamlToJson);
|
|
|
// go through key value pairs and create services from them, if they don't already exist
|
|
// go through key value pairs and create services from them, if they don't already exist
|
|
|
const newServices = [];
|
|
const newServices = [];
|
|
|
- const existingServices = formState.serviceList.map(s => s.name);
|
|
|
|
|
|
|
+ const existingServices = formState.serviceList.map((s) => s.name);
|
|
|
for (const [name, app] of Object.entries(porterYamlToJson.apps)) {
|
|
for (const [name, app] of Object.entries(porterYamlToJson.apps)) {
|
|
|
if (!existingServices.includes(name)) {
|
|
if (!existingServices.includes(name)) {
|
|
|
if (app.type) {
|
|
if (app.type) {
|
|
|
- newServices.push(Service.default(name, app.type, { readOnly: true, value: app.run }))
|
|
|
|
|
- } else if (name.includes('web')) {
|
|
|
|
|
- newServices.push(Service.default(name, 'web', { readOnly: true, value: app.run }))
|
|
|
|
|
|
|
+ newServices.push(
|
|
|
|
|
+ Service.default(name, app.type, {
|
|
|
|
|
+ readOnly: true,
|
|
|
|
|
+ value: app.run,
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
|
|
+ } else if (name.includes("web")) {
|
|
|
|
|
+ newServices.push(
|
|
|
|
|
+ Service.default(name, "web", { readOnly: true, value: app.run })
|
|
|
|
|
+ );
|
|
|
} else {
|
|
} else {
|
|
|
- newServices.push(Service.default(name, 'worker', { readOnly: true, value: app.run }))
|
|
|
|
|
|
|
+ newServices.push(
|
|
|
|
|
+ Service.default(name, "worker", {
|
|
|
|
|
+ readOnly: true,
|
|
|
|
|
+ value: app.run,
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -168,7 +180,7 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
git_branch: branch,
|
|
git_branch: branch,
|
|
|
build_context: folderPath,
|
|
build_context: folderPath,
|
|
|
builder: (buildConfig as any)?.builder,
|
|
builder: (buildConfig as any)?.builder,
|
|
|
- buildpacks: (buildConfig as any)?.buildPacks,
|
|
|
|
|
|
|
+ buildpacks: (buildConfig as any)?.buildpacks,
|
|
|
dockerfile: dockerfilePath,
|
|
dockerfile: dockerfilePath,
|
|
|
image_repo_uri: imageUrl,
|
|
image_repo_uri: imageUrl,
|
|
|
},
|
|
},
|
|
@@ -193,7 +205,7 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
cluster_id: currentCluster.id,
|
|
cluster_id: currentCluster.id,
|
|
|
project_id: currentProject.id,
|
|
project_id: currentProject.id,
|
|
|
}
|
|
}
|
|
|
- )
|
|
|
|
|
|
|
+ );
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.log(err);
|
|
console.log(err);
|
|
|
}
|
|
}
|
|
@@ -201,7 +213,10 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
// TODO: update Porter stack
|
|
// TODO: update Porter stack
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const combineEnv = (dashboardSetVariables: KeyValueType[], porterYamlSetVariables: Record<string, string> | undefined): z.infer<typeof EnvSchema> => {
|
|
|
|
|
|
|
+ const combineEnv = (
|
|
|
|
|
+ dashboardSetVariables: KeyValueType[],
|
|
|
|
|
+ porterYamlSetVariables: Record<string, string> | undefined
|
|
|
|
|
+ ): z.infer<typeof EnvSchema> => {
|
|
|
const env: z.infer<typeof EnvSchema> = {};
|
|
const env: z.infer<typeof EnvSchema> = {};
|
|
|
for (const { key, value } of dashboardSetVariables) {
|
|
for (const { key, value } of dashboardSetVariables) {
|
|
|
env[key] = value;
|
|
env[key] = value;
|
|
@@ -212,32 +227,39 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return env;
|
|
return env;
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
const createApps = (serviceList: Service[]): z.infer<typeof AppsSchema> => {
|
|
const createApps = (serviceList: Service[]): z.infer<typeof AppsSchema> => {
|
|
|
const apps: z.infer<typeof AppsSchema> = {};
|
|
const apps: z.infer<typeof AppsSchema> = {};
|
|
|
for (const service of serviceList) {
|
|
for (const service of serviceList) {
|
|
|
let config = Service.serialize(service);
|
|
let config = Service.serialize(service);
|
|
|
- if (porterJson != null && porterJson.apps[service.name] != null && porterJson.apps[service.name].config != null) {
|
|
|
|
|
- config = overrideObjectValues(config, porterJson.apps[service.name].config)
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ porterJson != null &&
|
|
|
|
|
+ porterJson.apps[service.name] != null &&
|
|
|
|
|
+ porterJson.apps[service.name].config != null
|
|
|
|
|
+ ) {
|
|
|
|
|
+ config = overrideObjectValues(
|
|
|
|
|
+ config,
|
|
|
|
|
+ porterJson.apps[service.name].config
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
apps[service.name] = {
|
|
apps[service.name] = {
|
|
|
type: service.type,
|
|
type: service.type,
|
|
|
run: service.startCommand.value,
|
|
run: service.startCommand.value,
|
|
|
config,
|
|
config,
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return apps
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return apps;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
const createFinalPorterYaml = (): z.infer<typeof PorterYamlSchema> => {
|
|
const createFinalPorterYaml = (): z.infer<typeof PorterYamlSchema> => {
|
|
|
return {
|
|
return {
|
|
|
version: "v1stack",
|
|
version: "v1stack",
|
|
|
env: combineEnv(formState.envVariables, porterJson.env),
|
|
env: combineEnv(formState.envVariables, porterJson.env),
|
|
|
apps: createApps(formState.serviceList),
|
|
apps: createApps(formState.serviceList),
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<CenterWrapper>
|
|
<CenterWrapper>
|
|
@@ -323,12 +345,17 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
|
|
|
<>
|
|
<>
|
|
|
<Text size={16}>Application services</Text>
|
|
<Text size={16}>Application services</Text>
|
|
|
<Spacer y={0.5} />
|
|
<Spacer y={0.5} />
|
|
|
- {porterJson && porterJson.apps && Object.keys(porterJson.apps).length > 0 &&
|
|
|
|
|
- <AppearingDiv>
|
|
|
|
|
- <Text size={16} color={"green"}>Auto-detected {Object.keys(porterJson.apps).length} services from porter.yaml!</Text>
|
|
|
|
|
- <Spacer y={1} />
|
|
|
|
|
- </AppearingDiv>
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ {porterJson &&
|
|
|
|
|
+ porterJson.apps &&
|
|
|
|
|
+ Object.keys(porterJson.apps).length > 0 && (
|
|
|
|
|
+ <AppearingDiv>
|
|
|
|
|
+ <Text size={16} color={"green"}>
|
|
|
|
|
+ Auto-detected {Object.keys(porterJson.apps).length}{" "}
|
|
|
|
|
+ services from porter.yaml!
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ <Spacer y={1} />
|
|
|
|
|
+ </AppearingDiv>
|
|
|
|
|
+ )}
|
|
|
<Services
|
|
<Services
|
|
|
setServices={(services: any[]) => {
|
|
setServices={(services: any[]) => {
|
|
|
setFormState({ ...formState, serviceList: services });
|
|
setFormState({ ...formState, serviceList: services });
|