Terraform / Heroku not finding 'web' process in heroku/ruby buildpack - heroku

I'm getting an error in Terraform:
Error: Patch "https://api.heroku.com/apps/coderdojo-contentful-staging/formation/web": Couldn't find that process type (web).
│
│ with heroku_formation.coderdojo_contentful_staging_formation[0],
│ on terraform.tf line 41, in resource "heroku_formation" "coderdojo_contentful_staging_formation":
│ 41: resource "heroku_formation" "coderdojo_contentful_staging_formation" {
from these lines from my terraform.tf file:
resource "heroku_formation" "coderdojo_contentful_staging_formation" {
count = length(var.formations)
app = heroku_app.coderdojo_contentful_staging.name
type = lookup(var.formations[count.index], "type")
quantity = lookup(var.formations[count.index], "quantity")
size = lookup(var.formations[count.index], "size")
}
which rely on these lines in my terraform.tfvars file:
formations = [
{
type = "web"
size = "standard-1x"
quantity = "1"
}
]
buildpacks = [
"heroku/ruby"
]
Searching the documentation online (e.g. buildpacks and heroku-buildpack-ruby) it appears that the web process type comes from either the buildpack, or the Procfile.
Another project works fine with a very similar setup (i.e. no Procfile), but with the addition of a heroku/nodejs buildpack. I tried adding that build pack but got the same error.
What am I missing?

Another project works fine with a very similar setup (i.e. no Procfile), but with the addition of a heroku/nodejs buildpack. I tried adding that build pack but got the same error.
The heroku/nodejs buildpack falls back to the start script defined in the package.json if no Procfile is present. I suspect your other project that uses that buildpack has a start script. The Ruby buildpack has no such default.
If your app doesn't require Node.js, don't add the Node.js buildpack. Instead, add a Procfile to the root of your repository that tells Heroku how to run your app, e.g.
web: bundle exec ruby path/to/some/script.rb
This defines a web process that runs bundle exec ruby ruby path/to/some/script.rb.

Related

The requested file (go1.13.7.linux-amd64.tar.gz) is unknown to the buildpack when pushing golang web app to heroku?

I have created a golang REST API and am trying to deploy it to heroku. I've built it on windows 7.
I linked my github account to push my golang web app to heroku, but I am getting the following error:
The requested file (go1.13.7.linux-amd64.tar.gz) is unknown to the buildpack!
I am using dep to package my app. Here is the metadata i provide to heroku in my Gopkg.toml:
[metadata.heroku]
root-package = "restapitest"
go-version = "go1.13.7"
install = [ "./..." ]
My file project folder looks like this:
C:\$GOPATH\src\API\RESTAPI\
Vendor\github.com\gorilla
go-sql-driver
Gopkg.lock
Gopkg.toml
main.go
It appeared to be an issue with the version. Lowering it to 1.12.0 allowed successful deployment of the app.

How can I deploy beego app to Heroku

I'm creating a web app in beego that I need to have running in Heroku.
I can get it running normally if I just specify the binary for the app in the Procfile. But I want to have swagger available in the app, so I need to use bee to start the app like:
bee run -downdoc=true -gendoc=true
so that it automatically creates and downloads all the swagger related icons, html, etc.
But, if I specify that as the command in Procfile (even after adding bee to vendor so that it is available), it fails because the app doesn't have the go command available in runtime. The exact error is this:
0001 There was an error running 'go version' command: exec: "go": executable file not found in $PATH
How can I bypass this without adding the whole swagger specification to heroku (and github, since it is a repository)?
You can not run bee command on heroku, because it is a executable program.
But you can run beego app on heroku with adding project dependencies. In order to that you should use tools like https://github.com/kardianos/govendor.
1. After install govendor try following steps in your project folder;
$ govendor init
This command will create ./vendor/vendor.json file in current directory.
{
"comment": "https://github.com/ismailakbudak/beego-api-example",
"heroku": {
"install" : [ "./..." ],
"goVersion": "go1.11"
},
"ignore": "test",
"package": [],
"rootPath": "reporting-api"
}
Add heroku tag like above example. There is a information about this configuration on heroku docs in here https://devcenter.heroku.com/articles/go-dependencies-via-govendor#build-configuration
2. After this add beego package dependency with this command
$ govendor fetch github.com/astaxie/beego
It will download the beego packages to ./vendor directory
3. Lastly you should configure listen ports and beego runmode as prod for heroku in main.go file
To deploy your app without problem, default config must be runmode = prod in conf/app.conf. I tried to set it default as dev and change it from heroku config vars as below, but it compiles packages before the set runmode and gives exception with this message panic: you are running in dev mode.
func main() {
log.Println("Env $PORT :", os.Getenv("PORT"))
if os.Getenv("PORT") != "" {
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
log.Fatal(err)
log.Fatal("$PORT must be set")
}
log.Println("port : ", port)
beego.BConfig.Listen.HTTPPort = port
beego.BConfig.Listen.HTTPSPort = port
}
if os.Getenv("BEEGO_ENV") != "" {
log.Println("Env $BEEGO_ENV :", os.Getenv("BEEGO_ENV"))
beego.BConfig.RunMode = os.Getenv("BEEGO_ENV")
}
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/"] = "swagger"
beego.Run()
}
You can use BEEGO_ENV=dev bee run to continue develop your app without change it again

