Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(name: string, memory: number = 128) {
let redis = new cloud.Service(name, {
containers: {
redis: {
image: "redis:alpine",
memory: memory,
ports: [{ port: 6379 }],
command: ["redis-server", "--requirepass", redisPassword],
},
},
});
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 },
replicas: 2,
});
export let nginxEndpoint: Output = nginx.defaultEndpoint;
// A simple NGINX service, scaled out over two containers, using a single container rather than a map.
let simpleNginx = new cloud.Service("examples-simple-nginx", {
image: "nginx",
memory: 128,
ports: [{ port: 80 }],
replicas: 2,
});
export let simpleNginxEndpoint: Output = simpleNginx.defaultEndpoint;
let cachedNginx = new cloud.Service("examples-cached-nginx", {
containers: {
nginx: {
build: {
context: "./app",
cacheFrom: true,
},
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});
let multistageCachedNginx = new cloud.Service("examples-multistage-cached-nginx", {
containers: {
nginx: {
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as pulumi from "@pulumi/pulumi";
import * as cloud from "@pulumi/cloud";
import { Config, Output } from "@pulumi/pulumi";
// A simple NGINX service, scaled out over two containers.
let nginx = new cloud.Service("examples-nginx", {
containers: {
nginx: {
image: "nginx",
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});
export let nginxEndpoint: Output = nginx.defaultEndpoint;
// A simple NGINX service, scaled out over two containers, using a single container rather than a map.
let simpleNginx = new cloud.Service("examples-simple-nginx", {
image: "nginx",
memory: 128,
containers: {
redis: {
image: "redis:alpine",
memory: 512,
ports: [{ port: redisPort }],
command: ["redis-server", "--requirepass", redisPassword],
},
},
});
const redisEndpoint = redisCache.endpoints.redis[redisPort];
// A custom container for the frontend, which is a Python Flask app
// Use the 'build' property to specify a folder that contains a Dockerfile.
// Pulumi builds the container for you and pushes to an ECR registry
const frontend = new cloud.Service("voting-app-frontend", {
containers: {
votingAppFrontend: {
build: "./frontend", // path to the folder containing the Dockerfile
memory: 512,
ports: [{ port: 80 }],
environment: {
// pass the Redis container info in environment variables
"REDIS": redisEndpoint.hostname,
"REDIS_PORT": redisEndpoint.apply(e => e.port.toString()),
"REDIS_PWD": redisPassword,
},
},
},
});
// Export a variable that will be displayed during 'pulumi up'
// components. If you are targeting a specific cloud like AWS, Azure, or GCP, we recommend you use
// platform-specific packages like @pulumi/aws, @pulumi/azure or @pulumi/gcp. These packages give
// you full access to the breadth of the platform's capabilities and comes with many abstractions to
// make developing against that platform easier.
import * as cloud from "@pulumi/cloud";
import * as pulumi from "@pulumi/pulumi";
// Get the password to use for Redis from config.
const config = new pulumi.Config();
const redisPassword = config.require("redisPassword");
const redisPort = 6379;
// The data layer for the application
// Use the 'image' property to point to a pre-built Docker image.
const redisCache = new cloud.Service("voting-app-cache", {
containers: {
redis: {
image: "redis:alpine",
memory: 512,
ports: [{ port: redisPort }],
command: ["redis-server", "--requirepass", redisPassword],
},
},
});
const redisEndpoint = redisCache.endpoints.redis[redisPort];
// A custom container for the frontend, which is a Python Flask app
// Use the 'build' property to specify a folder that contains a Dockerfile.
// Pulumi builds the container for you and pushes to an ECR registry
const frontend = new cloud.Service("voting-app-frontend", {
// A simple NGINX service, scaled out over two containers.
let nginx = new cloud.Service("examples-nginx", {
containers: {
nginx: {
image: "nginx",
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});
export let nginxEndpoint: Output = nginx.defaultEndpoint;
// A simple NGINX service, scaled out over two containers, using a single container rather than a map.
let simpleNginx = new cloud.Service("examples-simple-nginx", {
image: "nginx",
memory: 128,
ports: [{ port: 80 }],
replicas: 2,
});
export let simpleNginxEndpoint: Output = simpleNginx.defaultEndpoint;
let cachedNginx = new cloud.Service("examples-cached-nginx", {
containers: {
nginx: {
build: {
context: "./app",
cacheFrom: true,
},
memory: 128,
});
});
});
};
}
}
let cache = new Cache("examples-mycache");
let helloTask = new cloud.Task("examples-hello-world", {
image: "hello-world",
memory: 20,
});
// build an anonymous image:
let builtService = new cloud.Service("examples-nginx2", {
containers: {
nginx: {
build: "./app",
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
waitForSteadyState: false,
});
// expose some APIs meant for testing purposes.
let api = new cloud.API("examples-containers");
api.get("/test", async (req, res) => {
try {
res.json({
constructor(name: string, memory: number = 128) {
const pw = config.redisPassword;
this.redis = new cloud.Service(name, {
containers: {
redis: {
image: "redis:alpine",
memory: memory,
ports: [{ port: 6379 }],
command: ["redis-server", "--requirepass", pw],
},
},
});
const endpoint = this.redis.endpoints.redis[6379];
this.get = async (key: string) => {
const ep = (await endpoint).get();
console.log(`Getting key '${key}' on Redis@${ep.hostname}:${ep.port}`);
const client = require("redis").createClient(ep.port, ep.hostname, { password: pw });
let cachedNginx = new cloud.Service("examples-cached-nginx", {
containers: {
nginx: {
build: {
context: "./app",
cacheFrom: true,
},
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});
let multistageCachedNginx = new cloud.Service("examples-multistage-cached-nginx", {
containers: {
nginx: {
build: {
context: "./app",
dockerfile: "./app/Dockerfile-multistage",
cacheFrom: {stages: ["build"]},
},
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
});
let customWebServer = new cloud.Service("mycustomservice", {
containers: {
constructor(name: string, memory: number = 128) {
const pw = config.redisPassword;
this.redis = new cloud.Service(name, {
containers: {
redis: {
image: "redis:alpine",
memory: memory,
ports: [{ port: 6379, external: true }],
command: ["redis-server", "--requirepass", pw],
},
},
});
this.endpoint = this.redis.endpoints.redis[6379];
}