mirror of
https://github.com/eiblog/eiblog.git
synced 2025-12-19 17:32:24 +08:00
fix: workdir path error
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
*.dylib
|
||||
*.DS_Store
|
||||
*.tar.gz
|
||||
backend
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
2
Makefile
2
Makefile
@@ -24,7 +24,7 @@ dist:
|
||||
|
||||
# clean
|
||||
clean:
|
||||
@rm -rf bin && rm *.tar.gz
|
||||
@rm -rf bin && rm -f *.tar.gz && rm -f backend
|
||||
|
||||
# protoc
|
||||
protoc:
|
||||
|
||||
@@ -135,10 +135,7 @@ type Config struct {
|
||||
func init() {
|
||||
// compatibility linux and windows
|
||||
var err error
|
||||
if gopath := os.Getenv("GOPATH"); gopath != "" {
|
||||
WorkDir = filepath.Join(gopath, "src", "github.com",
|
||||
"eiblog", "eiblog")
|
||||
}
|
||||
WorkDir = workDir()
|
||||
path := filepath.Join(WorkDir, "conf", "app.yml")
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
|
||||
28
pkg/config/dev.go
Normal file
28
pkg/config/dev.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// +build !prod
|
||||
|
||||
// Package config provides ...
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// workDir recognize workspace dir
|
||||
var workDir = func() string {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for wd != "" {
|
||||
name := filepath.Join(wd, "conf")
|
||||
_, err := os.Stat(name)
|
||||
if err != nil {
|
||||
wd, _ = path.Split(wd)
|
||||
continue
|
||||
}
|
||||
return wd
|
||||
}
|
||||
return ""
|
||||
}
|
||||
7
pkg/config/pro.go
Normal file
7
pkg/config/pro.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// +build prod
|
||||
|
||||
// Package config provides ...
|
||||
package config
|
||||
|
||||
// workDir production use current dir
|
||||
var workDir = func() string { return "" }
|
||||
@@ -11,7 +11,7 @@ for file in pkg/core/*; do
|
||||
for os in linux darwin windows; do
|
||||
_target="$app-$_tag.$os-$_arch.tar.gz"
|
||||
CGO_ENABLED=0 GOOS=$os GOARCH=$_arch \
|
||||
go build -o backend "./cmd/$app"
|
||||
go build -tags prod -o backend "./cmd/$app"
|
||||
if [ "$app" = "eiblog" ]; then
|
||||
tar czf $_target conf website assets backend
|
||||
else
|
||||
|
||||
@@ -19,7 +19,7 @@ docker buildx create --use --name builder
|
||||
# build demo app
|
||||
for file in pkg/core/*; do
|
||||
app="$(basename $file)";
|
||||
CGO_ENABLED=0 go build -o bin/backend "./cmd/$app"
|
||||
CGO_ENABLED=0 go build -tags prod -o bin/backend "./cmd/$app"
|
||||
# docker image
|
||||
docker buildx build --platform "$_platform" \
|
||||
-f "build/package/$app.Dockerfile" \
|
||||
|
||||
Reference in New Issue
Block a user