static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Deploying to production environment not working as expected

Open rinukkusu opened this issue 2 years ago • 3 comments

Before filing this issue, please ensure you're using the latest CLI by running swa --version and comparing to the latest version on npm.

Are you accessing the CLI from the default port :4280 ?

  • [ ] No, I am using a different port number (--port) and accessing the CLI from that port
  • [ ] Yes, I am accessing the CLI from port :4280
  • [x] Yes, default port, but I'm not using the port at all

Make sure you are accessing the URL printed in the console when running swa start!

ℹ️ NOTE: Make sure to enable debug logs when running any swa commands using --verbose=silly

Describe the bug

  • ✅ Setting no environment with the --env option deploys to preview environment. That's fine.
  • ❌ Setting environment to "Production" deploys to preview environment called "production". NOT fine.
  • ❌ Setting environment to "production" deploys to preview environment called "production". NOT fine.
  • ✅ Only setting environment to "prod" deploys to the production environment. That's fine, but not documented.

To Reproduce Steps to reproduce the behavior:

  1. Go to your app folder
  2. Type in command 'swa deploy ./dist --env production'
  3. It deploys without problem, but to a preview environment called "production"

Expected behavior Looking at the documentation, I expect that setting the environment to "production" deploys the app to the production environment. I also expect that setting the environment to "Production" produces the same outcome (see #518). I'm fine with using "prod" as environment option, but this should be clearly documented then, otherwise I consider this is a bug, that cost me many hours debugging.

Screenshots See screenshots in #518

Desktop (please complete the following information):

  • OS: Docker image node
  • Version: lts-bullseye

rinukkusu avatar Nov 27 '23 08:11 rinukkusu

Hi @rinukkusu, I tried to reproduce the issue with the following commands:

  • swa deploy --env production
  • swa deploy --env Production
  • swa deploy --env myEnv

The first and second commands deployed to: purple-mud-05975d71e.3.azurestaticapps.net And the third one deployed to (a preview environment): purple-mud-05975d71e-myenv.westus2.3.azurestaticapps.net

So could you check if your cli version is 1.1.6 (the latest release)? If so, could you kindly provide the logs? Thanks!

cjk7989 avatar Dec 13 '23 13:12 cjk7989

In case it helps someone in the future. I experienced a similar issue on both swa cli 1.1.6 and 1.1.7 and the issue was caused by an environmental variable named DEPLOYMENT_ENVIRONMENT that was set to production. That env variable was causing the pipeline to deploy to a preview environment called production. Removing the env variable fixed the issue for me and now I can deploy to production with the --env production flag.

avh01 avatar May 10 '24 03:05 avh01

When any value is set for DEPLOYMENT_ENVIRONMENT including production or Production, swa deploy seems to ignore the --env option and deploy to a preview environment named to match the DEPLOYMENT_ENVIRONMENT value. I'm not sure if this is expected or not, maybe someone can point me to the correct documentation.

avh01 avatar May 10 '24 12:05 avh01