Gitlab CI and Go modules - go

I have a Go project and I want write a Gitlab CI file my project but I see error loading module requirements. This is my gitlab CI file:
stages:
- compile
build:
stage: compile
image: golang:1.12
script:
- go build -o binary
error :
Running with gitlab-runner 11.8.0 (4745a6f3)
on Runner #6 e0e0c446
Using Docker executor with image golang:1.12 ...
Pulling docker image golang:1.12 ...
Using docker image sha256:be63d15101cb68aea1841b45201b08a1a486c1a60a029bbf0ddb284ab646b0b7 for golang:1.12 ...
Running on runner-e0e0c446-project-753-concurrent-0 via runner-01.tool.afra.snapp.infra...
Cloning repository...
Cloning into '/builds/Alsopa/echo-training'...
Checking out ab3994cc as develop...
Skipping Git submodules setup
$ go build -o binary
go: finding github.com/labstack/gommon v0.2.9
go: finding github.com/labstack/echo v3.3.10+incompatible
go: finding github.com/go-sql-driver/mysql v1.4.1
go: google.golang.org/appengine#v1.6.1: unrecognized import path "google.golang.org/appengine" (parse https://google.golang.org/appengine?go-get=1: no go-import meta tags ())
go: error loading module requirements
ERROR: Job failed: exit code 1

Be sure you upload the last go.sum file. Just before uploading to master for the ci execution run go get, upload to master and run the ci.

