NSS
NSS

Reputation: 795

using docker alpine for go produces "unknown revision" error during go get

I’ve the following docker which works ok, I was able to run it and build it successfully!

FROM golang:1.13.6 AS build-env



ENV GO111MODULE=on
ENV GOOS=linux
ENV CGO_ENABLED=0




RUN mkdir -p /go/src/github.company.corp/deng/fst-cl
WORKDIR /go/src/github.company.corp/deng/fsr-clie


COPY ./ ./

# build the code
RUN go build -v -o ./fsr  ./src/cmd/main.go

Now I want to change the image to use lighter docker image such as go alpine

So I change the from and added alpine version and also added git ,however the build is failing for So go lib which doesn’t happen before the change, any idea what could be missing ?

FROM golang:1.13.6-alpine AS build-env



ENV GO111MODULE=on
ENV GOOS=linux
ENV CGO_ENABLED=0


## git is required to fetch go dependencies
RUN apk add --no-cache ca-certificates git
RUN apk add --no-cache gcc musl-dev


RUN mkdir -p /go/src/github.company.corp/deng/fst-cl
WORKDIR /go/src/github.company.corp/deng/fsr-clie


COPY ./ ./

# build the code
RUN go build -v -o ./fsr  ./src/cmd/main.go

The error is for specifid repo which resides on our company git repo, but I don’t understand why its happen on golang:1.13.6-alpine and works ok on golang:1.13.6 ????

Btw I try to use different version of go alpine without success…

This is the error:

get "github.company.corp/deng/logger-ut": found meta tag get.metaImport{Prefix:"github.company.corp/deng/logger-ut", VCS:"git", RepoRoot:"https://github.company.corp/deng/logger-ut.git"} at //github.company.corp/deng/logger-ut?go-get=1
go: github.company.corp/deng/[email protected]: reading github.company.corp/deng/logger-ut/go.mod at revision v1.0.0: unknown revision v1.0.0

Upvotes: 2

Views: 1873

Answers (1)

BentCoder
BentCoder

Reputation: 12740

If you want a lighter image and wish to use apline, you can use example below. Your final app image should be something like 7MB on scratch. Adjust it as it fits!

# STAGE 1: prepare
FROM golang:1.13.1-alpine3.10 as prepare

WORKDIR /source

COPY go.mod .
COPY go.sum .

RUN go mod download

# STAGE 2: build
FROM prepare AS build

COPY . .

RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o bin/app -v your/app.go

# STAGE 3: run
FROM scratch as run

COPY --from=build /source/bin/app /app

ENTRYPOINT ["/app"]

Upvotes: 1

Related Questions