Go application deployment in Bluemix fails - go

I am facing issues with pushing the sample Go applicaiton in Bluemix.
I will explain the steps I followed to push the applicaiton.
Created D:/goapp2016 and set it to GOPATH.
created src, pkg and bin folders in D:/goapp2016
In src, created "myapp" folder and written a sample app.go file.
Ran "go get" command inside GOPATH/src/myapp and that downloaded the libraries from Git in GOAPTH/src folder and mysql.a,native.a files in D:\goapp2016\pkg\windows_amd64\github.com\ziutek\mymysql. And myapp.exe is also created in GOPATH/bin after running go get command.
Ran "godep save" command which created Godeps/Godeps.json and vendor/(dependent libraries) folder in GOPATH/src/myapp.
To push the application to bluemix, I executed cf push command from GOPATH directory.
But, this is giving the below error.
-------> Buildpack version 1.7.5
file:///var/vcap/data/dea_next/admin_buildpacks/e57c0cd5-3b42-424d-ad32-b0bee17b
c1b0_a25a466217b64d5e4d47a6796be8ab23e7b7eeaf/dependencies/https___pivotal-build
packs.s3.amazonaws.com_concourse-binaries_godep_godep-v62-linux-x64.tgz
-----> Installing go1.6... done
Downloaded [file:///var/vcap/data/dea_next/admin_buildpacks/e57c0cd5-3b42-424d-a
d32-b0bee17bc1b0_a25a466217b64d5e4d47a6796be8ab23e7b7eeaf/dependencies/https___s
torage.googleapis.com_golang_go1.6.linux-amd64.tar.gz]
!
! Error: Cloud Foundry does not support the GB package manager
! We currently only support the 'Godep' package manager for go apps
! For support please file an issue: https://github.com/cloudfoundry/go- buildpack/issues
!
Staging failed: Buildpack compilation step failed
Directory Structure:
goapp2016/
bin/
godep.exe
myapp.exe
pkg/
windows_amd64/
github.com/
tools/
godep/
ziutek/
mymysql
src/
github.com/
ziutek/
myapp/
app.go
Godeps/
Godeps.json
vendor/
github.com/
ziutek/
manifest.yml
Procfile
Am I missing anything here?

The compile file for the buildpack can be seen here: https://github.com/cloudfoundry/go-buildpack/blob/master/bin/compile
Dependency tool selection begins on line 136, as long as there is a Godeps/Godeps.json file, the buildpack should used godeps, not GB. Are you sure you are pushing from the folder than contains the Godeps folder, that in turn contains the Godeps.json file?

Related

Problem that clone project cannot be run due to gitignore

I'm using gitignore, and I'm good at push and pull for personal management.
The focus is on my own creation, so I have all the configuration files, so it runs well locally.
However, if I "Clone" this project and download it to an empty folder, it cannot be run anywhere.
It seems as if there is no configuration file necessary for project configuration or server execution.
I am attaching my gitignore.
Is this what gitignore originally intended?
I want to clone a project so that it can run.
Do I have to delete gitignore to do that?
p.s If I delete gitignore and clone all projects (including build artifacts) it works fine.
use tool & etc : Intellij, Spring, Tomcat
### Java template
*.class
# Package Files #
*.jar
*.war
*.ear
### macOS template
*.DS_Store
.AppleDouble
.LSOverride
# IntelliJ project files
.idea
.idea/*.xml
*.iml
out
gen
build
rebel.xml
# Compliled files
/target/
**/target
/example/
# Gradle
.gradle
/build/
.gradletasknamecache
Normally, you don't distribute compiled binaries with your git repo. The convention is to either have users compile the code locally, or distribute that code using a package management system like Maven, Ivy, npm, Nuget, pip or gem. This isn't a hard and fast rule however.

How can I use a local repository in the vendor in Google Cloud Functions with Go

