Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Service: add link env values in docker build args
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Oct 8, 2024
1 parent 35b8b95 commit d633a2a
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 158 deletions.
3 changes: 3 additions & 0 deletions examples/internal/playground/cluster/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# sst
.sst
15 changes: 15 additions & 0 deletions examples/internal/playground/cluster/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:18-bullseye-slim
ARG SST_RESOURCE_MyBucket

WORKDIR /app/

COPY package.json /app
RUN npm install

# Ensure linked resources are available at build time
COPY build.mjs /app
RUN node build.mjs

COPY index.mjs /app

ENTRYPOINT ["node", "index.mjs"]
3 changes: 3 additions & 0 deletions examples/internal/playground/cluster/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Resource } from "sst";

console.log("SDK", Resource.MyBucket.name);
19 changes: 19 additions & 0 deletions examples/internal/playground/cluster/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from "express";
import { Resource } from "sst";

const PORT = 80;

const app = express();

app.get("/", async (req, res) => {
res.send(
JSON.stringify({
sdk: Resource.MyBucket.name,
env: process.env.SST_RESOURCE_MyBucket,
})
);
});

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
13 changes: 13 additions & 0 deletions examples/internal/playground/cluster/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "cluster",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.19.2",
"sst": "latest"
}
}
21 changes: 21 additions & 0 deletions examples/internal/playground/cluster/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"MyBucket": {
"name": string
"type": "sst.aws.Bucket"
}
"MyService": {
"service": string
"type": "sst.aws.Service"
"url": string
}
"MyVpc": {
"type": "sst.aws.Vpc"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"MyBucket": {
"name": string
"type": "sst.aws.Bucket"
}
"MyService": {
"service": string
"type": "sst.aws.Service"
"url": string
}
"MyVpc": {
"type": "sst.aws.Vpc"
}
}
}
16 changes: 10 additions & 6 deletions examples/internal/playground/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"MyApp": {
"name": string
"type": "sst.aws.Function"
"url": string
}
"MyBucket": {
"name": string
"type": "sst.aws.Bucket"
}
"MyService": {
"service": string
"type": "sst.aws.Service"
"url": string
}
"MyVpc": {
"type": "sst.aws.Vpc"
}
}
}
export {}
77 changes: 42 additions & 35 deletions examples/internal/playground/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,50 @@ export default $config({
home: "aws",
};
},
console: {
autodeploy: {
target(event) {
if (
event.type === "branch" &&
event.branch === "dev" &&
event.action === "pushed"
) {
return { stage: "dev" };
}
},
workflow(context) {
context.install();
context.shell("cd examples/internal/playground && npm install");
context.deploy();
},
},
},
async run() {
const bucket = new sst.aws.Bucket("MyBucket", {
access: "public",
transform: {
bucket: (args) => {
args.tags = { foo: "bar" };
},
},
});
const ret: Record<string, $util.Output<string>> = {};

const app = new sst.aws.Function("MyApp", {
handler: "functions/handler-example/index.handler",
link: [bucket],
url: true,
});
const vpc = addVpc();
const bucket = addBucket();
//const app = addFunction();
const service = addService();

return {
bucket: bucket.name,
app: app.url,
};
return ret;

function addVpc() {
return new sst.aws.Vpc("MyVpc");
}

function addBucket() {
const bucket = new sst.aws.Bucket("MyBucket");
ret.bucket = bucket.name;
return bucket;
}

function addFunction() {
const app = new sst.aws.Function("MyApp", {
handler: "functions/handler-example/index.handler",
link: [bucket],
url: true,
});
ret.app = app.url;
return app;
}

function addService() {
const cluster = new sst.aws.Cluster("MyCluster", { vpc });
const service = cluster.addService("MyService", {
public: {
ports: [{ listen: "80/http" }],
},
image: {
context: "cluster",
},
link: [bucket],
});
ret.service = service.url;

return service;
}
},
});
Loading

0 comments on commit d633a2a

Please sign in to comment.