I am trying to run golang application which use goracle library with such Dockerfile:
FROM golang:1.12
RUN go get github.com/gorilla/mux && \
go get github.com/gorilla/handlers && \
go get github.com/lib/pq && \
go get github.com/joho/godotenv && \
go get github.com/jinzhu/gorm && \
go get gopkg.in/goracle.v2
ADD ./ /go/src/application
WORKDIR /go/src/application
RUN go build -o /bin application
ENV PORT=8000
CMD ["/bin"]
Unfortunatly it raise error when I try to create image:
package gopkg.in/goracle.v2: unrecognized import path "gopkg.in/goracle.v2" (https fetch: Get https://gopkg.in/goracle.v2?go-get=1: proxyconnect tcp: tls: first record does not look like a TLS handshake)
The command '/bin/sh -c go get github.com/gorilla/mux && go get github.com/gorilla/handlers && go get github.com/lib/pq && go get github.com/joho/godotenv && go get github.com/jinzhu/gorm && go get gopkg.in/goracle.v2' returned a non-zero code: 1
Why I can't install goracle library in Docker? How to fix this problem?
In my case the CentOS server where was located Docker has proxy. For thats why I couldn't download the gopkg.in/goracle.v2 package.
SOLUTION:
1) Create vender folder inside your project.
2) Remove source code of gopkg.in/goracle.v2 package which you has in go/src folder to vender folder.
3) Run you Dockerfile.
In my case this instruction removed problem with importing of gopkg.in/goracle.v2
package.
I hope this post will helpful for somebody!
Related
We are using
golangci-lint version 1.40.1 together with
golang version 1.16.4
in our project for linting our Golang code.
Until now, what we did is running this bash script (from the root
directory of our repository):
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go mod tidy
fi
golangci-lint run --build-tags="unit contract container"
With some recent updates of Golang and golangci-lint, we suddenly face this error message:
ERRO Running error: context loading failed: no go files to analyze
There is a lengthy post on GitHub regarding this issue but the only useful suggestion there is to turn off the GO111MODULE env variable. When I run the linter with GO111MODULE turned off like
GO111MODULE=off golangci-lint run --build-tags="unit contract container"
the upper error message disappears but instead I am getting lots of false linting errors like:
api/router.go:152:5: undeclared name: `PermissionUpdatePackage` (typecheck)
PermissionUpdatePackage,
^
My go environment looks like this:
GO111MODULE=on
GOPATH=/Users/USER/workspace/go
GOROOT=/usr/local/opt/go/libexec
GOPRIVATE=*.CUSTOMER.com
GOSS_PATH=/usr/local/bin/goss
I tried to install the linter via go get... as well as go install ... and finally brew install golangci-lint which seems to be the recommended way following this documentation.
Running a go get ./... in the root of the project eventually solved the issues. In between we ran the following commands that probably cleared some (module?) caches that might have caused trouble as well:
golangci-lint cache clean && go clean -modcache -cache -i
golangci-lint run -v --timeout=5s
The error message
ERRO Running error: context loading failed: failed to load packages: timed out to load packages: context deadline exceeded
in the latter command pointed us to this GitHub post that made me try out go get ./...
For installing the linter (with a specified version), we ended up with this script:
linter_version='1.40.1'
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
# we cannot install linter in the project directory, otherwise we get dependency errors
# hence, temporarily jump into the /tmp directory
pushd /tmp > /dev/null
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint#v"${linter_version}" 2>&1
popd >/dev/null
fi
I have been following a gRPC tutorial, this works perfectly fine. The problems start when I try to add https://github.com/grpc-ecosystem/grpc-gateway to my project. I use the commands they give you:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
and I import the package in my proto:
import "google/api/annotations.proto";
I am getting an error on the line above saying "file not found".
When I copy the files inside my project, they are found but when I run the command
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:. \
path/to/your_service.proto
it will complain that it cannot find the files.
Could someone please tell me the correct way on how to be able to get this grpc-gateway working properly?
I am currently on windows with GoLand as IDE.
If I read this issue correct it's the same that you have. They say you have to put these files in your repository https://github.com/grpc-ecosystem/grpc-gateway/issues/1065#issuecomment-544241612
Recently I get an issue on go get when processing build on Jenkins: the Go get command will be randomly failed when trying to build images.
For example, here are several lines in my Dockerfile:
go get -u golang.org/x/lint/golint && \
go get github.com/glaslos/ssdeep && \
go get github.com/mitchellh/mapstructure && \
go get github.com/denisenkom/go-mssqldb && \
go get -u github.com/go-sql-driver/mysql && \
go get github.com/hashicorp/consul/api && \
go get -u github.com/gin-gonic/gin && \
go get -u github.com/gocql/gocql && \
go get github.com/satori/go.uuid && \
go get github.com/golang/protobuf/protoc-gen-go && \
And I will get a fail like:
go get -u github.com/go-sql-driver/mysql cd .; git clone
https://github.com/go-sql-driver/mysql
/root/go/src/github.com/go-sql-driver/mysql Cloning into
'/root/go/src/github.com/go-sql-driver/mysql'... fatal: unable to
access 'https://github.com/go-sql-driver/mysql/': Could not resolve
host: github.com package github.com/go-sql-driver/mysql: exit status
128
The failed go packages are randomly distributed.
Does anyone have any idea to avoid this issue? Like tools that get go package without go get, etc.
Many thanks!
TLDR; Just commit and push your vendor folder.
It may be caused by a network issue. What I suggest is that you use a vendoring solution (like dep or modules) and have all your dependencies in a vendor folder, that way you make sure that you are able to replicate builds. Even Kubernetes (https://github.com/kubernetes/kubernetes) has its dependencies in a vendor folder in their repository.
I have an AWS CodeBuild job, defined with the following buildspec file (apologies if indentation isn't reproduced correctly):
version: 0.2
env:
variables:
PACKAGE: "github.com/user/package"
phases:
install:
commands:
- mkdir -p ${GOPATH}/src/${PACKAGE}
- cp -a ${CODEBUILD_SRC_DIR}/. ${GOPATH}/src/${PACKAGE}
- cd ${GOPATH}/src/${PACKAGE} && go get ./...
build:
commands:
- cd ${GOPATH}/src/${PACKAGE} && go build -o ${CODEBUILD_SRC_DIR}/application
post_build:
commands:
- aws cloudformation package --template-file template.yml --output-template-file serverless.yml --s3-bucket some-bucket
artifacts:
files:
- serverless.yml
This fails in the install phase.
The go application I'm trying to build has several sub-packages and external dependencies. When running "go get ./..." I'm getting
cannot find package github.com/user/package/sub-package in any of:
/usr/local/go/src/github.com/user/package/sub-package(from $GOROOT) /go/src/github.com/user/package/sub-package(from $GOPATH) /codebuild/output/src708017258/src/github.com/user/package/sub-package
When "debugging" (by putting in some echos and listing the contents of the newley created folders) it appears that everything is in the right place and everything should just work.
I want to build a docker image with a fixed version of micro and go dependencies. I plan to do it with dep:
git checkout git#github.com:micro/micro.git
dep ensure
git add Gopkg.toml
git add Gopkg.lock
# Build micro
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -i -o micro ./main.go
# Build docker image
...
So, my question is does it the best solution to build consistent micro docker image?
An example of a Dockerfile can be:
FROM golang:1.9-alpine3.6 as builder
# Install package manager
RUN apk add --no-cache --virtual .go-dependencies git curl \
&& curl https://glide.sh/get | sh
# Copy files from context
WORKDIR /go/src/github.com/foo/bar
COPY . .
# Install project dependencies, test and build
RUN glide install \
&& go test ./... \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -i -o ./entry ./main.go ./plugins.go
# Build final image with binary
FROM alpine:3.6
RUN apk add --update ca-certificates && \
rm -rf /var/cache/apk/* /tmp/*
WORKDIR /
COPY --from=builder /go/src/github.com/foo/bar/entry .
ENTRYPOINT [ "/entry" ]
And the glide.yaml would look like this:
package: .
import:
- package: github.com/micro/go-micro
version: ^0.3.0
subpackages:
- client
- server
- package: github.com/micro/go-plugins
version: ^0.6.1
subpackages:
- wrapper/trace/opentracing
- broker/nats
- transport/nats
- package: github.com/opentracing/opentracing-go
version: ^1
- package: github.com/openzipkin/zipkin-go-opentracing
version: ^0.3
testImport:
- package: github.com/golang/mock
subpackages:
- gomock
- package: github.com/smartystreets/goconvey
subpackages:
- convey
In my case, dep looks great and fast enough, moreover, it's official dependency manager in go so I think it's a right choice.