Heroku release phase bundle not found

I have the following release phase in my Procfile:
release: bundle exec rake db:migrate
It works great when I merge PR's into my staging and production apps, but it fails when running on a new review app. The Heroku docs say that the release phase is run after a successful build, so I don't know why it can't find bundle.
This is my output
heroku releases:output 9 --app my-app-pr-253
/bin/sh: 1: bundle: not found
For Heroku's review apps, you must specify all buildpacks and ENV vars you need in the app.json file. You can either manually create one, or have Heroku generate one for you.
https://devcenter.heroku.com/articles/github-integration-review-apps#app-json
Confirm that in your app.json you have specified
1) The required buildpacks https://devcenter.heroku.com/changelog-items/670. Since you are using bundle I'm guessing heroku/ruby will be one. Below is an example.
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-ruby.git"
},
2) Also make sure you specify any config variables that you want to inherit from the app off which your review app is being built. https://devcenter.heroku.com/articles/app-json-schema#env Missing one of these could also be causing a build to fail.
If neither of these work, try checking the logs for your heroku app. Watch the ones in the Heroku GUI during the build. Also try to tail the logs in the CLI.
heroku logs -t -a <review_app_name>
I figured out my problem. It was a silly typo:
"buildpacks": [
{
"url": "heroku/ruby",
"url": "https://github.com/guillaume-tgl/heroku-buildpack-ghostscript.git"
}
]
should have been:
"buildpacks": [
{ "url": "heroku/ruby"},
{ "url": "https://github.com/guillaume-tgl/heroku-buildpack-ghostscript.git" }
]

Using Heroku Scheduler add-on with Golang app

I can't figure out how to use the Heroku Scheduler add-on with Go.
I would like run a separate Go file periodically, but I can find the command to achieve that.
From Heroku's doc (https://devcenter.heroku.com/articles/scheduler), if the app is not a Rails app, I should use a ruby script. But I don't know how to run a Go file from there.
I ended up forking the same main function used by my web dyno:
func main () {
if len(os.Args) >= 2 && os.Args[1] == "my_job_param" {
// Execute job.
} else {
// Set up my web server with port, router, etc.
}
}
Then, in the Scheduler add-on, I just call: my-app-name "my_job_param". It's pretty hacky, but I wanted to find a solution using the Scheduler add-on.
The typical pattern is to do something like:
.
└── cmd
├── processX
│ └── main.go
└── web
└── main.go
And you set heroku.install to ["./cmd/..."] and Heroku compiles and installs both commands into bin, so you get a bin/web and a bin/processX (processX is just a placeholder, whatever the name of the directory that contains a main package is the name of the resulting executable). In the above case your Procfile would say web: web, the first web being the process type, the second being the name of the executable. And the job you would tell scheduler to run would be processX.
That cleanly separates responsibilities
The Heroku scheduler will run any terminal command basically. So, if you compile your script into an executable called myscript, for example, you could simply put:
myscript
In the scheduler and it will execute that command, thereby running your script =) No ruby is required.

