-
Notifications
You must be signed in to change notification settings - Fork 25
EVG-19946: Support Docker on provider settings page #2017
Conversation
cy.getInputByLabel("User Data").type("my user data"); | ||
cy.getInputByLabel("Merge with existing user data").check({ | ||
force: true, | ||
describe.only("docker", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe.only("docker", () => { | |
describe("docker", () => { |
src/gql/queries/index.ts
Outdated
@@ -71,6 +70,7 @@ import PROJECT_HEALTH_VIEW from "./project-health-view.graphql"; | |||
import GET_PROJECT_PATCHES from "./project-patches.graphql"; | |||
import GET_SPAWN_EXPIRATION_INFO from "./spawn-expiration.graphql"; | |||
import GET_SPAWN_TASK from "./spawn-task.graphql"; | |||
import GET_SPRUCE_CONFIG from "./spruce-config.graphql"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been removing GET_
from the import/export name too
import GET_SPRUCE_CONFIG from "./spruce-config.graphql"; | |
import SPRUCE_CONFIG from "./spruce-config.graphql"; |
providerName: Provider.Docker, | ||
}, | ||
providerSettings: { | ||
...dockerProviderSettings(providerSettingsList[0]).form, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched the localhost
distro to use Docker and then tried to switch it back to static and saw this error:
It seems like there's validation here preventing container pool distros from using a different provider.
Maybe someone on app would have insight into the best approach here. Do we want to ban Docker distros from having their types changed? Or do we maybe want to update the save function to remove this distro from the list of Docker distros? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's probably my fault. Have to clear the containerPool
field in the transformers
providerSettingsList: [ | ||
...dockerProviderSettings(data.providerSettings).gql, | ||
], | ||
// @ts-ignore-error - containerPoolId will exist in DockerFormState. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can narrow down the type here using the in
operator to avoid this error (docs). Something like this:
case Provider.Docker: {
if ("containerPoolId" in data.providerSettings) {
return {
...distro,
provider: Provider.Docker,
providerSettingsList: [
...dockerProviderSettings(data.providerSettings).gql,
],
containerPool: data.providerSettings.containerPoolId,
};
}
break;
}
evergreen retry |
const { pools = [] } = containerPools || {}; | ||
|
||
const selectedPoolId = formData?.providerSettings?.containerPoolId; | ||
const selectedPool = pools.find((p) => p.id === selectedPoolId) ?? null; | ||
const poolMappingInfo = selectedPool | ||
? JSON.stringify(omitTypename(selectedPool), null, 4) | ||
: ""; | ||
|
||
const formSchema = useMemo( | ||
() => getFormSchema({ pools, poolMappingInfo }), | ||
[pools, poolMappingInfo] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useMemo
will run on every render when pools
is undefined
. You can avoid doing that by casting pools
to an array closer to where it's used. Another place to cast pools
is in getFormSchema
which is good if the function were reused so we only have to type cast in one place.
const { pools = [] } = containerPools || {}; | |
const selectedPoolId = formData?.providerSettings?.containerPoolId; | |
const selectedPool = pools.find((p) => p.id === selectedPoolId) ?? null; | |
const poolMappingInfo = selectedPool | |
? JSON.stringify(omitTypename(selectedPool), null, 4) | |
: ""; | |
const formSchema = useMemo( | |
() => getFormSchema({ pools, poolMappingInfo }), | |
[pools, poolMappingInfo] | |
); | |
const { pools } = containerPools || {}; | |
const selectedPoolId = formData?.providerSettings?.containerPoolId; | |
const selectedPool = pools?.find((p) => p.id === selectedPoolId) ?? null; | |
const poolMappingInfo = selectedPool | |
? JSON.stringify(omitTypename(selectedPool), null, 4) | |
: ""; | |
const formSchema = useMemo( | |
() => getFormSchema({ pools: pools || [], poolMappingInfo }), | |
[pools, poolMappingInfo] | |
); |
Passing run #12763 ↗︎
Details:
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
hello hello, so after experimenting a bit with the EC2 providers, I ended up concluding that maybe we should just have unique fields for each provider (rather than trying to share the I first tried a more "elegant" solution where the
And this is why I ended up thinking that it would be simpler for each of the providers to have their own fields. Lmk what you think! 😲 |
Pull = "pull", | ||
} | ||
|
||
// TODO: Append type with additional provider options, e.g. type ProviderFormState = StaticProviderFormState | DockerProviderFormState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] I think this no longer applies in the way it's written here, could update or just remove.
import { BaseTab } from "../BaseTab"; | ||
import { getFormSchema } from "./getFormSchema"; | ||
import { TabProps } from "./types"; | ||
import { TabProps, ProviderFormState } from "./types"; | ||
|
||
export const ProviderTab: React.FC<TabProps> = ({ distroData }) => { | ||
const initialFormState = distroData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] No need to rename this var (even though I think we have been doing it unnecessarily in every tab 😂)
}, | ||
], | ||
}; | ||
describe("docker provider", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a test that uses the poolMappingInfo
field?
buildType: BuildType; | ||
registryUsername: string; | ||
registryPassword: string; | ||
containerPoolId: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like poolMappingInfo
could also be a field here no?
@@ -30,27 +32,88 @@ const getSecurityGroups = ((providerSettings) => ({ | |||
}, | |||
})) satisfies FieldGetter; | |||
|
|||
const getImageUrl = ((providerSettings) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we somehow indicate that providerSettings represents 2 different types of objects with TypeScript types? It will also be helpful if we can type the providerSettings from the API based on usage in Spruce so we know what to expect from the object.
type ProviderSettings = ProviderFormState["staticProviderSettings"] & | ||
ProviderFormState["dockerProviderSettings"]; | ||
|
||
export const gqlProviderSettings = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure makes a lot more sense 😅 gorgeous!
* Because if you switch from static -> docker you need to update a bunch of fields, versus switch from docker -> static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!!! 😎
EVG-19946
Description
This PR adds Docker to the provider settings page. The Docker configuration is kind of weird (container pool ID is not part of provider settings list) so I made some changes in the form schema and conversion functions.
Screenshots
Testing
Evergreen PR