I'm trying to deploy a Google Cloud Function written in Go.
By doing some research I found out that vendor files are prefered over go.mod so I'm vendoring everything I use (which includes some local dependencies) and ignoring the go.mod/sum files in the .gcloudignore file.
The problem is that after trying to deploy, I get the following error:
go: nimbus#v0.0.0-00010101000000-000000000000: parsing /nimbus/go.mod: open /nimbus/go.mod: no such file or directory; Error ID: 03a1e2f7
nimbus is my local dependency and it has the following structure:
My Function repository has the following structrure:
and my go.mod file is:
module my_function
go 1.13
require nimbus v0.0.0-00010101000000-000000000000
replace nimbus => ../../../nimbus
I've tried this solution https://stackoverflow.com/questions/5441096 already. But it did not fix my issue.
I've tried everything to solve this issue, but nothing seems to work.
If you have a go.mod file and a vendor directory, the vendor directory will be ignored when you deploy your function.
https://cloud.google.com/functions/docs/writing/specifying-dependencies-go
I have used modules when deploying GCP functions in Go. Haven't had any problems. But I can't speak to the preference of using vendor/ instead. It should work, just without the go.mod file.
Turns out the problem was very complicated and I hope Google finds a solution for it asp.
By deploying my function using Cloud Build, It would read from my repository on Google Source, but, by reading from there it would bypass the .gcloudignore file and deploy both the go.mod/sum files and the vendor directory with my local code.
As said in https://stackoverflow.com/a/62050872/10316247:
If you have a go.mod file and a vendor directory, the vendor directory will be ignored when you deploy your function.
So the error would occur because of my go.mod not being able to find local repository.
My solution was to rename my go.mod/sum files so it would not be considered:
When you use golang 1.16 and specify golang 1.16 in the go.mod folder it will instead default to using the vendor files with the --mod=vendor flag set, which will solve this issue.
You'll just need to ensure your module name is formatted correctly (something like example.com/module).

How to use modules replace functionality in cloud functions

I have a google cloud function that is a subdirectory in a repository. It uses the "Directory with source code" option in the settings menu. I keep getting this error on deploy:
Deployment failure:
Build failed: go: parsing /utils/pubsub/go.mod: open /utils/pubsub/go.mod: no such file or directory
go: error loading module requirements
I'm assuming that GCF does not upload the entire directory to the instance, but instead only the folder? This breaks the replace functionality of Go modules. Is there something I am doing wrong?
Link to the repo: https://github.com/FreekingDean/jeffbotgo/tree/5d735cc/slackevent
I work at Google and on this product.
Only the directory where you run gcloud is uploaded. There is no staging step beyond zipping the current directory and uploading it.
Notably, modules are preferred by the builder over vendor. If there is a go.mod, modules will be used. When you upload your function, it only includes the directory with your function at the root, not any directories one level up. So, when there is a go.mod and you have a replace directive pointing one level up, it will not work.
The solution for now with this layout is to vendor and not upload the go.mod/go.sum files. When using gcloud, you can create a .gcloudignore file to do this for you. See https://cloud.google.com/functions/docs/concepts/go-runtime#specifying_dependencies for more detail. Alternatively, modify your project to include any necessary helper packages in subdirectories.
I had the same issue today.
When reading thru the documentation for the 8th time i came across a warning box bellow the "Vendor directory" headline.
Warning: If your project has both a go.mod file and a vendor directory
at the root of your project, the vendor directory will be ignored
during deployment. You must use a .gcloudignore file to ignore the
go.mod file in order to ensure that your vendor directory is used
during deployment.
So basically once i added a .gcloudignore file with go.mod (will add go.sum as well) everything worked. So i guess if you have a go.mod file the cloud function will try to fetch dependencies instead of using the ones uploaded in the vendor folder.
I'm just guessing here tough.

Gitlab CI - Auto DevOps job failed, Unable to select a buildpack for a Go project?

