try to build minimal image
This commit is contained in:
parent
6eefd24fae
commit
00d4b5047b
12
aux/Dockerfile-release
Normal file
12
aux/Dockerfile-release
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
FROM golang as builder
|
||||||
|
WORKDIR /app/dtm
|
||||||
|
RUN go env -w GO111MODULE=on
|
||||||
|
RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
|
||||||
|
EXPOSE 8080
|
||||||
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" app/main.go
|
||||||
|
|
||||||
|
FROM scratch as runner
|
||||||
|
COPY --from=builder /app/dtm/main /app/dtm/main
|
||||||
|
ENV IS_DOCKER=1
|
||||||
|
CMD ["/app/dtm/main", "dtmsvr"]
|
||||||
@ -1,15 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
services:
|
|
||||||
mysql:
|
|
||||||
image: 'mysql:5.7'
|
|
||||||
environment:
|
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: 1
|
|
||||||
TZ: Asia/shanghai
|
|
||||||
command:
|
|
||||||
[
|
|
||||||
'--character-set-server=utf8mb4',
|
|
||||||
'--collation-server=utf8mb4_unicode_ci',
|
|
||||||
'--default-time-zone=+8:00',
|
|
||||||
]
|
|
||||||
ports:
|
|
||||||
- '3306:3306'
|
|
||||||
@ -3,7 +3,7 @@ services:
|
|||||||
api:
|
api:
|
||||||
build: .
|
build: .
|
||||||
environment:
|
environment:
|
||||||
IS_DOCKER_COMPOSE: '1'
|
IS_DOCKER: '1'
|
||||||
ports:
|
ports:
|
||||||
- '8080:8080'
|
- '8080:8080'
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@ -174,7 +174,7 @@ func GetFuncName() string {
|
|||||||
|
|
||||||
// MayReplaceLocalhost when run in docker compose, change localhost to host.docker.internal for accessing host network
|
// MayReplaceLocalhost when run in docker compose, change localhost to host.docker.internal for accessing host network
|
||||||
func MayReplaceLocalhost(host string) string {
|
func MayReplaceLocalhost(host string) string {
|
||||||
if os.Getenv("IS_DOCKER_COMPOSE") != "" {
|
if os.Getenv("IS_DOCKER") != "" {
|
||||||
return strings.Replace(host, "localhost", "host.docker.internal", 1)
|
return strings.Replace(host, "localhost", "host.docker.internal", 1)
|
||||||
}
|
}
|
||||||
return host
|
return host
|
||||||
|
|||||||
@ -70,10 +70,10 @@ func TestSome(t *testing.T) {
|
|||||||
func1 := GetFuncName()
|
func1 := GetFuncName()
|
||||||
assert.Equal(t, true, strings.HasSuffix(func1, "TestSome"))
|
assert.Equal(t, true, strings.HasSuffix(func1, "TestSome"))
|
||||||
|
|
||||||
os.Setenv("IS_DOCKER_COMPOSE", "1")
|
os.Setenv("IS_DOCKER", "1")
|
||||||
s := MayReplaceLocalhost("http://localhost")
|
s := MayReplaceLocalhost("http://localhost")
|
||||||
assert.Equal(t, "http://host.docker.internal", s)
|
assert.Equal(t, "http://host.docker.internal", s)
|
||||||
os.Setenv("IS_DOCKER_COMPOSE", "")
|
os.Setenv("IS_DOCKER", "")
|
||||||
s2 := MayReplaceLocalhost("http://localhost")
|
s2 := MayReplaceLocalhost("http://localhost")
|
||||||
assert.Equal(t, "http://localhost", s2)
|
assert.Equal(t, "http://localhost", s2)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user