How to deploy Go apps with internal package to Heroku using `dep` - go

I am using Heroku's Golang buildpack to deploy a simple web app with the following structure
my-app/
handler/
user.go
session.go
vendor/
github.com/
golang.org/
main.go
Gopkg.toml
Gopkg.lock
Inside my main file, I imported my own handler package
import (
"fmt"
"net/http"
"my-app/handler"
)
Heroku was not able to run go install on my project due the following error:
----> Using go1.9.3
----> Running: go install -v -tags heroku .
----> cannot find package "my-app/handler" in any of: ...
I can run go install and my-app without any problem locally. It seems to me that heroku does not recognize my internal project package.
I am using dep and I have the following configurations in my Gopkg.toml:
[metadata.heroku]
root-package = "github.com/mygithub/my-app"
go-version = "go1.9.3"
install = ["."]
ensure = "false"
What else do I need to do to deploy a Go app with internal package? Thanks.

Try to set the root package to just the name of the project without the domain
[metadata.heroku]
root-package = "my-app"
go-version = "go1.9.2"
install = [ "./..." ]

Related

Why does terraformer not find plugin?

I am new to the world of terraform. I am trying to use terraformer on a GCP project, but keep getting plugin not found:
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --connect=true --
regions=europe-west1,europe-west4 --projects=myproj
2021/02/12 08:17:03 google importing project myproj region europe-west1
2021/02/12 08:17:04 google importing... gcs
2021/02/12 08:17:05 open \.terraform.d/plugins/windows_amd64: The system cannot find the path specified.
Prior to the above, installed terraformer thus: choco install terraformer I downloaded the Google provider, terraform-provider-google_v3.56.0_x5.exe, placed it in my terraform dir, and did terraform init. I checked %AppData\Roaming\terraform.d\plugins\windows_amd64 and the plugins\windows_amd64 did not exist, so I created it, dropped in the Google exe and redid the init.
My main.tf was:
provider "google" {
project = "{myproj"
region = "europe-west2"
zone = "europe-west2-a"
}
Could it be the chocolatey install causing this issue? I have never used it before but the alternative install looks daunting!
If you install from Chocolatey, it seems it looks for the provider files at C:\.terraform.d\plugins\windows_amd64. If you create those directories and drop the terraform-provider-xxx.exe file in there it will be picked up.
I would also suggest running it with the --verbose flag.
Remember to execute "terraform init"
Once you install the terraformer, check this
Create the versions.tf file
versions.tf example
terraform {
required_providers {
google = {
source = "hashicorp/aws"
}
}
required_version = ">= 0.13"
}
Execute terraform init
Start the import process, something like:
terraformer import aws --profile [my-aws-profile] --resources="*" --regions=eu-west-1
Where --resources="*" will get everything from aws, but you could specify route53 or other resources
terraformer import aws --profile [my-aws-profile] --resources="route53" --regions=eu-west-1
The daunting instructions worked!
Run git clone <terraformer repo>
Run go mod download
Run go build -v for all providers OR build with one provider go run build/main.go {google,aws,azure,kubernetes and etc}
Run terraform init against an versions.tf file to install the plugins required for your platform. For example, if you need plugins for the google provider, versions.tf should contain:
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
required_version = ">= 0.13"
}
making sure to run that version and not the chocolatey one.
go mod download the flag -x will give output while that command runs, otherwise you might think nothing is happening.

Kubernetes client go couldn't find module

I'm trying to connect to my local Kubernetes cluster hosted on minikube, here's the code for the same, now when I do go run minikube.go, it gives me an error saying:
../../../pkg/mod/k8s.io/client-go#v11.0.0+incompatible/kubernetes/scheme/register.go:26:2: module k8s.io/api#latest found (v0.19.0), but does not contain package k8s.io/api/auditregistration/v1alpha1`.
Now, I tried to manually install the package using go get then I found out that this package does not exist.
How can I make it work and fix this?.
My go.mod file in case anyone wants to see that.
Always specify matching versions of all three k8s.io/... components in your go.mod file
require (
...
k8s.io/api v0.19.0
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
...
)

Golang google cloud functions using go modules fail build when importing subdirectories

I am trying to deploy a google cloud function using go modules and I am having problem with it picking up code in subdirectories when using go modules.
It appears that inside the gcloud functions deploy build it is duplicating the package name. So for instance locally (and what i expect is this import)
import "github.com/lwaddicor/gofunctionmodules/demoa"
however it will only work in the gcloud functions deploy if set to
import "github.com/lwaddicor/gofunctionmodules/gofunctionmodules/demoa"
If anyone has any ideas what is happening here it would be much appreciated. Thanks
Structure
demoa/demo.go
func.go
go.mod
go.mod
module github.com/lwaddicor/gofunctionmodules
go 1.13
func.go
package gofunctionmodules
import (
"net/http"
// This is what i would expect, and it builds locally but it wont deploy
"github.com/lwaddicor/gofunctionmodules/demoa"
// With this one it deploys but locally wont build
//"github.com/lwaddicor/gofunctionmodules/gocloudfunctions/demoa"
)
// Demo demonstrates the issue with package management in cloud functions
func Demo(w http.ResponseWriter, r *http.Request) {
w.Write(demo.Demo())
}
package demoa
// Demo returns a demo string
func Demo() []byte {
return []byte("demo")
}
Then deploying a new cloud function using
gcloud functions deploy demofunction --entry-point Demo --project my-demo-project --runtime go113 --trigger-http --allow-unauthenticated
Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: {"error":{"errorType":2,"canonicalCode":2,"errorId":"32633c29","errorMessage":"
serverless_function_app imports
github.com/lwaddicor/gofunctionmodules/gofunctionmodules imports
github.com/lwaddicor/gofunctionmodules/gocloudfunctions/demo: git ls-remote -q origin in /layers/google.go.gomod/gopath/pkg/mod/cache/vcs/48848540be122d75f1d2e6549925c34394ce402803530dc7962ab1442de3b180: exit status 128:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information."}}
Edit: removed the github link as it just downloaded the dependency from the public github repo. Changed demo package to demoa to prevent using cached github copy

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.

Writing an openshift extension

Trying to understand how one builds a tool consuming the Openshift Origin and Kubernetes APIs (I'm new to Go). It seems that I have a version of Kubernetes installed from Openshift and another version installed by godep and I'm getting all sorts of exciting version mismatches.
Here's my code so far:
package main
import (
kclient "k8s.io/kubernetes/pkg/client/unversioned"
client "github.com/openshift/origin/pkg/client"
)
func main() {
config := kclient.Config{
Host: "...",
}
client.SetOpenShiftDefaults(&config)
client := client.NewOrDie(&config)
}
I then did a go get github.com/openshift/origin which I can see has a copy of Kubernetes in it's Godeps/_workspace/src directory.
However when I do a godep save I get:
godep: Package (k8s.io/kubernetes/pkg/client/unversioned) not found
If I do a go get to install Kubernetes I get a version that doesn't match with the version used by Openshift. What's the correct way to do this?

Resources