When I run "sbt ~run" I can see that mode is set Dev as expected. However, when I run "heroku local web" the server runs in Prod mode. Any idea how I can get this set to Dev mode? Do I have to set any variable with heroku config CLI ? My intention is to test with heroku local before pushing to Heroku git.
Have tried this in my Procfile:
web: target/universal/stage/bin/myapp -Dhttps.port=${PORT} -Dhttp.port=disabled -Dhttps.keyStore=conf/generated.keystore -Dlogback.configurationFile=conf/logback.xml -Dapplication.mode=DEV
But still it shows Prod. When server runs, the conf file is set programmatically with "-Dconfig.resource=root-dev.conf".
You'll want to use environment variables for the application.mode in some fashion (after all, that's what environment variables are for: changes specific to an environment). There are a few way you could do this, one is to create an APPLICATION_MODE env var, and use it in your Procfile thusly:
-Dapplication.mode=${APPLICATION_MODE:-DEV}
This will set -Dapplication.mode from APPLICATION_MODE and default to DEV if the env var is not set. Then you can set the env var on Heroku like this:
$ heroku config:set APPLICATION_MODE="PROD"
Or you could put the whole -Dapplication.mode=DEV in JAVA_OPTS in your .env file in your local repo like this:
JAVA_OPTS="-Dapplication.mode=DEV"
The heroku local command will pick up .env and load it. In this way you don't need to change anything on Heroku.
Related
I am trying to deploy a flask app in fly.io, but when execute flyctl launch in the terminal I get an error:
Error name argument or flag must be specified when not running interactively.
I don't see any other way to make a deployment in fly.io other than the console. I tried with a Dockerfile but flyctl launch continue throwing the same error.
Apparently flyctl believes you're not running its command-line tool interactively. That may or may not be a bug of flyctl itself, you can ask about that in the fly.io community.
The solution to this problem is to add the required information as parameters instead of being prompted for data entry. To my knowledge, you only need the name of the app you want to launch and the region code of the server location. The syntax for that can be found using the fly help launch command:
λ flyctl help launch
Create and configure a new app from source code or a Docker image.
Usage:
flyctl launch [flags]
Flags:
--auto-confirm Will automatically confirm changes when running non-interactively.
--build-arg strings Set of build time variables in the form of NAME=VALUE pairs. Can be specified multiple times.
--build-only Build but do not deploy
--build-secret strings Set of build secrets of NAME=VALUE pairs. Can be specified multiple times. See https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information
--build-target string Set the target build stage to build if the Dockerfile has more than one stage
--copy-config Use the configuration file if present without prompting
--detach Return immediately instead of monitoring deployment progress
--dockerfile string Path to a Dockerfile. Defaults to the Dockerfile in the working directory.
--dockerignore-from-gitignore If a .dockerignore does not exist, create one from .gitignore files
-e, --env strings Set of environment variables in the form of NAME=VALUE pairs. Can be specified multiple times.
--generate-name Always generate a name for the app, without prompting
-i, --image string The Docker image to deploy
--image-label string Image label to use when tagging and pushing to the fly registry. Defaults to "deployment-{timestamp}".
--local-only Only perform builds locally using the local docker daemon
--name string Name of the new app
--nixpacks Deploy using nixpacks to generate the image
--no-cache Do not use the build cache when building the image
--no-deploy Do not prompt for deployment
--now Deploy now without confirmation
-o, --org string The target Fly organization
--path string Path to the app source root, where fly.toml file will be saved (default ".")
--push Push image to registry after build is complete
-r, --region string The target region (see 'flyctl platform regions')
--remote-only Perform builds on a remote builder instance instead of using the local docker daemon
--strategy string The strategy for replacing running instances. Options are canary, rolling, bluegreen, or immediate. Default is canary, or rolling when max-per-region is set.
Global Flags:
-t, --access-token string Fly API Access Token
-j, --json json output
--verbose verbose output
In summary, the following command, executed in the directory of the app you want to launch on fly.io, should create an app called your-app-name in the Toronto, Canada location.
flyctl launch --name your-app-name --region yyz
So currently I'm working on a project on Heroku with Drupal and my issue is that I want to reset the database each time I deploy to master, yes I know it not ideal but its a development env because I'm working Drupal plugin and it would be nice if changes happened it could just reset to a state.
But when I try to connect using psql and some variables I just get password authentication failed for user even tho I know its the right password because I got it from Heroku itself.
Currently, I have tried using the console to try to make in connection soi could run a DROP TABLE command for me to afterword import an SQL file with the basic setup using pg_dump, and put it into a .sh script and run it with and release: in a procfile
Until now I have this as a release.sh file where I only tried in the console on heroku
PGHOST=HOST PGPORT=5432 \
PGDATABASE=DB \
PGUSER=USER PGPASSWORD=SOMEPASS \
psql
Try below command to reset DB
heroku pg:reset DATABASE_URL
On Compute Engine, using the click-to-deploy option for MEAN, how can we clone the repo of the sample app it locally creates so that we can start editing and pushing changes?
I tried gcloud init my-project however all it seems to do is initialize an empty repo. And indeed when I go to "source code" section for that project, there is nothing there.
How do I get the source code for this particular instance, setup a repo locally for it and then deploy changes to the same instance? Any help would be greatly appreciated.
OK, well I have made some progress. Once you click-to-deploy GCE will present you with a command to access your MEAN stack application through an SSH tunnel.
It will look something like this:
gcloud compute ssh --ssh-flag=-L3000:localhost:3000 --project=project-id --zone us-central1-f instance-name
You can change the port numbers as long as your firewall rules allow that specific port.
https://console.developers.google.com/project/your-project-id/firewalls/list
Once you SSH in, you will see the target directory, named the same as you told mean-io to use as the name of the application when you ran mean init
I first made a copy of this folder where mine was named "flow" cp -r flow flow-bck and then I removed some unnecessary directories with:
cd flow-bck && rm -rf node_modules bower_components .bower* .git
All of this to setup copying that folder to my local machine using gcloud compute copy-files availabe after installing Google Cloud SDK.
On my local machine, I ran the following:
gcloud compute copy-files my-instance-name:/remote/path/to/flow-bck /local/path/to/destination --zone the-instance-region
Above 'my-instance-name', '/remote/path/to', '/local/path/to', and 'the-instance-region' obviously need to changed to your deployment's info, etc.
This copied all the files from the remote instance to a folder called flow-bck on local found at the defined local path. I renamed this folder to what it is on remote flow and then did:
cd flow && npm install
This installed all the needed modules and stuff for MEAN io. Now the important part about this is you have to kill your remote ssh connection so that you can start running the local version of the app, because the ssh tunnel will be using that same port (3000) already, unless you changed it when you tunneled in.
Then in my local app directory flow I ran gulp to start the local version of the app on port 3000. So it loads up and runs just fine. I needed to create a new user as it's obviously not the same database.
Also I know this is basic stuff, but not too long ago I would have forgotten to start mongodb process by running mongod beforehand. In any case, mongo must be running before you can start the app locally.
Now the two things I haven't done yet, is editing and deploying a new version based on this... and the nagging question of whether this is all even necessary. That'd be great to find that this is all done with a few simple commands.
I'd like to use heroku_san to deploy multiple environments to heroku. I'm using dragonfly for image handling and S3 for storage. Usually you can add your key and secret for the storage using heroku config:add S3_KEY=… S3_SECRET=… directly.
So I've added these details to the heroku.yml file used by heroku_san:
staging:
app: app-staging
config: &default
BUNDLE_WITHOUT: "development:test"
S3_KEY: XXXXXXXXXXXXXXXXXX
S3_SECRET: XXXXXXXXXXXXXXXXXX
S3_BUCKET: app-staging
but when deploying I'm still getting:
rake aborted!
ENV variable 'S3_KEY' needs to be set - use
heroku config:add S3_KEY=XXXXXXXXX
What am I missing here? Is there a better way then storing this information in a YML file?
There's no need to run heroku config:add manually. Just run heroku_san's config task:
$ rake all heroku:config
Repeat this whenever you update the heroku.yml file.
I was confused about this too, since it's strangely absent from heroku_san's documentation, but the option does appear in the list of rake tasks:
$ rake -T
and in the heroku_san code: https://github.com/fastestforward/heroku_san/blob/master/lib/heroku_san/tasks.rb
A simple solution/work-around:
heroku config:add S3_KEY=XXX S3_SECRET=XXX --app app-staging
Any better ideas?
I think you need to run the command rake all heroku:rack_env. This command will then set the environment configurations for you based on your heroku_san YAML configuration.
I read somewhere but cannot seem to find where to add secret keys into Heroku without needing to put it into the source code git repository?
I guess that helps keep it secure when I am pushing into github.
How do I do that and does that make sense to do?
http://docs.heroku.com/config-vars
Then add the development keys to an initializer:
#config/initializers/keys.rb
development:
SOME_KEY = 'abc123' #not your production key
testing:
SOME_KEY = 'abc123' #not your production key
#production:
#blank
Optionally add the initializer to .gitignore. Not required as your production key isn't stored.
As Mark has suggested, the best way would be Heroku environment vars. you can read about them here:
To do so, you need to use Heroku CLI which you need to download and install it based on your operating system. Don't forget to set up Heroku CLI with these 3 steps:
$ heroku login
$ cd ~/myapp
$ heroku create (your Heroku app name)
now it's time to set up config variable. The command is:
$ heroku config:set <ENVIRONMENT_VARIABLE>=<VALUE>
for example I'm gonna save my API key here as a config var:
$ heroku config:set DARKSKY_API_KEY=8e11111111162218d22222222229cc22222c6
and now it's time to use it in you server side code. For Nodejs you can access them by:
process.env.DARKSKY_API_KEY
like so:
const weatherURL =`https://api.darksky.net/forecast/${process.env.DARKSKY_API_KEY}/${latitude},${longitude}?units=si`;
For other languages like Ruby, Java, ... check this link.
you can view your config vars by typing:
$ heroku config
or removing a config var:
$ heroku config:unset DARKSKY_API_KEY
Also, I was thinking about a .env file for heroku config vars that we can edit them locally and then upload them on heroku. Finally, I come up with this solution.
To save the cofig vars locally from heroku and be able to change them locally in a file, later down the road when it's needed, we can run:
$ heroku config | sed 's/: */=/g; /^=/d' >> HEROKU_CONFIG_ENV.env
which HEROKU_CONFIG_ENV.env is just a file name and you can name whatever you like.This script is gonna save HEROKU_CONFIG_ENV.env file on the root of your project.
After modifying the keys, it's the time to upload them on Heroku and set heroku config vars by running:
$ heroku config:set $(cat HEROKU_CONFIG_ENV.env | sed '/^$/d; /#[[:print:]]*$/d')
that's it.