The primary error seems to be:
go: google.golang.org/appengine#v1.6.1: unrecognized import path
"google.golang.org/appengine" (parse
https://google.golang.org/appengine?go-get=1: no go-import meta tags ())
I would try running go get -v google.golang.org/appengine and curl -v https://google.golang.org/appengine?go-get=1 from within your CI environment to see what they show.
This is what I get for go get -v google.golang.org/appengine:
$ go get -v google.golang.org/appengine
Fetching https://google.golang.org/appengine?go-get=1
Parsing meta tags from https://google.golang.org/appengine?go-get=1 (status code 200)
get "google.golang.org/appengine": found meta tag
get.metaImport{Prefix:"google.golang.org/appengine",
VCS:"git", RepoRoot:"https://github.com/golang/appengine"}
at https://google.golang.org/appengine?go-get=1
Perhaps you have some network connectivity, firewall, or HTTP proxy issue.

You should download modules before compilation. Assuming your project already has go modules files go.mod and go.sum try to update .gitlab-ci.yml this way
build:
stage: compile
image: golang:1.13
script:
- go get -d -v
- go build -o binary

Related

Module lookup disabled by GOPROXY=off golangci

I have a vendor folder and CI/CD task Linter. Before push the folder to gitlab I did
go mod tidy
go mod vendor
My Linter task in Makefile looks like
#GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off $(GOLINT) run ./... -v --max-same-issues 0
and I have no any problems when I start linting locally. But during CI/CD I got an error
Running error: context loading failed: failed to load packages: failed
to load with go/packages: err: exit status 1: stderr: go:
github.com/jmoiron/sqlx#v1.3.1: module lookup disabled by GOPROXY=off
So i can't understand why I got this error
Update
I decided to remove the vendor, go.mod and go.sum. Then I created new go.mod and did
go mod vendor
After that I got the same error but with another package
level=error msg="Running error: context loading failed: failed to load
packages: failed to load with go/packages: err: exit status 1: stderr:
go: github.com/fsnotify/fsnotify#v1.5.1: module lookup disabled by
GOPROXY=off
The problem was in the settings of golangci modules-download-mode
this solution is set this variable to vendor mode:
modules-download-mode: vendor

How to deploy GoLang Binaries to CF

Hi we are trying to deploy golang binaries to cf.
for example main.exe which is in /deploy/ folder along with mainfest file
Note: It is also observed that if we push the whole project app then it works. but if we try to push only binaries then we get the below error
And Manifest file contains following info
applications:
- name: test-app
command: test-app
env:
GO_INSTALL_PACKAGE_SPEC: ./
**ERROR** To use go native vendoring set the $GOPACKAGENAME
environment variable to your app's package name
**ERROR** Unable to determine import path: GOPACKAGENAME unset
After adding GOPACKAGENAME: main since main.exe is our binary name we get following error below
Failed to compile droplet: Failed to run finalize script: exit status 12
Cell 507b6e9c-c5c5-4685-9a71-d7cc1c876f5a stopping instance 6a92ff73-76ec-4baf-8a3e-54b54cfa307e
BuildpackCompileFailed - App staging failed in the buildpack compile phase
thanks #Volker for pointing out
for above issue:
first we have to build with following command (used make file)
GOOS="linux" go build main.go
then copy that main binary to /deploy folder
then manifest file in the deploy folder
applications:
- name: test-app
command: ./main
stack: cflinuxfs3
buildpacks:
- https://github.com/cloudfoundry/binary-buildpack.git
Then to push to cf
cf push -f ./manifest-template.yml

Using golang-ci lint error fetch corp package

Im using golangci-lint and getting the following error in CI, any idea what could be the reason? and how can I avoid this.
Our GitHub repo is already have all the vendor packages so it shouldn't install it in first place.
golangci-lint run --config golangci.yml
level=error msg="Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit
status 1: stderr: go: github.avt.corp/ding/logger-ut#v1.1.0:
unrecognized import path "github.avt.corp/ding/logger-ut" (https
fetch: Get https://github.avt.corp/ding/logger-ut?go-get=1: x509:
certificate signed by unknown authority)\n"
btw I was able to clone the project and run it
Use the following:
run:
modules-download-mode: vendor
or add this to the command you are runnig
--modules-download-mode vendor

The command "go get github.com/gohugoio/hugo" failed and exited with 2 during

I am building websites with Hugo and deploying using Travis-Ci. Recently (about within 3 days) an error occurred:
$ go get github.com/gohugoio/hugo
# github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort
../../gohugoio/hugo/tpl/internal/go_templates/fmtsort/sort.go:58:18: mapValue.MapRange undefined (type reflect.Value has no field or method MapRange)
The command "go get github.com/gohugoio/hugo" failed and exited with 2 during .
Since the code errored at go get line, I think it must be caused by some updates by Hugo.
.travis.yml
sudo: false
language: go
git:
depth: 1
install:
- go get github.com/gohugoio/hugo
script:
- git submodule init
- git submodule update
- hugo
# Deploy to GitHub pages
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: public
on:
branch: master
Since Hugo 0.48, Hugo uses the Go Modules support built into Go 1.11 to build.
docker run -it golang:1.10
root#2598ed7e489d: go get github.com/gohugoio/hugo
src/github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort/sort.go:58:18: mapValue.MapRange undefined (type reflect.Value has no field or method MapRange)
docker run -it golang:1.11
root#07e6e634656a: go get https://github.com/gohugoio/hugo
will not return any error
using go versions > 1.11 will not cause this issue.
In example 1,similar error is there.
In example 2,it is installed successfully.

Yocto build broken when setting a remote rpm repository with https

I have generated a Yocto image to be used on all my target devices. When that image is running on target devices, it must be able to be updated using a rpm remote repository through https protocol.
To try doing that, I have added a dnf bbappend to my custom layer:
$ cat recipes-devtools/dnf/dnf_%.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
file://yocto-adv-rpm.repo \
"
do_install_append () {
install -d ${D}/etc/yum.repos.d
install -m 0600 ${WORKDIR}/yocto-adv-rpm.repo ${D}/etc/yum.repos.d/yocto-adv-rpm.repo
}
FILES_${PN} += "/etc/yum.repos.d"
This is the content of repository configuration file included by dnf bbappend recipe:
$ cat recipes-devtools/dnf/files/yocto-adv-rpm.repo
[yocto-adv-rpm]
name=Rocko Yocto Repo
baseurl=https://storage.googleapis.com/my_repo/
gpgkey=https://storage.googleapis.com/my_repo/PACKAGEFEED-GPG-KEY-rocko
enabled=1
gpgcheck=1
This repository configuration breaks the build process of the image. When I try to build myimage recipe, I always get this error:
ERROR: myimage-1.0-r0 do_rootfs: [log_check] myimage: found 1 error message in the logfile:
[log_check] Failed to synchronize cache for repo 'yocto-adv-rpm', disabling.
ERROR: myimage-1.0-r0 do_rootfs: Function failed: do_rootfs
ERROR: Logfile of failure stored in: /home/yocto/yocto/build/tmp/work/machine-poky-linux/myimage/1.0-r0/temp/log.do_rootfs.731
ERROR: Task (/home/yocto/yocto/sources/meta-mylayer/recipes-images/myimage.bb:do_rootfs) failed with exit code '1'
However, when I replace the "https" by "http" in "baseurl" variable:
baseurl=http://storage.googleapis.com/my_repo/
Then the myimage recipe is built fine.
The host machine can download files from the https repository using wget:
$ wget https://storage.googleapis.com/my_repo/PACKAGEFEED-GPG-KEY-rocko
Previous commands works fine, so the problem is not related with the host machine, I think it must be something related with google certificates and yocto stuff.
I found some relevant information inside this file:
yocto/build/tmp/work/machine-poky-linux/myimage/1.0-r0/temp/dnf.librepo.log
The relevant part:
15:56:41 lr_download: Downloading started
15:56:41 check_transfer_statuses: Transfer finished: repodata/repomd.xml (Effective url: https://storage.googleapis.com/my_repo/repodata/repomd.xml)
15:56:41 check_finished_transfer_status: Fatal error - Curl code (77): Problem with the SSL CA cert (path? access rights?) for https://storage.googleapis.com/my_repo/repodata/repomd.xml [error setting certificate verify locations:
CAfile: /home/yocto/yocto/build/tmp/work/x86_64-linux/curl-native/7.54.1-r0/recipe-sysroot-native/etc/ssl/certs/ca-certificates.crt
CApath: none]
15:56:41 lr_yum_download_repomd: repomd.xml download was unsuccessful
Can some of you provide any useful advice to try to fix this?
Thank you in advance for your time! :-)
I finally fixed my issue removing completely my dnf bbappend recipe from my custom layer and adding this variable to my distro.conf file:
PACKAGE_FEED_URIS = "https://storage.googleapis.com/my_repo/"
After that, at the end of the build process the image contains a valid /etc/yum.d/oe-remote-repo file and all the necesary stuff to manage it. There is no need to copy "ca-certificates.crt" manually at all.
Also, it's important to execute this command after finishing the build of the image:
$ bitbake package-index
This command generates a "repodata" directory within the package feed needed by the target device once it uses the repo to update packages using dnf client.
I found a temporal hack to fix my issue:
$ cp /etc/ssl/certs/ca-certificates.crt /home/yocto/yocto/build/tmp/work/x86_64-linux/curl-native/7.54.1-r0/recipe-sysroot-native/etc/ssl/certs/
After that, I was finally able to build the image using the "https" repo.
Now I am in the process of fixing this issue in the right way. I'll come back with the final solution.

Resources