sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.34k stars 175 forks source link

Can't use dependsOn arg on sst.aws.Nextjs component #667

Open bruno-espino opened 1 month ago

bruno-espino commented 1 month ago

I want to have my nextjs site build after creating a pulumi EC2 Instance, the following doesn't work:

import { backend } from "./backend"

export const site = new sst.aws.Nextjs("site", {
    path: "./packages/site/",
    build: {
        command: "yarn build",
    },
    domain: {
        name: site_domain,
        dns: sst.cloudflare.dns(),
    }
},
    { dependsOn: [backend] })

It still tries to build the site before deploying the backend

jayair commented 1 month ago

Build the site or deploy it? Also can I see what's in backend?

bruno-espino commented 1 month ago

Build, since when the site builds, it need to query the backend. Here is the backend file which creates the backend instance: // Get AL2023 AMI const amazon_ami = aws.ec2.getAmi({});

// EC2 IAM Role const backend_role = new aws.iam.Role("BackendRole", {});

// DB IAM Role const db_role = new aws.iam.Role("DbRole", {});

// EC2 Instance Profile const backend_profile = new aws.iam.InstanceProfile("BackendProfile", {});

// DB Instance Profile const db_profile = new aws.iam.InstanceProfile("DbProfile", {});

// EC2 Security Group export const backend_security_group = new aws.ec2.SecurityGroup("BackendSecurityGroup", {});

// DB Security Group const db_security_group = new aws.ec2.SecurityGroup("DbSecurityGroup", {});

// Redis Security Group const redis_security_group = new aws.ec2.SecurityGroup("RedisSecurityGroup", {});

// Redis Cache export const redis = new aws.elasticache.Cluster("Redis", {});

// DB Instance const db = new aws.rds.Instance("Db", {});

// Generate random strings for secrets const jwtSecret = new random.RandomPassword("JwtSecret", {}); const cookieSecret = new random.RandomPassword("CookieSecret", {});

// EC2 Instance export const backend = new aws.ec2.Instance("Backend", {});

// EC2 EIP const backend_eip = new aws.ec2.Eip("Eip", {});

// Cloudflare backend record const zone = cloudflare.getZoneOutput({});

new cloudflare.Record("BackendRecord", {});

fwang commented 1 month ago

@bruno-espino from the code u shared, sst.aws.Nextjs should be created after aws.ec2.Instance gets created. Are you seeing that Nextjs is being created before the Instance is created?

bruno-espino commented 1 month ago

Yes, it's actually the first thing that the deployment does, building the site. I assume there is kind of a priority for SST components vs pulumi resources or something like that?

fwang commented 4 weeks ago

@bruno-espino I did some test today and saw this:

The follow up question is, is it a requirement for you that building the site also happens after the backend is created?

bruno-espino commented 4 weeks ago

That's right, that is what I saw;

In this case yes, since while the nextjs site builds, it queries some backend endpoints. Since it fails to query the backend, it fails to build, so it fails fails to deploy.

If I do a deploy afterwards, it builds and deploys just fine (since the backend is deployed), so its not really a huge issue, just maybe something that could be optional