Skip to content

Commit 23ae012

Browse files
committed
add some files
1 parent 69fe178 commit 23ae012

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

build/Dockerfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# @build-example docker build . -f Dockerfile -t inherelab/httprr
3+
#
4+
5+
################################################################################
6+
### builder image
7+
################################################################################
8+
FROM golang:1.14-alpine as Builder
9+
10+
# Recompile the standard library without CGO
11+
#RUN CGO_ENABLED=0 go install -a std
12+
13+
ENV BUILd_DIR=/go/project \
14+
GO111MODULE=on \
15+
GOPROXY=https://goproxy.io
16+
17+
RUN mkdir -p $BUILd_DIR
18+
19+
COPY . $BUILd_DIR
20+
21+
# Compile the binary and statically link
22+
# -ldflags '-w -s'
23+
# -s: 去掉符号表
24+
# -w: 去掉调试信息,不能gdb调试了
25+
# RUN cd $BUILd_DIR && CGO_ENABLED=0 go build -ldflags '-d -w -s' -o /tmp/app
26+
RUN go version && cd $BUILd_DIR && go build -ldflags '-w -s' -o $BUILd_DIR/app
27+
# RUN cd $BUILd_DIR && go build -o /tmp/app
28+
29+
################################################################################
30+
### target image
31+
################################################################################
32+
FROM alpine:3.12
33+
LABEL maintainer="inhere <[email protected]>" version="1.0"
34+
35+
##
36+
# ---------- env settings ----------
37+
##
38+
ARG timezone
39+
# env: prod pre test dev. --build-arg app_env=dev
40+
ARG app_env=dev
41+
ARG app_port
42+
43+
ENV APP_ENV=${app_env:-"dev"} \
44+
APP_PORT=${app_port:-8080} \
45+
BUILd_DIR=/go/project \
46+
TIMEZONE=${timezone:-"Asia/Shanghai"}
47+
48+
EXPOSE ${APP_PORT}
49+
WORKDIR /data/www
50+
51+
COPY --from=Builder $BUILd_DIR/* ./
52+
#COPY --from=Builder $BUILd_DIR/static static
53+
#COPY --from=Builder $BUILd_DIR/resource resource
54+
#COPY --from=Builder $BUILd_DIR/app app
55+
56+
##
57+
# ---------- some config, clear work ----------
58+
##
59+
RUN set -ex; \
60+
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories; \
61+
# install some tools
62+
apk update && apk add --no-cache tzdata ca-certificates; \
63+
# clear caches
64+
rm -rf /var/cache/apk/*; \
65+
# - config timezone
66+
ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime; \
67+
echo "${TIMEZONE}" > /etc/timezone; \
68+
# - create logs, caches dir
69+
mkdir -p /data/logs /data/www; \
70+
# chown -R worker:worker /data/www; \
71+
chown -R www:www /data/www; \
72+
chmod a+x /data/www/app; \
73+
# && chown -R www:www /data/logs \
74+
echo -e "\033[42;37m Build Completed :).\033[0m\n"
75+
76+
CMD ./app

build/gcr.Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Start by building the application.
2+
#
3+
# @build-example docker build . -f gcr.Dockerfile -t gcr:test
4+
#
5+
FROM golang:1.14 as build
6+
7+
ENV APP_DIR $GOPATH/src/appointment
8+
RUN mkdir -p $APP_DIR
9+
#WORKDIR /go/src/app
10+
WORKDIR $APP_DIR
11+
12+
COPY . .
13+
14+
RUN go build -ldflags '-w -s' -o /go/bin/app
15+
16+
# Now copy it into our base image.
17+
#FROM gcr.io/distroless/base
18+
FROM myaniu/gcr.io-distroless-base
19+
COPY --from=build /go/bin/app /
20+
ENTRYPOINT ["/app"]

deploy/nginx-vhost.conf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
server {
2+
listen 80;
3+
server_name www.inhere.xyz inhere.xyz;
4+
root /data/service/httprr/static;
5+
index index.html index.htm;
6+
7+
error_log logs/inhere.xyz.error.log;
8+
access_log logs/inhere.xyz.access.log;
9+
10+
##### 第一个必选规则: 匹配首页
11+
location = / {
12+
proxy_pass http://127.0.0.1:8080;
13+
}
14+
15+
##### 第二个必选规则: 处理静态文件请求,这是nginx作为http服务器的强项
16+
# 有两种配置模式,目录匹配或后缀匹配,任选其一或搭配使用
17+
# location ^~ /static/ {
18+
# root /webroot/static/;
19+
# }
20+
21+
location ~* \.(js|css|map|png|jpg|jpeg|gif|ico|ttf|woff2|woff)$ {
22+
expires max;
23+
# root /webroot/static/;
24+
# log_not_found off;
25+
access_log off;
26+
}
27+
28+
##### 通用规则: 上面的都不匹配
29+
location / {
30+
# try_files $uri $uri/;
31+
32+
# proxy_redirect off;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header Host $host;
35+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
36+
proxy_http_version 1.1;
37+
# proxy_set_header Upgrade $http_upgrade;
38+
# proxy_set_header Connection "upgrade";
39+
proxy_set_header Connection "keep-alive";
40+
41+
# 没有找到文件就转发到 swoole server
42+
# 也可去掉 if. 全部转发到后端server
43+
if (!-e $request_filename){
44+
proxy_pass http://127.0.0.1:8080;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)