Fixed Dockerfile build and runtime

pull/45/head
James Mills 2019-01-10 15:23:55 +10:00 committed by kun
parent 26d189ed77
commit 5053e78599
4 changed files with 48 additions and 27 deletions

View File

@ -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"]
ENTRYPOINT ["/goproxy"]
CMD []

15
Makefile Normal file
View File

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

View File

@ -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' {} +
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' {} +

View File

@ -1,4 +1,4 @@
//go:generate bash build/generate.sh
//go:generate ./build/generate.sh
package main