New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure without go code #954

Merged
merged 2 commits into from Aug 5, 2017

Conversation

Projects
None yet
4 participants
@ebati
Copy link
Contributor

ebati commented Aug 4, 2017

What does this do / why do we need it?

dep ensure -vendor-only can now work in folder without any go code. It is especially useful for builds inside docker utilizing cache layers.

Sample dockerfile:

FROM golang:1.8 AS builder

RUN apt-get update && apt-get install -y unzip --no-install-recommends && \
    apt-get autoremove -y && apt-get clean -y && \
    wget -O dep.zip https://github.com/golang/dep/releases/download/v0.3.0/dep-linux-amd64.zip && \
    echo '96c191251164b1404332793fb7d1e5d8de2641706b128bf8d65772363758f364  dep.zip' | sha256sum -c - && \
    unzip -d /usr/bin dep.zip && rm dep.zip

RUN mkdir -p /go/src/github.com/***
WORKDIR /go/src/github.com/***

COPY Gopkg.toml Gopkg.lock ./

RUN dep ensure -vendor-only
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o *** 

FROM alpine:latest
RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /go/src/github.com/***  .
ENTRYPOINT ["./***"]

What should your reviewer look out for in this PR?

  • runVendorOnly splitted from runDefault and called before ListPackages in ensure.Run
  • harness_test nocode_vendoronly added by duplicating hashnew_vendoronly and removing main.go

Which issue(s) does this PR fix?

fixes #796

@ebati ebati requested a review from ibrasho as a code owner Aug 4, 2017

@googlebot googlebot added the cla: yes label Aug 4, 2017

@sdboyer

sdboyer approved these changes Aug 5, 2017

Copy link
Member

sdboyer left a comment

yep! easy peasy. and good call, moving it up above the ListPackages() call.

@sdboyer sdboyer merged commit 4455eff into golang:master Aug 5, 2017

4 checks passed

cla/google All necessary CLAs are signed
codeclimate All good!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sdboyer

This comment has been minimized.

Copy link
Member

sdboyer commented Aug 5, 2017

yaaaay first PR! 🎉 🎊

@ebati ebati deleted the ebati:ensure-without-go-code branch Aug 5, 2017

@netrounds-joakim

This comment has been minimized.

Copy link

netrounds-joakim commented Dec 13, 2017

FROM golang:1.8 AS builder

# Install dep
RUN apt-get update && apt-get install -y unzip --no-install-recommends && \
    apt-get autoremove -y && apt-get clean -y && \
    wget -O dep.zip https://github.com/golang/dep/releases/download/v0.3.0/dep-linux-amd64.zip && \
    echo '96c191251164b1404332793fb7d1e5d8de2641706b128bf8d65772363758f364  dep.zip' | sha256sum -c - && \
    unzip -d /usr/bin dep.zip && rm dep.zip

RUN mkdir -p /go/src/github.com/***
WORKDIR /go/src/github.com/***

COPY Gopkg.toml Gopkg.lock ./

RUN dep ensure -vendor-only
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o *** 

FROM alpine:latest
RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /go/src/github.com/***  .
ENTRYPOINT ["./***"]

I used the exact Dockerfile as in this PR but I get this when building docker build -t ta2 .:

...
Archive:  dep.zip
  inflating: /usr/bin/dep
 ---> c682f0f63ba5
Removing intermediate container ec673c1eb0c4
Step 3/13 : RUN mkdir -p /go/src/github.com/***
 ---> Running in eac2e56b6b27
 ---> 647eac1a464b
Removing intermediate container eac2e56b6b27
Step 4/13 : WORKDIR /go/src/github.com/***
 ---> f9b96d48f844
Removing intermediate container ef017da7a94b
Step 5/13 : COPY Gopkg.toml Gopkg.lock ./
 ---> 85acdf026334
Removing intermediate container 1789b9f53060
Step 6/13 : RUN dep ensure -vendor-only
 ---> Running in 6ef8974e7302
all dirs lacked any go code
The command '/bin/sh -c dep ensure -vendor-only' returned a non-zero code: 1

I actually have a go file in this dir. main.go:

package main

import "fmt"

func main() {
	fmt.Println("hello world")
}

However my Gopkg.lock and Gopkg.toml are completely empty (maybe that is the issue?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment