Skip to content

Commit 70cd2a1

Browse files
committed
dockerize studygolang
1 parent 98c2efd commit 70cd2a1

File tree

5 files changed

+151
-15
lines changed

5 files changed

+151
-15
lines changed

.dockerignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.git
2+
bundles
3+
pkg
4+
bin
5+
log
6+
pid
7+
sitemap
8+
assets
9+
*.swp
10+
*.o
11+
*.a
12+
*.so

Dockerfile.web

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file decribes the standard way to build stadygolang, using docker
2+
#
3+
# # Usage
4+
#
5+
# # # download the src and enter the dir first
6+
# docker build -f Dockerfile.web -t studygolang .
7+
#
8+
# docker run --name mysqlDB -e MYSQL_ROOT_PASSWORD=123456 -d mysql
9+
# docker run -d --name studygolang-web -v `pwd`:/studyglang -p 8090:8088 --link mysqlDB:db.localhost studygolang ./docker-entrypoint.sh
10+
#
11+
# # inside the container
12+
# bin/studygolang
13+
#
14+
# # just compile
15+
# docker run --rm -v `pwd`:/studyglang ./install.sh
16+
# # and in production environment just put this binary file in jockerxu/ubuntu-golang and run it
17+
18+
19+
FROM jockerxu/ubuntu-golang
20+
MAINTAINER jockerxu <[email protected]>
21+
22+
# download dep
23+
RUN go get github.com/polaris1119/gvt
24+
WORKDIR /studygolang
25+
COPY . /studygolang
26+
RUN cd src/ && gvt restore
27+
RUN mkdir -p /vendor/src/ && mv src/vendor/* /vendor/src/
28+
ENV GOPATH $GOPATH:/vendor
29+
30+
# run
31+
CMD ["docker-entrypoint.sh"]

docker-entrypoint.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# ***************************************************************************
4+
# *
5+
# * @author:jockerxu
6+
# * @date:2017-11-15 13:28
7+
# * @version 1.0
8+
# * @description: Shell script
9+
# * @Copyright (c) all right reserved
10+
#*
11+
#**************************************************************************/
12+
13+
14+
# TODO run the install cmd
15+
set -x
16+
CURDIR=`pwd`
17+
OLDGOPATH="$GOPATH"
18+
export GOPATH="$GOPATH:$CURDIR"
19+
20+
if [ ! -d log ]; then
21+
mkdir log
22+
fi
23+
24+
gofmt -w -s src
25+
26+
BUILD="`git symbolic-ref HEAD | cut -b 12-`-`git rev-parse HEAD`"
27+
28+
go install -ldflags "-X global.Build="$BUILD server/studygolang
29+
go install server/indexer
30+
go install server/crawler
31+
32+
export GOPATH="$OLDGOPATH"
33+
# TODO run binary
34+
./start.sh
35+
sleep infinity
36+
set +x

src/http/http.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,21 @@ const (
181181

182182
// 是否访问这些页面
183183
var filterPathes = map[string]struct{}{
184-
"/account/login": struct{}{},
185-
"/account/register": struct{}{},
186-
"/account/forgetpwd": struct{}{},
187-
"/account/resetpwd": struct{}{},
188-
"/topics/new": struct{}{},
189-
"/topics/modify": struct{}{},
190-
"/resources/new": struct{}{},
191-
"/resources/modify": struct{}{},
192-
"/articles/new": struct{}{},
193-
"/articles/modify": struct{}{},
194-
"/project/new": struct{}{},
195-
"/project/modify": struct{}{},
196-
"/book/new": struct{}{},
197-
"/wiki/new": struct{}{},
198-
"/wiki/modify": struct{}{},
184+
"/account/login": {},
185+
"/account/register": {},
186+
"/account/forgetpwd": {},
187+
"/account/resetpwd": {},
188+
"/topics/new": {},
189+
"/topics/modify": {},
190+
"/resources/new": {},
191+
"/resources/modify": {},
192+
"/articles/new": {},
193+
"/articles/modify": {},
194+
"/project/new": {},
195+
"/project/modify": {},
196+
"/book/new": {},
197+
"/wiki/new": {},
198+
"/wiki/modify": {},
199199
}
200200

201201
// Render html 输出

start-docker.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# ***************************************************************************
4+
# *
5+
# * @author:jockerxu
6+
# * @date:2017-11-14 22:20
7+
# * @version 1.0
8+
# * @description: Shell script
9+
#*
10+
#**************************************************************************/
11+
12+
#---------tool function---------------
13+
echo_COLOR_GREEN=$( echo -e "\e[32;49m")
14+
echo_COLOR_RESET=$( echo -e "\e[0m")
15+
function echo-info()
16+
{
17+
echo -e "${echo_COLOR_GREEN}[$(date "+%F %T")]\t$*${echo_COLOR_RESET}";
18+
}
19+
#---------end tool function-----------
20+
if [[ $USER != "root" ]]; then
21+
echo "you must be root!!!!!"
22+
exit 1
23+
fi
24+
25+
if [[ $1 == "" ]]; then
26+
echo "Usage start-docker.sh [local | remote]"
27+
exit 1
28+
fi
29+
30+
STUDYGOLANG_IMG=
31+
32+
if [[ $1 == "local" ]]; then
33+
STUDYGOLANG_IMG=studygolang
34+
docker images ${STUDYGOLANG_IMG} | grep -q ${STUDYGOLANG_IMG} || {
35+
docker build -f Dockerfile.web -t $STUDYGOLANG_IMG .
36+
}
37+
elif [[ $1 == "remote" ]]; then
38+
STUDYGOLANG_IMG="jockerxu/studygolang"
39+
else
40+
exit 1
41+
fi
42+
43+
docker ps -a | grep -q mysqlDB || {
44+
docker run --name mysqlDB -e MYSQL_ROOT_PASSWORD=123456 -d mysql
45+
}
46+
docker ps -a | grep -q studygolang-web && {
47+
docker rm -f studygolang-web
48+
}
49+
docker run -d --name studygolang-web -v `pwd`:/studygolang -p 8090:8088 --link mysqlDB:db.localhost $STUDYGOLANG_IMG ./docker-entrypoint.sh
50+
51+
if [[ $? == 0 ]]; then
52+
echo-info "studygolang-web start, waiting several seconds to install..."
53+
sleep 5
54+
echo-info "open browser: http://localhost:8090"
55+
echo-info "mysql-host is: db.localhost "
56+
echo-info "mysql-password is: 123456"
57+
fi

0 commit comments

Comments
 (0)