Cool component. However I'm stumped on how to manage stages. I'd like to have multiple scripts in my project, such prod-deploy and dev-deploy that deploy to different stages with different environment.
However, it seems that the deployment is tied to the .serverless dir, which only stores one config. Therefore, the only solution appears to be to dynamically write this dir at deploy time. (So keeping both .serverless.prod and .serverless.dev and running cp -r .serverless.dev .serverless as part of deployment script).
Can anyone give feedback or share their approach?
@patricktyndall There is an example that demonstrates how to manage multiple environments. It's what you are looking for.
Hi
I've setup this work around for this problem
instead of having a "serverless.yml" file you should have a "serverless,js" file and resolve the variables programmatically here is an example
// serverless.js
const fs = require("fs");
const yaml = require("js-yaml");
const loadStageConfig = stage => {
try {
const raw = fs.readFileSync(`./stages/${stage}.yml`);
return yaml.safeLoad(raw);
} catch (e) {
console.warn(e);
return {};
}
};
const stage = process.env["STAGE"] || "dev";
const stageConfig = {
domain: null,
...loadStageConfig(stage)
};
console.log("stage :", stage);
console.log("stageConfig : ", stageConfig);
module.exports[`your-app-${stage}`] = {
component: "serverless-next.js",
inputs: {
domain: stageConfig.domain,
bucketName: `${stage}-your-app`
}
};
then you can passe the stage name by env variable
{
"scripts": {
"start": "next",
"build": "next build",
"deploy:dev": "export STAGE=dev && serverless"
}
}
@patricktyndall like @barrysteyn said the example https://github.com/danielcondemarin/serverless-next.js/tree/master/packages/serverless-nextjs-component/examples/multiple-instance-environment should help here.
Most helpful comment
Hi
I've setup this work around for this problem
instead of having a "serverless.yml" file you should have a "serverless,js" file and resolve the variables programmatically here is an example
then you can passe the stage name by env variable