From 5053e785996327b50fed7c9b199b91e959b163b9 Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Thu, 10 Jan 2019 15:23:55 +1000 Subject: [PATCH] Fixed Dockerfile build and runtime --- Dockerfile | 28 +++++++++++++++++----------- Makefile | 15 +++++++++++++++ build/generate.sh | 30 +++++++++++++++--------------- main.go | 2 +- 4 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile index 9f6db24..5747755 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,23 @@ -FROM golang:1.11 AS build +FROM golang:alpine AS build -COPY ./ /goproxy +RUN apk add --no-cache -U make -RUN cd /goproxy &&\ - export GO111MODULE=on &&\ - go generate &&\ - go mod tidy &&\ - go build +COPY . /src/goproxy +WORKDIR /src/goproxy -FROM alpine:3.8 -RUN apk add --no-cache git mercurial subversion bzr fossil -COPY --from=build /goproxy/goproxy /bin/goproxy +ENV CGO_ENABLED=0 + +RUN make + +FROM alpine:latest + +RUN apk add --no-cache -U git mercurial subversion bzr fossil + +COPY --from=build /src/goproxy/goproxy /goproxy + +VOLUME /go EXPOSE 8081 -CMD ["goproxy"] \ No newline at end of file +ENTRYPOINT ["/goproxy"] +CMD [] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d93641f --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: build generate image clean + +all: build + +build: generate + @go build -tags "netgo static_build" -installsuffix netgo -ldflags -w . + +generate: + @go generate + +image: + @docker build -t goproxy/goproxy . + +clean: + @git clean -f -d -X diff --git a/build/generate.sh b/build/generate.sh index 34fb496..7763a5f 100755 --- a/build/generate.sh +++ b/build/generate.sh @@ -1,22 +1,22 @@ -#!/usr/bin/env bash +#!/bin/sh -PKG=${PWD}/internal -GOROOT=`go env GOROOT` +PKG="${PWD}/internal" +GOROOT="$(go env GOROOT)" -mkdir -p ${PKG} -cp -r ${GOROOT}/src/cmd/go/internal/* ${PKG} +mkdir -p "${PKG}" +cp -r "${GOROOT}/src/cmd/go/internal/"* "${PKG}" -cp -r ${GOROOT}/src/cmd/internal/browser ${PKG} -cp -r ${GOROOT}/src/cmd/internal/buildid ${PKG} -cp -r ${GOROOT}/src/cmd/internal/objabi ${PKG} -cp -r ${GOROOT}/src/cmd/internal/test2json ${PKG} +cp -r "${GOROOT}/src/cmd/internal/browser" "${PKG}" +cp -r "${GOROOT}/src/cmd/internal/buildid" "${PKG}" +cp -r "${GOROOT}/src/cmd/internal/objabi" "${PKG}" +cp -r "${GOROOT}/src/cmd/internal/test2json" "${PKG}" -cp -r ${GOROOT}/src/internal/singleflight ${PKG} -cp -r ${GOROOT}/src/internal/testenv ${PKG} +cp -r "${GOROOT}/src/internal/singleflight" "${PKG}" +cp -r "${GOROOT}/src/internal/testenv" "${PKG}" -find ${PKG} -type f -name '*.go' -exec sed -i 's/cmd\/go\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} + -find ${PKG} -type f -name '*.go' -exec sed -i 's/cmd\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} + -find ${PKG} -type f -name '*.go' -exec sed -i 's/internal\/singleflight/github.com\/goproxyio\/goproxy\/internal\/singleflight/g' {} + -find ${PKG} -type f -name '*.go' -exec sed -i 's/internal\/testenv/github.com\/goproxyio\/goproxy\/internal\/testenv/g' {} + \ No newline at end of file +find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/cmd\/go\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} + +find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/cmd\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} + +find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/singleflight/github.com\/goproxyio\/goproxy\/internal\/singleflight/g' {} + +find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/testenv/github.com\/goproxyio\/goproxy\/internal\/testenv/g' {} + diff --git a/main.go b/main.go index dd885ba..7e0f4b6 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -//go:generate bash build/generate.sh +//go:generate ./build/generate.sh package main