How to deploy a Go application to Bluemix? - go

I am using Bluemix to run app, I can deploy Java app to Bluemix, does anyone know how to deploy a Go App to Bluemix?

You can deploy a Go application to Bluemix, but need to supply -b with the Go Buildpack URL.
There is a sample application you can take a look:
https://github.com/acostry/Go-on-Bluemix

You need to use a custom buildpack to deploy a Go web application. So, login to your cloud and run the cf command below from the root folder of your application:
cf push appname -b https://github.com/cloudfoundry/cloudfoundry-buildpack-go

Actually, Bluemix now includes the Cloud Foundry Go buildpack https://github.com/cloudfoundry/go-buildpack in its catalog. Hence, it should be unnecessary to resort to use of the BYOB feature.
API endpoint: https://api.ng.bluemix.net (API version: 2.19.0)
mbp:utils cbf$ cf buildpacks
Getting buildpacks...
buildpack position enabled locked filename
liberty-for-java 1 true false buildpack_liberty-for-java_v1.15-20150402-1422-yp.zip
sdk-for-nodejs 2 true false buildpack_sdk-for-nodejs_v1.15-20150331-2231-yp.zip
noop-buildpack 3 true false noop-buildpack-20140311-1519.zip
java_buildpack 4 true false java-buildpack-v2.6.zip
ruby_buildpack 5 true false ruby_buildpack-offline-v1.2.0.zip
nodejs_buildpack 6 true false nodejs_buildpack-offline-v1.1.1.zip
go_buildpack 7 true false go_buildpack-offline-v1.1.1.zip
python_buildpack 8 true false python_buildpack-offline-v1.1.1.zip
php_buildpack 9 true false php_buildpack-offline-v1.0.2.zip
liberty-for-java_v1-14-20150319-1159 10 true false buildpack_liberty-for-java_v1.14-20150319-1159-yp.zip
sdk-for-nodejs_v1-14-20150309-1555 11 true false buildpack_sdk-for-nodejs_v1.14-20150309-1555-yp.zip

Just to be clear the full command would be the following.
cf push appname -b https://github.com/cloudfoundry/go-buildpack.git

You have to include "-b" option while pushing your go app on Bluemix cloud.
cf push app_name -b buildpack_URL
For any other types of app, you can refer below link for pushing app on bluemix:
https://www.ng.bluemix.net/docs/#starters/byob.html.

Issue the following command with the -b option to deploy your application with your own buildpack, in which buildpack_URL is the URL of the buildpack:
$ cf push app_name -b buildpack_URL
More specifically
cf push app_name -b https://github.com/cloudfoundry/go-buildpack.git
more info is below:
https://www.ng.bluemix.net/docs/#starters/byob.html.

Deploying the app to Bluemix is pretty much the same as deploying any other app, with the exception of a command-line flag to set the custom buildpack the platform should use to provision the runtime.
Log in to your Bluemix account and run this command from the root folder of your application, where appname represents a unique name for your Bluemix-hosted app:
cf push appname -b url
More details regrading creating/pushing/deploying/connecting can be found at http://www.ibm.com/developerworks/cloud/library/cl-bluemix-go-app/

Related

Couldn't connect to GitHub while authenicating to github on heroku