Set host name as an environment variable in Heroku review app

I'm using the Review Apps feature integrated with Github on Heroku. In one of my apps, I set an environment variable called HOST_NAME . For example, if the site is http://www.purplebinder.com, then HOST_NAME would be set to www.purplebinder.com. It's used in a couple of places where we work with cookies and in our transactional emails.
When I open up a new pull request and spin up a review app, HOST_NAME should be something like purplebinder-pr-27.herokuapp.com.
Is there a way to set this value automatically? The Heroku documentation on review apps says an env var can inherit a value from the parent app or be hardcoded in app.json. Neither of those approaches work here, because the value needs to be different each time, and also different from the parent app.
Heroku also says an env var can be set "through a generator", but doesn't go into detail about what that is.
This question might be a duplicate of Setting ROOT_URL for Review Apps, but nobody answered that one. It's also similar to How to get Heroku app name from inside the app, but the answers there involved running a script after the app was created - here I'd like to set this value as part of the initial build.
From https://devcenter.heroku.com/articles/github-integration-review-apps#heroku_app_name-and-heroku_parent_app_name:
To help with scripting, two special config vars are available to
review apps. If you specify HEROKU_APP_NAME or HEROKU_PARENT_APP_NAME
as required or optional config vars in your app.json file, Heroku will
set those config vars to the new application name and the parent
application name respectively. They will then be available for use in
the postdeploy script so that you can do more advanced bootstrapping
and configuration.
Here is an example app.json file that uses
HEROKU_APP_NAME and HEROKU_PARENT_APP_NAME:
{
"name":"Advanced App",
"scripts": {
"postdeploy": "rake db:setup && bin/bootstrap"
},
"env": {
"HEROKU_APP_NAME": {
"required": true
},
"HEROKU_PARENT_APP_NAME": {
"required": true
}
}
}
If you add the heroku-buildpack-cli to your parent app, then it enables you to set environment variables from your post-deploy script. The command should look something like the following:
heroku config:set HOST_NAME=${HEROKU_APP_NAME}.herokuapp.com --app ${HEROKU_APP_NAME}
Here's an approach ignoring app.json for Rails installations:
in the relative config/<environment>.rb. I personally use production.rb and staging just references it.
if ENV.fetch("HEROKU_APP_NAME", "").include?("staging-pr-")
ENV["APPLICATION_HOST"] = ENV["HEROKU_APP_NAME"] + ".herokuapp.com"
ENV["ASSET_HOST"] = "https://" + ENV["APPLICATION_HOST"]
config.action_mailer.default_url_options = { host: ENV.fetch("APPLICATION_HOST") }
end
...
It's a bit misleading as the heroku environment variables will still have the old variables, but it works.
You can also create review environment for you application copying staging.rb or production.rb from config/environments. This would be useful.
After adding HEROKU_APP_NAME and HEROKU_PARENT_APP_NAME to your app.json, you can easily set;
config.action_mailer.default_url_options = { host: "#{ENV['HEROKU_APP_NAME']}.herokuapp.com" }
config.action_mailer.asset_host = "http://#{ENV['HEROKU_APP_NAME']}.herokuapp.com"
config.action_controller.asset_host = "#{ENV['HEROKU_APP_NAME']}.herokuapp.com"
config.action_cable.url = "wss://#{ENV['HEROKU_APP_NAME']}.herokuapp.com/cable"

Resources