Skip to content

Commit

Permalink
Build linux/amd64 images (#812)
Browse files Browse the repository at this point in the history
Workaround breaking change in docker build semantics.

Also add containers example under test.

Also update redis NPM package dependency.
  • Loading branch information
lukehoban authored Jul 24, 2023
1 parent 2173285 commit 8638667
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 112 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## HEAD (Unreleased)

- Fix a bug to allow computing minimum task and memory size requirements as `Inputs` for `Service` in `cloud/aws`.
- Update to use `@pulumi/aws` 5.x
- Update to use `@pulumi/awsx` 0.40.x
- Update to use `@pulumi/azure` 5.x
- aws: Build docker images for `linux/amd64` platform.

## 0.30.1 (Release May 24, 2021)

Expand Down
10 changes: 9 additions & 1 deletion aws/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ function computeImageFromBuildWorker(
pulumi.log.debug(` already built: ${imageName} (${d})`, logResource));
}
else {
const dockerBuildOptions: docker.DockerBuild = {
// Force build of linux/amd64 image. Once we support
// specifying the target platform for compute in the
// container cluster, we can thread that through here.
extraOptions: ["--platform", "linux/amd64"],
context: typeof build === "string" ? build : build.context,
...(typeof build === "string" ? {} : build),
};
// If we haven't, build and push the local build context to the ECR repository. Then return
// the unique image name we pushed to. The name will change if the image changes ensuring
// the TaskDefinition get's replaced IFF the built image changes.
uniqueImageName = docker.buildAndPushImage(imageName, build, repositoryUrl, logResource, async () => {
uniqueImageName = docker.buildAndPushImage(imageName, dockerBuildOptions, repositoryUrl, logResource, async () => {
// Construct Docker registry auth data by getting the short-lived authorizationToken from ECR, and
// extracting the username/password pair after base64-decoding the token.
//
Expand Down
72 changes: 0 additions & 72 deletions azure/examples/containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,75 +42,3 @@ let cachedNginx = new cloud.Service("examples-cached-nginx", {
},
replicas: 1,
});

// expose some APIs meant for testing purposes.
// let api = new cloud.API("examples-containers");
// api.get("/test", async (req, res) => {
// try {
// res.json({
// nginx: await nginx.getEndpoint(),
// nginx2: await builtService.getEndpoint(),
// });
// } catch (err) {
// console.error(errorJSON(err));
// res.status(500).json(errorJSON(err));
// }
// });

// function errorJSON(err: any) {
// const result: any = Object.create(null);
// Object.getOwnPropertyNames(err).forEach(key => result[key] = err[key]);
// return result;
// }

// api.get("/", async (req, res) => {
// try {
// const fetch = (await import("node-fetch")).default;
// // Use the NGINX or Redis Services to respond to the request.
// console.log("handling /");
// let page = await cache.get("page");
// if (page) {
// res.setHeader("X-Powered-By", "redis");
// res.end(page);
// return;
// }
// let endpoint = await nginx.getEndpoint("nginx", 80);
// console.log(`got host and port: ${JSON.stringify(endpoint)}`);
// let resp = await fetch(`http://${endpoint.hostname}:${endpoint.port}/`);
// let buffer = await resp.buffer();
// console.log(buffer.toString());
// await cache.set("page", buffer.toString());
// res.setHeader("X-Powered-By", "nginx");
// res.end(buffer);
// } catch (err) {
// console.error(errorJSON(err));
// res.status(500).json(errorJSON(err));
// }
// });
// api.get("/run", async (req, res) => {
// try {
// await helloTask.run();
// res.json({ success: true });
// } catch (err) {
// console.error(errorJSON(err));
// res.status(500).json(errorJSON(err));
// }
// });
// api.get("/custom", async (req, res) => {
// try {
// const fetch = (await import("node-fetch")).default;
// let endpoint = await customWebServer.getEndpoint();
// console.log(`got host and port: ${JSON.stringify(endpoint)}`);
// let resp = await fetch(`http://${endpoint.hostname}:${endpoint.port}/`);
// let buffer = await resp.buffer();
// console.log(buffer.toString());
// await cache.set("page", buffer.toString());
// res.setHeader("X-Powered-By", "custom web server");
// res.end(buffer);
// } catch (err) {
// console.error(errorJSON(err));
// res.status(500).json(errorJSON(err));
// }
// });
// api.proxy("/nginx", nginx.defaultEndpoint);
// export let frontendURL = api.publish().url;
3 changes: 1 addition & 2 deletions azure/examples/containers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"dependencies": {
"@pulumi/pulumi": "dev",
"@pulumi/azure": "dev",
"node-fetch": "^2.6.1",
"redis": "^2.8.0"
"node-fetch": "^2.6.1"
},
"devDependencies": {
"@types/node": "^10.0.0",
Expand Down
54 changes: 18 additions & 36 deletions examples/containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,45 +108,27 @@ class Cache {
},
},
});
this.get = (key: string) => {
return redis.getEndpoint("redis", 6379).then(endpoint => {
// console.log(`Endpoint: ${JSON.stringify(endpoint)}`);
let client = require("redis").createClient(
endpoint.port,
endpoint.hostname,
{ password: redisPassword },
);
console.log(client);
return new Promise<string>((resolve, reject) => {
client.get(key, (err: any, v: any) => {
if (err) {
reject(err);
} else {
resolve(v);
}
});
});
this.get = async (key: string) => {
const { createClient } = await import("redis");
const endpoint = await redis.getEndpoint("redis", 6379);
let client = createClient({
url: `redis://${endpoint.hostname}:${endpoint.port}`,
password: redisPassword,
});
console.log(client);
const res = await client.get(key);
return res ?? "";
};
this.set = (key: string, value: string) => {
return redis.getEndpoint("redis", 6379).then(endpoint => {
// console.log(`Endpoint: ${JSON.stringify(endpoint)}`);
let client = require("redis").createClient(
endpoint.port,
endpoint.hostname,
{ password: redisPassword },
);
console.log(client);
return new Promise<void>((resolve, reject) => {
client.set(key, value, (err: any, v: any) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
this.set = async (key: string, value: string) => {
const { createClient } = await import("redis");
const endpoint = await redis.getEndpoint("redis", 6379);
let client = createClient({
url: `redis://${endpoint.hostname}:${endpoint.port}`,
password: redisPassword,
});
console.log(client);
const res = await client.set(key, value);
console.log(res);
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/containers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@pulumi/pulumi": "dev",
"node-fetch": "^2.6.1",
"redis": "^2.8.0"
"redis": "^4.6.7"
},
"devDependencies": {
"@types/node": "^10.0.0",
Expand Down
12 changes: 12 additions & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ func TestAccAwsApi(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccAwsContainers(t *testing.T) {
test := getAwsBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "containers"),
Config: map[string]string{
"containers:redisPassword": "ABC$123",
"cloud-aws:useFargate": "true",
},
})
integration.ProgramTest(t, &test)
}

func TestAccAwsTimers(t *testing.T) {
test := getAwsBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down

0 comments on commit 8638667

Please sign in to comment.