-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 使用makefile编译 - 添加Dockerfile - 完善readme
- Loading branch information
Showing
7 changed files
with
197 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM golang:1.14-alpine as builder | ||
WORKDIR /usr/src/app | ||
ENV GOPROXY=https://goproxy.cn | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ | ||
apk add --no-cache upx ca-certificates tzdata | ||
COPY ./go.mod ./ | ||
COPY ./go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
|
||
RUN BUILDUSER=`whoami`@`hostname` ;\ | ||
BUILDDATE=`date +'%Y-%m-%d %H:%M:%S'` ;\ | ||
GITREVISION=`git rev-parse HEAD` ;\ | ||
GITVERSION=`cat VERSION` ;\ | ||
GITBRANCH=`git symbolic-ref --short -q HEAD` ;\ | ||
LDFLAGES=" -X 'github.com/prometheus/common/version.BuildUser=${BUILDUSER}' -X 'github.com/prometheus/common/version.BuildDate=${BUILDDATE}' -X 'github.com/prometheus/common/version.Revision=${GITREVISION}' -X 'github.com/prometheus/common/version.Version=${GITVERSION}' -X 'github.com/prometheus/common/version.Branch=${GITBRANCH}' ";\ | ||
echo ${LDFLAGES} ;\ | ||
CGO_ENABLED=0 go build -o server -ldflags "${LDFLAGES}" | ||
FROM busybox as runner | ||
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /usr/src/app/server /opt/app/stree-index | ||
ENTRYPOINT [ "/opt/app/stree-index" ] | ||
CMD [ "--config.file=/etc/stree-index.yml"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
GOCMD=go | ||
GOBUILD=${GOCMD} build | ||
GOCLEAN=${GOCMD} clean | ||
GOTEST=${GOCMD} test | ||
GOGET=${GOCMD} get | ||
|
||
DATE= `date +%FT%T%z` | ||
|
||
|
||
BINARY_NAME="`pwd |awk -F '/' '{print $NF}'`" | ||
BINARY_LINUX=${BINARY_NAME}_linux | ||
BUILDUSER=`whoami`@`hostname` | ||
BUILDDATE=`date +'%Y-%m-%d %H:%M:%S'` | ||
GITREVISION=`git rev-parse HEAD` | ||
GITVERSION=`cat VERSION` | ||
GITBRANCH=`git symbolic-ref --short -q HEAD` | ||
LDFLAGES=" -X 'github.com/prometheus/common/version.BuildUser=${BUILDUSER}' -X 'github.com/prometheus/common/version.BuildDate=${BUILDDATE}' -X 'github.com/prometheus/common/version.Revision=${GITREVISION}' -X 'github.com/prometheus/common/version.Version=${GITVERSION}' -X 'github.com/prometheus/common/version.Branch=${GITBRANCH}' " | ||
|
||
all: build | ||
build: | ||
${GOBUILD} -v -ldflags ${LDFLAGES} -o ${BINARY_NAME} | ||
test: | ||
${GOTEST} -v ./... | ||
clean: | ||
${GOCLEAN} | ||
rm -f ${BINARY_NAME} | ||
rm -f ${BINARY_LINUX} | ||
run: | ||
${GOBUILD} -o ${BINARY_NAME} -v ./... | ||
./${BINARY_NAME} | ||
|
||
|
||
build-linux: | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${GOBUILD} -ldflags ${LDFLAGES} -o ${BINARY_LINUX} -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Unit] | ||
Description="ning1875 opensource service tree" | ||
Documentation=https://github.com/ning1875/stree-index | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/stree-index -f /etc/stree-index/stree-index.yml | ||
Restart=on-failure | ||
RestartSecs=10s | ||
SuccessExitStatus=0 | ||
LimitNOFILE=3000000 | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier=stree-index | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|