I had created a app on heroku on authenticating to github it say
Error: remote was closed, authorization was denied, or an authentication message otherwise not received before the window closed..
How can i fix that
I was also facing the same error in Google Chrome.
Error: remote was closed, authorization was denied, or an authentication message otherwise not received before the window closed.`
I tried opening in Chrome's Incognito mode and it worked for me.
Again, I tried using Firefox and it also worked! 🎉
I guess it's for pushing an app on heroku, so if it's that you can use a action on the GitHub marketplace to do so :
You have this one : heroku deploy
You will have to set you heroku key in secrets on repository settings before and set your workflow just like this:
name: Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: akhileshns/heroku-deploy#v3.0.4 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
heroku_email: "YOUR EMAIL"
buildpack: "SOME BUILDPACK" #OPTIONAL
branch: "YOUR_BRANCH" #OPTIONAL and DEFAULT - 'HEAD' (a.k.a your current branch)
dontuseforce: false #OPTIONAL and DEFAULT - false
usedocker: false #OPTIONAL and DEFAULT - false
appdir: "" #OPTIONAL and DEFAULT - "". This is useful if the api you're deploying is in a subfolder
I hope it helps.

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.

Heroku custom buildpack fsharp

When you deploy the https://github.com/SuaveIO/heroku-getting-started example project to Heroku, the correct fsharp buildpack is used (specified in the app.json file). Like so:
{
"name": "Sample Suave web app",
"description": "Sample single-script Suave web app, deployable to Heroku.",
"website": "http://suave.io/",
"repository": "https://github.com/SuaveIO/heroku-getting-started",
"logo": "https://raw.githubusercontent.com/SuaveIO/suave/gh-pages/images/logo.gif",
"env": {
"BUILDPACK_URL": "https://github.com/SuaveIO/mono-script-buildpack.git"
}
}
However, if you want to deploy directly from github, the custom buildpack isn't used.
The only way to get this running is by manually specifying the BUILPACK_URL config var in the web api of the web app. So, why is this config var specified by the app.json not used? Is there another way of specifying this config var, without having to add this manually to the dashboard -> settings -> config vars of the web app?
Instead of using app.json, you can use heroku buildpacks command to set/remove/clear buildpacks. Here is the output of command heroku buildpacks -h:
buildpacks:add BUILDPACK_URL # add new app buildpack, inserting into list of buildpacks if neccessary
buildpacks:clear # clear all buildpacks set on the app
buildpacks:remove [BUILDPACK_URL] # remove a buildpack set on the app
buildpacks:set BUILDPACK_URL # set new app buildpack, overwriting into list of buildpacks if neccessary
The heroku toolbelt can be found here: https://toolbelt.heroku.com

Heroku + Grails - missing DATABASE_URL when building app on heroku

I'm trying to connect my application to Shared Database 5MB using grails tutorial. I'm using grails 2.1.0. On my local machine when I run heroku config I can see that DATABASE_URL is set, but after executing git push... my build stops with error:
Error packaging application: Error loading DataSource.groovy: null (Use --stacktrace to see the full trace)
Failed to build app
Heroku push rejected, failed to compile Grails app
So I've added logging to see how environment looks on heroku. I've added println System.env to Datasource.groovy and I cannot find any DATABASE_URL:
.[OLDPWD:/app/tmp/repo.git/.cache, SHELL:/bin/bash, SHLVL:2, GIT_DIR:., JAVA_HOME:/usr/lib/jvm/java-6-openjdk, PATH:/app/tmp/repo.git/.cache/.grails/bin::/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin, SSH_CLIENT:XXX, MAIL:XXX, USER:XXX, LOG_TOKEN:t.9e79a5be-dfa2-446e-9f83-f6b4ebbc4eb7, GRAILS_HOME:/app/tmp/repo.git/.cache/.grails, PWD:XXX, HOME:/app/, LOGNAME:u11846, _:/app/tmp/repo.git/.cache/.grails/bin/grails, SSH_CONNECTION:XXX, LD_LIBRARY_PATH:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64]
I have checked with heroku addons that for my application shared database is installed:
heroku addons
=== XXX Configured Add-ons
shared-database:5mb
and when I execute heroku config
heroku config
=== Config Vars for XXX
DATABASE_URL: postgres://XXX
JAVA_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops
SHARED_DATABASE_URL: postgres://XXX
Datasource.groovy:
production {
dataSource {
dbCreate = "update"
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
println System.env
println System.env.DATABASE_URL
uri = new URI(System.env.DATABASE_URL)
println uri
url = "jdbc:postgresql://" + uri.host + uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
}
}
In BuildConfig.groovy I've added
runtime 'postgresql:postgresql:8.4-702.jdbc3'
I can launch application locally with DATABASE_URL set to local postgresql. I'm building war and running it on jetty.
Can anyone tell me what am I missing?
The application environment variables are not available at build time. Your code needs to be able to handle that accordingly. Or you can enable the new user_env_compile Heroku Labs feature that does enable the environment variables to be there at build time: https://devcenter.heroku.com/articles/labs-user-env-compile

How to increase ActiveRecord thread pool size on heroku

Normally I would set the pool size as
development:
adapter: postgresql
encoding: unicode
database: openkitchen_development
username: rails
host: localhost
pool: 10
password:
in database.yml. However heroku replaces the config file. I'm using girl_friday to
do background db work and need to increase the thread pool size.
Simply add a pool query parameter to the DATABASE_URL in your heroku config. To set the pool size to 15 in your heroku app use something like:
heroku config -s | awk '/^DATABASE_URL=/{print $0 "?pool=15"}' | xargs heroku config:add
For what it's worth, using the URL params method as described in other answers here is not recommended by Heroku. They reserve the right to reset or change this URL at any time, and long term this behavior will likely be removed for the Rails build behavior, anyway.
Setting additional parameters via an after-initialize application callback is the recommended way to modify the configuration of your heroku-postgresql databases per this dev center article.
In config/initializers/database_connection.rb:
Rails.application.config.after_initialize do
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['pool'] = 10
ActiveRecord::Base.establish_connection(config)
end
end
Heroku now has a nice article on managing pool sizes - https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool
remvee's answer gets to the heart of what is needed but since his command caused my console to hang I thought I would write up how to do this manually.
heroku config
Look for the DATABASE_URL key. For this example lets say it is:
DATABASE_URL: mysql2://something.example.com/stuff?reconnect=true
Add "&pool=10" to the end of the URL (use & instead of ? because the url already has a parameter)
heroku config:add DATABASE_URL=mysql2://something.example.com/stuff?reconnect=true&pool=10
It's not very straight forward but you could try creating your own buildpack.
You'll nee to fork:
https://github.com/heroku/heroku-buildpack-ruby
Then modify the following:
https://github.com/heroku/heroku-buildpack-ruby/blob/master/lib/language_pack/ruby.rb#L325-387
Just add the pool size you require.
Then you can create a new Heroku app with your custom buildpack:
heroku create --stack cedar --buildpack https://github.com/yourgithubusername/heroku-buildpack-ruby.git
That should be it!

Resources