Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Ensure without go code #954

Merged
merged 2 commits into from
Aug 5, 2017
Merged

Conversation

ebati
Copy link
Contributor

@ebati 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

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

sdboyer commented Aug 5, 2017

yaaaay first PR! 🎉 🎊

@ebati ebati deleted the ensure-without-go-code branch August 5, 2017 13:15
@netrounds-joakim
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dep ensure without any go code in directories
4 participants