I am trying to build Go docker image Windows 10 with build 19044.2130 but giving below error
cmd/go: unsupported GOOS/GOARCH pair mingw64_nt-10.0-19044/amd64, in current GOOS list mingw64 is not listed as per list. Below is the dockerfile
ARG OS=linux
FROM golang as build_base
ARG OS
WORKDIR /tmp/auditcompile
COPY go.mod .
RUN go mod download
COPY . .
RUN GOOS=$OS go build -o out/audit .
Related
download kubernetes sdk source code
git clone https://github.com/kubernetes/client-go.git kubernet-client
and then
cd kubernet-client/examples/in-cluster-client-configuration/
and
type go run main.go , has error
➜ in-cluster-client-configuration git:(master) go run main.go
# net
/usr/local/Cellar/go/1.18.2/libexec/src/net/dial.go:351:11: d.DialContext undefined (type *Dialer has no field or method DialContext)
/usr/local/Cellar/go/1.18.2/libexec/src/net/dial.go:372:18: invalid character U+2013 '–' in identifier
/usr/local/Cellar/go/1.18.2/libexec/src/net/lookup_unix.go:70:14: d.DialContext undefined (type Dialer has no field or method DialContext)
➜ in-cluster-client-configuration git:(master) pwd
go_sourcecode/kubernet-client/examples/in-cluster-client-configuration
the go version
➜ in-cluster-client-configuration git:(master) go version
go version go1.18.2 darwin/amd64
what's wrong?
The step-by-step process has been written in the markdown file (https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration), why you didn't follow that ?
As this is an in-cluster example, this has to be run from inside of a kubernetes cluster. go run main.go will not work. To run this,
make a binary : go build -o ./app .
build an image : docker build -t YOUR_DOCKER_ID/controller:in-cluster .
push it on docker hub: docker push IMAGE
OR load this image into cluster. For kind cluster : kind load docker-image IMAGE
give permission to list pods : kubectl create clusterrolebinding default-view --clusterrole=view --serviceaccount=default:default
Then run kubectl run --rm -i demo --image=IMAGE
I am following the steps from "Building Go Services With Bazel" youtube and created a simple project with dependency that fails to build with an error:
ERROR: /builds/mvfwd/issue-bazel-go/cmd/BUILD.bazel:3:11: no such package '#com_github_pallinder_go_randomdata//': The repository '#com_github_pallinder_go_randomdata' could not be resolved and referenced by '//cmd:cmd_lib'
ERROR: Analysis of target '//cmd:cmd' failed; build aborted: Analysis failed
INFO: Elapsed time: 1.263s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 165 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 165 targets configured)
Whole log
Versions
$ bazel --version
bazel 4.1.0
$ go version
go version go1.17 linux/amd64
File structure
Project: https://gitlab.com/mvfwd/issue-bazel-go
cmd/
BUILD.bazel
hello.go
hello_test.go
BUILD
WORKSPACE
go.mod
go.sum
Steps
See .gitlab-ci.yml
go mod init gitlab.com/mvfwd/issue-bazel-go
creates go.mod
go mod tidy
creates go.sum
bazel run //:gazelle
creates cmd/BUILD.bazel
bazel build ...
fails with error
Thought it might be because of the dash in "go-randomdata", so added another non-dashed dependency (github.com/stretchr/testify/assert), got the same issue.
What am I doing wrong? Am I missing something?
UPD:
Solution was to use the following combination
$ bazel run //:gazelle
$ bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
$ bazel run //:gazelle
As described here. update-repos... part would update WORKSPACE with all the necessary dependencies.
Solution was to use the following combination
$ bazel run //:gazelle
$ bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
$ bazel run //:gazelle
As described here.
update-repos... part would update WORKSPACE file with all the necessary dependencies.
My Dockerfile
FROM golang:1.10.2-alpine3.7 AS build
RUN apk --no-cache add gcc g++ make ca-certificates
RUN apk add git
WORKDIR /go/src/github.com/meower
COPY Gopkg.lock Gopkg.toml ./
COPY util util
COPY event event
COPY db db
COPY search search
COPY schema schema
COPY meow-service meow-service
COPY query-service query-service
COPY pusher-service pusher-service
RUN go get -d -v ./...
RUN go install ./...
FROM alpine:3.7
WORKDIR /usr/bin
COPY --from=build /go/bin .
I added apk add git line.Without this line my docker-compose up produced
Step 13/17 : RUN go get -d -v ./...
---> Running in d917adba00cd
github.com/lib/pq (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/lib/pq: exec: "git": executable file not found in $PATH
github.com/nats-io/go-nats (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/nats-io/go-nats: exec: "git": executable file not found in $PATH
github.com/gorilla/mux (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/gorilla/mux: exec: "git": executable file not found in $PATH
github.com/kelseyhightower/envconfig (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/kelseyhightower/envconfig: exec: "git": executable file not found in $PATH
package github.com/retry: invalid github.com/ import path "github.com/retry"
github.com/segmentio/ksuid (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/segmentio/ksuid: exec: "git": executable file not found in $PATH
github.com/gorilla/websocket (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/gorilla/websocket: exec: "git": executable file not found in $PATH
github.com/olivere/elastic (download)
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/olivere/elastic: exec: "git": executable file not found in $PATH
With git line,other problems are still there
docker-compose up
Building pusher
Step 1/18 : FROM golang:1.10.2-alpine3.7 AS build
---> 44ccce322b34
Step 2/18 : RUN apk --no-cache add gcc g++ make ca-certificates
---> Using cache
---> 088fa5ba19a9
Step 3/18 : RUN apk add git
---> Running in 01022f57861b
WARNING: Ignoring APKINDEX.70c88391.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.5022a8a2.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
git (missing):
What does this mean?
go get internally calls the "reference" client-side tool of the particular VCS used to host the package to be fetched. In other words, go get by itself does not know how to interact with VCS servers.
So yes, in order to go get a package which is hosted by Git, you need the working Git installation providing a callable git binary.
As to your second problem, it does not appear to have anything related to Go, so I suggest you to do a bit of research and then ask a separate question tagged alpine if that fails.
I am installing fabric in a custom path $HOME//gopath/src/github.com/hyperledger/fabric using the make command but after installing all the 15 steps, I am getting the following error
Step 15/15 : LABEL org.hyperledger.fabric.version=1.0.2 org.hyperledger.fabric.base.version=0.3.2
---> Running in ed05a67810db
Removing intermediate container ed05a67810db
---> 99b4b0b28957
Successfully built 99b4b0b28957
Successfully tagged hyperledger/fabric-javaenv:latest
docker tag hyperledger/fabric-javaenv hyperledger/fabric-javaenv:x86_64-1.0.2
build/bin/peer
CGO_CFLAGS=" " GOBIN=/root/gopath/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.2 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.2 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/peer
go build github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11: invalid flag in #cgo LDFLAGS: -Wl,--no-as-needed
Makefile:227: recipe for target 'build/bin/peer' failed
make: *** [build/bin/peer] Error 1
Docker version 17.12.0-ce, build c97c6d6
docker-compose version 1.18.0, build 8dd22a9
go version go1.9.4 linux/amd64
OS : Ubuntu 16.04
I have set the following path also
$ mkdir $HOME/gopath
$ export GOPATH=$HOME/gopath
$ export GOROOT=$HOME/go
$ export PATH=$PATH:$GOROOT/bin
Jira Link: https://jira.hyperledger.org/browse/FAB-2218 which I have already done
It is a known issue in go 1.9.4:
https://github.com/golang/go/issues/23739
While go people are fixing it, you can manually whitelist the flags before starting make:
$ export CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed'
$ make
Alternatively you can just downgrade to go 1.9.3
as far as I know you don't need to build the fabric itself.
You just need to have sources in the gopath, as your chaincode will need this, when you are building your chaincode for the blockchain itself.
In addition you will probably also need to install the fabric-ca for your chaincode to build successfully, if you use the certificate-stuff.
This is sufficient to check if you installed fabric correctly:
cd $GOPATH/src/github.com/hyperledger/fabric
make unit-test
Keep going if this works.
I found this confusing at first as well ;)
I'd assume you switch to golang 1.9.4 or greater hence I belive this actually related to following issue, to solve it you need to update vendor dependencies:
govendor fetch github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
Next continue to build binaries and run tests.
I have a Golang web application that I am looking to run in Docker container. I am able to run it fine outside of the container, so I know it works, but when I build it from Dockerfile and run it, it gives me an error.
The Makefile looks like the following
GOCMD = go
GOBUILD = $(GOCMD) build
GOGET = $(GOCMD) get -v
GOCLEAN = $(GOCMD) clean
GOINSTALL = $(GOCMD) install
GOTEST = $(GOCMD) test
.PHONY: all
all: build
test:
$(GOTEST) -v -cover ./...
build:
$(GOGET); $(GOBUILD) -v -o engine
clean:
$(GOCLEAN) -n -i -x
rm -f $(GOPATH)/bin/engine
rm -rf bin/engine
install:
$(GOINSTALL)
And the Dockerfile looks like the following
FROM golang
ADD engine /go/bin/engine
EXPOSE 7777
ENTRYPOINT /go/bin/engine
I am building the image and running it using the following
docker build -t engine .
docker run -d --name engine -p 7777:7777 engine
and its giving me the following error
/go/bin/engine: 1: /go/bin/engine: Syntax error: "(" unexpected
When you build a binary, go build assumes that you are trying to build for your current computer, it chooses values for GOOS and GOARCH (described here) for you.
If you are not building on a linux machine then you will need to cross compile the binary for linux, as this is what the OS inside the docker container will be running. Explanation here
You need something like:
GOOS=linux
build:
$(GOGET); GOOS=$(GOOS) $(GOBUILD) -v -o engine