From 1a45326c96717f9b5173fb7b3d8862c0d64bf3d7 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 20 Dec 2018 09:23:52 -0500 Subject: [PATCH 1/7] Converted to go modules so it can be easily built on armh --- Dockerfile | 17 ++++------------- Gopkg.lock | 17 ----------------- Gopkg.toml | 34 ---------------------------------- go.mod | 3 +++ go.sum | 3 +++ 5 files changed, 10 insertions(+), 64 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/Dockerfile b/Dockerfile index de388df..bfb96ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,13 @@ -FROM golang:1.11.2 as builder +FROM golang:1.11 as builder EXPOSE 8080 -ENV BUILD_DIR /go/src/github.com/halverneus/static-file-server -ENV MAIN github.com/halverneus/static-file-server/bin/serve -ENV DEP_VERSION v0.5.0 - -RUN curl -fsSL -o /usr/local/bin/dep \ - https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 && \ - chmod +x /usr/local/bin/dep - -RUN mkdir -p ${BUILD_DIR} -WORKDIR ${BUILD_DIR} +RUN mkdir -p /build +WORKDIR /build COPY . . -RUN dep ensure -vendor-only RUN go test -race -cover ./... -RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /serve ${MAIN} +RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /serve /build/bin/serve FROM scratch COPY --from=builder /serve / diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 05423c8..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,17 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = ["gopkg.in/yaml.v2"] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index ef7e857..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,34 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - name = "gopkg.in/yaml.v2" - version = "2.2.1" - -[prune] - go-tests = true - unused-packages = true diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..dc86d92 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/halverneus/static-file-server + +require gopkg.in/yaml.v2 v2.2.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..99fc7ca --- /dev/null +++ b/go.sum @@ -0,0 +1,3 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 7eb1918df2e40f2ba10c7e87a39b69fa3ee2b503 Mon Sep 17 00:00:00 2001 From: zbrown Date: Thu, 20 Dec 2018 09:59:09 -0500 Subject: [PATCH 2/7] go test -cover is not supported on armh --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bfb96ab..cd38d91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN mkdir -p /build WORKDIR /build COPY . . -RUN go test -race -cover ./... +RUN go test -cover ./... RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /serve /build/bin/serve FROM scratch From b1b00805c3d29b825e781574c26c35ac03d60473 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Thu, 20 Dec 2018 13:37:17 -0800 Subject: [PATCH 3/7] Updated dependencies and version number. Modified Dockerfile to place dependencies in a separate layer to speed development. --- Dockerfile | 11 ++++++++--- cli/version/version.go | 2 +- go.mod | 6 +++++- go.sum | 11 +++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd38d91..313be19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,14 @@ -FROM golang:1.11 as builder +FROM golang:1.11.3 as builder EXPOSE 8080 -RUN mkdir -p /build -WORKDIR /build +ENV BUILD_DIR /build + +RUN mkdir -p ${BUILD_DIR} +WORKDIR ${BUILD_DIR} + +COPY go.* ./ +RUN go mod download COPY . . RUN go test -cover ./... diff --git a/cli/version/version.go b/cli/version/version.go index 37be87d..d86d822 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -19,7 +19,7 @@ var ( MinorVersion = 5 // FixVersion of static-file-server. - FixVersion = 0 + FixVersion = 1 // Text for directly accessing the static-file-server version. Text = fmt.Sprintf( diff --git a/go.mod b/go.mod index dc86d92..3c30ef3 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,7 @@ module github.com/halverneus/static-file-server -require gopkg.in/yaml.v2 v2.2.1 +require ( + github.com/kr/pretty v0.1.0 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/go.sum b/go.sum index 99fc7ca..ad03c0f 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,10 @@ +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From ae0e44e9cc886d42792b48c50127bef6a500add2 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Thu, 20 Dec 2018 15:15:27 -0800 Subject: [PATCH 4/7] Creating multi-arch building container and consolidated version to Dockerfiles. --- .dockerignore | 1 + Dockerfile | 12 ++++++++++-- Dockerfile.all | 23 +++++++++++++++++++++++ cli/version/version.go | 21 +++++---------------- 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 Dockerfile.all diff --git a/.dockerignore b/.dockerignore index 81cbee1..303dd4e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ .git .gitignore Dockerfile +Dockerfile.all LICENSE README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 313be19..a1fb642 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.11.3 as builder EXPOSE 8080 - +ENV VERSION 1.5.1 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -12,9 +12,17 @@ RUN go mod download COPY . . RUN go test -cover ./... -RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /serve /build/bin/serve +RUN CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o /serve /build/bin/serve FROM scratch COPY --from=builder /serve / ENTRYPOINT ["/serve"] CMD [] + +# Metadata +LABEL life.apets.vendor="Halverneus" \ + life.apets.url="https://github.com/halverneus/static-file-server" \ + life.apets.name="Static File Server" \ + life.apets.description="A tiny static file server" \ + life.apets.version="v1.5.1" \ + life.apets.schema-version="1.0" diff --git a/Dockerfile.all b/Dockerfile.all new file mode 100644 index 0000000..1c870e3 --- /dev/null +++ b/Dockerfile.all @@ -0,0 +1,23 @@ +FROM golang:1.11.3 as builder + +EXPOSE 8080 +ENV VERSION 1.5.1 +ENV BUILD_DIR /build + +RUN mkdir -p ${BUILD_DIR} +WORKDIR ${BUILD_DIR} + +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-amd64/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm6/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm7/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm64/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve /build/bin/serve + +# Metadata +LABEL life.apets.vendor="Halverneus" \ + life.apets.url="https://github.com/halverneus/static-file-server" \ + life.apets.name="Static File Server" \ + life.apets.description="A tiny static file server" \ + life.apets.version="v1.5.1" \ + life.apets.schema-version="1.0" diff --git a/cli/version/version.go b/cli/version/version.go index d86d822..b1956c4 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -7,27 +7,16 @@ import ( // Run print operation. func Run() error { - fmt.Printf("%s\n%s\n", Text, GoVersionText) + fmt.Printf("%s\n%s\n", VersionText, GoVersionText) return nil } var ( - // MajorVersion of static-file-server. - MajorVersion = 1 + // version is the application version set during build. + version string - // MinorVersion of static-file-server. - MinorVersion = 5 - - // FixVersion of static-file-server. - FixVersion = 1 - - // Text for directly accessing the static-file-server version. - Text = fmt.Sprintf( - "v%d.%d.%d", - MajorVersion, - MinorVersion, - FixVersion, - ) + // VersionText for directly accessing the static-file-server version. + VersionText = fmt.Sprintf("v%s", version) // GoVersionText for directly accessing the version of the Go runtime // compiled with the static-file-server. From 3d1a102f386fff60657e166f6311f91ba3a9047c Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Fri, 21 Dec 2018 09:30:19 -0800 Subject: [PATCH 5/7] Added unit testing with the -race flag into the Dockerfile.all file. --- Dockerfile.all | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile.all b/Dockerfile.all index 1c870e3..e745b96 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -8,6 +8,7 @@ RUN mkdir -p ${BUILD_DIR} WORKDIR ${BUILD_DIR} COPY . . +RUN go test -race -cover ./... RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-amd64/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm6/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm7/serve /build/bin/serve From 0f8667889cf31796f02084b635e15286f2018711 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Fri, 21 Dec 2018 10:05:25 -0800 Subject: [PATCH 6/7] Added exe extension to Windows build and added additional architectures. --- Dockerfile.all | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile.all b/Dockerfile.all index e745b96..db34e1e 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -10,10 +10,12 @@ WORKDIR ${BUILD_DIR} COPY . . RUN go test -race -cover ./... RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-amd64/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-i386/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm6/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm7/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm64/serve /build/bin/serve -RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/darwin-amd64/serve /build/bin/serve +RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve.exe /build/bin/serve.exe # Metadata LABEL life.apets.vendor="Halverneus" \ From f76f7f8f766142435f9a23348c90c01ad3e1aa54 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Fri, 21 Dec 2018 10:07:37 -0800 Subject: [PATCH 7/7] Removed type extension from Dockerfile.all. --- Dockerfile.all | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.all b/Dockerfile.all index db34e1e..7adf054 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -15,7 +15,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -install RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm7/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm64/serve /build/bin/serve RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/darwin-amd64/serve /build/bin/serve -RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve.exe /build/bin/serve.exe +RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve.exe /build/bin/serve # Metadata LABEL life.apets.vendor="Halverneus" \