deployjs / deployjs-cli

Deploy JS applications with a single command
MIT License
11 stars 3 forks source link

Can't deploy to different environments #5

Open jrdn91 opened 6 years ago

jrdn91 commented 6 years ago

I've been trying for hours to figure out why I can't get a staging setup to deploy to a different location when I pass it as a parameter to deploy js

Is this not supported? I'm using the S3 deployment setup and have two different buckets for production and staging. I can't figure out how to get this to work. Please help

duizendnegen commented 6 years ago

Hi! This is supported for sure. Running deployjs deploy -e staging would use the staging environment. In config/deploy.js you would then put something like

if(environment === 'staging') {
    ENV["s3-index"] = {
      accessKeyId: process.env.AWS_ACCESS_ID,
      secretAccessKey: process.env.AWS_SECRET_KEY,
      bucket: "bucket",
      region: "eu-central-1",
      allowOverwrite: true
    };

    ENV["s3"] = {
      accessKeyId: process.env.AWS_ACCESS_ID,
      secretAccessKey: process.env.AWS_SECRET_KEY,
      bucket: "bucket",
      region: "eu-central-1",
      filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,otf,json,mp3}'
    };
  }

If your staging endpoint also points to a different backend server, be sure to update the API URL depending on your framework build script.

Let me know if this works for you.

jrdn91 commented 6 years ago

So when I run that with --verbose I see a link at the beginning...

- Missing config:environment, using default:prod``

And then when it runs the build...

- building app todistusing buildEnvprod...

And it's uploading to the correct bucket, but using the wrong environment file

I've set up in my .angular-cli.json I list it

"environments": {
    "dev": "environments/environment.dev.ts",
    "staging": "environments/environment.staging.ts",
    "prod": "environments/environment.prod.ts"
}

Which references a different APIUrl but when I open the different buckets in the web, both are using my production APIUrl instead of being different

duizendnegen commented 6 years ago

Add the following lines inside the if block of your staging environment:

ENV["deployjs-angular-build"] = {
  environment: 'staging'
}

Welcoming a PR for better docs on https://github.com/deployjs/deployjs-angular-build specifically for this.