Skip to content

Commit fe2ae37

Browse files
authored
Merge pull request #45 from DefangLabs/lio/pulumi-defang-aliases
Update proto for aliases
2 parents 2742e0b + 4cca092 commit fe2ae37

File tree

8 files changed

+1670
-480
lines changed

8 files changed

+1670
-480
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const service = new DefangService("defang-demo", {
2222
context: ".",
2323
dockerfile: "Dockerfile.dev",
2424
},
25+
networks: {
26+
public: {
27+
//aliases: ["demo.example.com"],
28+
},
29+
},
2530
ports: [{ target: 80, protocol: "http", mode: "ingress" }],
2631
// fabricDNS: "…", // override the Defang Fabric Controller endpoint
2732
// platform: "…", // "linux/arm64" | "linux/amd64" | "linux" (default)

index.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ function convertServiceInputs(inputs: DefangServiceInputs): pb.Service {
132132
resources.setReservations(reservations);
133133
deploy.setResources(resources);
134134
}
135-
switch (inputs.networks?.[0]) {
136-
case "public":
137-
service.setNetworks(pb.Network.PUBLIC);
138-
break;
139-
case "private":
140-
service.setNetworks(pb.Network.PRIVATE);
141-
break;
135+
const publicNetwork = inputs.networks?.public;
136+
const privateNetwork = inputs.networks?.private;
137+
if (publicNetwork !== undefined) {
138+
service.setNetworks(pb.Network.PUBLIC);
139+
service.setAliasesList(publicNetwork?.aliases ?? []);
140+
} else if (privateNetwork !== undefined) {
141+
service.setNetworks(pb.Network.PRIVATE);
142142
}
143143
service.setDeploy(deploy);
144144
service.setPlatform(
@@ -430,7 +430,7 @@ interface DefangServiceInputs {
430430
image?: string;
431431
init?: boolean;
432432
name: string;
433-
networks?: [Network];
433+
networks?: Record<NetworkName, Network>;
434434
platform?: Platform;
435435
ports?: Port[];
436436
project: string;
@@ -571,6 +571,12 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider<
571571
}
572572
}
573573
}
574+
if (Object.keys(news.networks || {}).length > 1) {
575+
failures.push({
576+
property: "networks",
577+
reason: "only one network can be specified",
578+
});
579+
}
574580
for (const secret of news.secrets || []) {
575581
// TODO: validate source name
576582
if (!secret.source) {
@@ -711,7 +717,7 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider<
711717
id: string,
712718
olds?: DefangServiceOutputs
713719
): Promise<pulumi.dynamic.ReadResult<DefangServiceOutputs>> {
714-
const serviceId = new pb.ServiceID();
720+
const serviceId = new pb.GetRequest();
715721
// serviceId.setProject(project);
716722
serviceId.setName(id);
717723
assert(olds?.fabricDNS, "fabricDNS is required");
@@ -745,7 +751,8 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider<
745751
export type Platform = "linux/arm64" | "linux/amd64" | "linux";
746752
export type Protocol = "tcp" | "udp" | "http" | "http2" | "grpc";
747753
export type DeviceCapability = "gpu";
748-
export type Network = "private" | "public";
754+
export type NetworkName = "private" | "public";
755+
export type Network = { aliases?: string[] } | null; // TODO: pulumi.Input<string>[]
749756

750757
export interface Port {
751758
target: number;
@@ -813,7 +820,7 @@ export interface DefangServiceArgs {
813820
/** the platform to deploy to; defaults to "linux/amd64" */
814821
platform?: pulumi.Input<Platform>;
815822
/** which network the service is in, ie. whether the service requires a public IP or not; defaults to "private" (was: internal=true) */
816-
networks?: [Network];
823+
networks?: Record<NetworkName, Network>;
817824
/** the optional deployment configuration */
818825
deploy?: pulumi.Input<Deploy>;
819826
/** the ports to expose */

0 commit comments

Comments
 (0)