forked from inhere/go-web-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (58 loc) · 2.03 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# @build-example build . -f Dockerfile -t algoo:test
#
################################################################################
### builder image
################################################################################
FROM golang:1.12-alpine as Builder
# Recompile the standard library without CGO
#RUN CGO_ENABLED=0 go install -a std
ENV APP_DIR $GOPATH/src/go-web-skeleton
RUN mkdir -p $APP_DIR
ADD . $APP_DIR
# Compile the binary and statically link
# -ldflags '-w -s'
# -s: 去掉符号表
# -w: 去掉调试信息,不能gdb调试了
# RUN cd $APP_DIR && CGO_ENABLED=0 go build -ldflags '-d -w -s' -o /tmp/app-server
RUN go version && cd $APP_DIR && go build -ldflags '-w -s' -o /tmp/app-server
# RUN cd $APP_DIR && go build -o /tmp/app-server
################################################################################
### target image
################################################################################
FROM alpine:3.9
LABEL maintainer="inhere <[email protected]>" version="1.0"
##
# ---------- env settings ----------
##
ARG timezone
# prod audit test dev. --build-arg app_env=dev
ARG app_env=dev
ARG app_port
ENV APP_ENV=${app_env:-"dev"} \
APP_PORT=${app_port:-59440} \
TIMEZONE=${timezone:-"Asia/Shanghai"}
##
# ---------- some config, clear work ----------
##
RUN set -ex \
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories \
# install some tools
&& apk update && apk add --no-cache tzdata ca-certificates \
# clear caches
&& rm -rf /var/cache/apk/* \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# - create logs, caches dir
&& mkdir -p /data/logs /var/www \
# && chown -R www:www /data/logs \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
EXPOSE ${APP_PORT}
WORKDIR /var/www
COPY --from=Builder /tmp/app-server app-server
COPY config config
COPY static static
COPY resource resource
# ENTRYPOINT ["./app-server"]
CMD ["./app-server"]