My Gitlab CI Auto DevOps job failed with
Status: Downloaded newer image for gliderlabs/herokuish:latest
-----> Unable to select a buildpack
ERROR: Job failed: exit code 1
I've gone through
Auto DevOps and
Getting started with Auto DevOps
and am still not sure where I should put the buildpack.
Mine should be heroku-buildpack-go, which I've lost track where I get that from.
My repo consist only a single-character README.md, and the "Hello, playground" main.go.
Conclusion:
Thanks to David's comprehensive explanation, I was able to get DevOps started with correct buildpack:
From this I would conclude that your single .go file at the root of the directory tree does not meet the activation criteria for auto-building Go projects. I'd suggest picking one of the dependency managers in the requirements above and modifying your project to support it.
FTA, I just did touch go.mod then git add & git push and the AutoDevops started building my GO project indeed.
However it seems to me that Gitlab AutoDevops is not able to build any GO projects very easily, as I get the following error (with project variable TRACE=true):
...
!! The go.mod file for this project does not specify a Go version
!!
!! Defaulting to go1.11.1
!!
!! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
!!
-----> Installing go1.11.1
-----> Fetching go1.11.1.linux-amd64.tar.gz... done
!! Installing package '.' (default)
!!
!! To install a different package spec add a comment in the following form to your `go.mod` file:
!! // +heroku install ./cmd/...
!!
!! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
!!
-----> Running: go install -v -tags heroku .
go: cannot determine module path for source directory /tmp/build (outside GOPATH, no import comments)
ERROR: Job failed: exit code 1
The easier solution is to use .gitlab-ci.yml file instead, documented in
https://blog.boatswain.io/post/build-go-project-with-gitlab-ci/
(and followed up at Gitlab CI - Start Shared Runner for normal repos).
From the AutoDevops documentation:
Auto Build creates a build of the application in one of two ways:
If there is a Dockerfile, it will use docker build to create a Docker image.
Otherwise, it will use Herokuish and Heroku buildpacks to automatically detect and build the application into a Docker image.
Then looking at the build activation criteria, as per the Heroku Go buildpack documentation:
This buildpack will detect your repository as Go if you are using either:
go modules
dep
govendor
glide
GB
Godep
Or more specifically for godep, govendor or GB:
The Heroku Go buildpack is used when an application meets one of the following requirements:
has a Godeps/Godeps.json file, identifying the application as being managed by godep;
has a vendor/vendor.json file, identifying the application as being managed by govendor;
has a src directory, which has sub directories, contains one or more .go files, identifying the application as being managed by gb.
From this I would conclude that your single .go file at the root of the directory tree does not meet the activation criteria for auto-building Go projects. I'd suggest picking one of the dependency managers in the requirements above and modifying your project to support it. After that AutoDevops should start building your project.
If you are still having issues after that, this debugging note might help:
After making sure that the project meets the buildpack requirements;
if it still fails, setting a project variable TRACE=true will enable verbose logging which​ may help to continue troubleshooting.

Deploy WebSharper.Suave web application to Heroku

I can not understand what I need to change to make it.
I created a demo project from this blogpost with app.json and Procfile:
web: fsharpi-heroku WebsahrperSuaveHerokuExample1.sln
Next, I tried to deploy it to Heroku in accordance with these recommendations:
heroku create websahrper-with-suave-example --buildpack https://github.com/SuaveIO/mono-script-buildpack.git
heroku git:remote -a websahrper-with-suave-example
git push heroku master
There was an error in Heroku when building the project:
...
Import process completed.
-----> packages.config found, installing dependencies with nuget
Cannot open assembly 'install': No such file or directory.
! Push rejected, failed to compile SuaveFramework app
Could you suggest me a solution if there is one?
Have you tried here:
https://github.com/SuaveIO/heroku-getting-started
Fork it and click the Deploy to Heroku button.
Don't have the rep to comment on the above, but ademar's solution should cover as well as long as you don't have a file named "app.fsx"
The heroku buildpack checks to see if there is a script, then checks for a solution:
https://github.com/SuaveIO/mono-script-buildpack/blob/master/bin/compile#L66
Just make sure there is a .sln file in the project directory (can be empty, just needs to be present) or fork the buildpack and just make it default run mono $YOURPROJECT in the compile step.
When using an sln instead of a script, you need to change your Procfile to:
web: mono Path/execName.exe

Resources