From 5d43173673d084a40a64b91979b67383114dbaa6 Mon Sep 17 00:00:00 2001 From: mritd Date: Fri, 7 Aug 2020 11:51:26 +0800 Subject: [PATCH 1/2] chore(docker): add dockerfile add dockerfile Signed-off-by: mritd --- Dockerfile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..052e842 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM golang:1.14.7-alpine3.12 AS builder + +LABEL maintainer="mritd " + +# The following parameters are used to set compilation information(such as compilation time, +# commit id, etc.). Use "docker build --build-arg VERSION=1.1.1 ..." to set these parameters. +# These parameters can be set automatically through CI Server. +ARG VERSION="Unknown" +ARG COMMIT="Unknown" +ARG TIMESTAMP="Unknown" + +# GOPROXY is disabled by default, use: +# docker build --build-arg GOPROXY="https://goproxy.io" ... +# to enable GOPROXY. +ARG GOPROXY="" + +ENV VERSION ${VERSION} +ENV COMMIT ${COMMIT} +ENV TIMESTAMP ${TIMESTAMP} +ENV GOPROXY ${GOPROXY} + +# go mod is always enabled +ENV GO111MODULE on + +COPY . /go/src/github.com/tobyxdd/hysteria + +WORKDIR /go/src/github.com/tobyxdd/hysteria/cmd + +# TODO: Is it necessary to remove "-w -s" to add debugging information? +RUN set -ex \ + && go build -o /go/bin/hysteria -ldflags \ + "-w -s -X main.appVersion=${VERSION} \ + -X main.appCommit=${COMMIT} \ + -X main.appDate=${TIMESTAMP}" + +# multi-stage builds to create the final image +FROM alpine:3.12 AS dist + +LABEL maintainer="mritd " + +# bash is used for debugging, tzdata is used to add timezone information. +# Install ca-certificates to ensure no CA certificate errors. +# +# Do not try to add the "--no-cache" option when there are multiple "apk" +# commands, this will cause the build process to become very slow. +RUN set -ex \ + && apk upgrade \ + && apk add bash tzdata ca-certificates \ + && rm -rf /var/cache/apk/* + +COPY --from=builder /go/bin/hysteria /usr/local/bin/hysteria + +ENTRYPOINT ["hysteria"] \ No newline at end of file From 3614c80080a21417afcf61818cf4994d8f35ddd2 Mon Sep 17 00:00:00 2001 From: mritd Date: Fri, 7 Aug 2020 12:11:38 +0800 Subject: [PATCH 2/2] chore(docker): fix special date format causing build failed fix special date format causing build failed Signed-off-by: mritd --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 052e842..c023ea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,9 +29,9 @@ WORKDIR /go/src/github.com/tobyxdd/hysteria/cmd # TODO: Is it necessary to remove "-w -s" to add debugging information? RUN set -ex \ && go build -o /go/bin/hysteria -ldflags \ - "-w -s -X main.appVersion=${VERSION} \ - -X main.appCommit=${COMMIT} \ - -X main.appDate=${TIMESTAMP}" + "-w -s -X 'main.appVersion=${VERSION}' \ + -X 'main.appCommit=${COMMIT}' \ + -X 'main.appDate=${TIMESTAMP}'" # multi-stage builds to create the final image FROM alpine:3.12 AS dist