plan to use docker
This commit is contained in:
parent
edd2470102
commit
14ac7ce698
@ -3,4 +3,5 @@ WORKDIR /app/dtm
|
|||||||
RUN go env -w GO111MODULE=on
|
RUN go env -w GO111MODULE=on
|
||||||
RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
|
RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
ENV IS_DOCKER 1
|
||||||
CMD [ "/bin/bash", "-c", "go build app/main.go && /app/dtm/main" ]
|
CMD [ "/bin/bash", "-c", "go build app/main.go && /app/dtm/main" ]
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -87,6 +88,9 @@ func (op *tracePlugin) Initialize(db *gorm.DB) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDsn(conf map[string]string) string {
|
func GetDsn(conf map[string]string) string {
|
||||||
|
if IsDocker() {
|
||||||
|
conf["host"] = strings.Replace(conf["host"], "localhost", "host.docker.internal", 1)
|
||||||
|
}
|
||||||
return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", conf["user"], conf["password"], conf["host"], conf["port"], conf["database"])
|
return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", conf["user"], conf["password"], conf["host"], conf["port"], conf["database"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -188,6 +188,9 @@ func init() {
|
|||||||
// RestyClient.SetRetryCount(2)
|
// RestyClient.SetRetryCount(2)
|
||||||
// RestyClient.SetRetryWaitTime(1 * time.Second)
|
// RestyClient.SetRetryWaitTime(1 * time.Second)
|
||||||
RestyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
|
RestyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
|
||||||
|
if IsDocker() {
|
||||||
|
r.URL = strings.Replace(r.URL, "localhost", "host.docker.internal", 1)
|
||||||
|
}
|
||||||
logrus.Printf("requesting: %s %s %v %v", r.Method, r.URL, r.Body, r.QueryParam)
|
logrus.Printf("requesting: %s %s %v %v", r.Method, r.URL, r.Body, r.QueryParam)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -269,3 +272,7 @@ func GetFuncName() string {
|
|||||||
pc, _, _, _ := runtime.Caller(1)
|
pc, _, _, _ := runtime.Caller(1)
|
||||||
return runtime.FuncForPC(pc).Name()
|
return runtime.FuncForPC(pc).Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsDocker() bool {
|
||||||
|
return os.Getenv("IS_DOCKER") != ""
|
||||||
|
}
|
||||||
|
|||||||
29
compose.yml
Normal file
29
compose.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
version: '3.3'
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: 'mysql:5.7'
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: my-secret-pw
|
||||||
|
TZ: Asia/shanghai
|
||||||
|
command:
|
||||||
|
[
|
||||||
|
'--character-set-server=utf8mb4',
|
||||||
|
'--collation-server=utf8mb4_unicode_ci',
|
||||||
|
'--default-time-zone=+8:00',
|
||||||
|
]
|
||||||
|
ports:
|
||||||
|
- '3306:3306'
|
||||||
|
services:
|
||||||
|
dtm:
|
||||||
|
image: 'mysql:5.7'
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: my-secret-pw
|
||||||
|
TZ: Asia/shanghai
|
||||||
|
command:
|
||||||
|
[
|
||||||
|
'--character-set-server=utf8mb4',
|
||||||
|
'--collation-server=utf8mb4_unicode_ci',
|
||||||
|
'--default-time-zone=+8:00',
|
||||||
|
]
|
||||||
|
ports:
|
||||||
|
- '3306:3306'
|
||||||
Loading…
x
Reference in New Issue
Block a user