mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
fix: workdir path error
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
|||||||
*.dylib
|
*.dylib
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
backend
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -24,7 +24,7 @@ dist:
|
|||||||
|
|
||||||
# clean
|
# clean
|
||||||
clean:
|
clean:
|
||||||
@rm -rf bin && rm *.tar.gz
|
@rm -rf bin && rm -f *.tar.gz && rm -f backend
|
||||||
|
|
||||||
# protoc
|
# protoc
|
||||||
protoc:
|
protoc:
|
||||||
|
|||||||
@@ -135,10 +135,7 @@ type Config struct {
|
|||||||
func init() {
|
func init() {
|
||||||
// compatibility linux and windows
|
// compatibility linux and windows
|
||||||
var err error
|
var err error
|
||||||
if gopath := os.Getenv("GOPATH"); gopath != "" {
|
WorkDir = workDir()
|
||||||
WorkDir = filepath.Join(gopath, "src", "github.com",
|
|
||||||
"eiblog", "eiblog")
|
|
||||||
}
|
|
||||||
path := filepath.Join(WorkDir, "conf", "app.yml")
|
path := filepath.Join(WorkDir, "conf", "app.yml")
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(path)
|
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
|
for os in linux darwin windows; do
|
||||||
_target="$app-$_tag.$os-$_arch.tar.gz"
|
_target="$app-$_tag.$os-$_arch.tar.gz"
|
||||||
CGO_ENABLED=0 GOOS=$os GOARCH=$_arch \
|
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
|
if [ "$app" = "eiblog" ]; then
|
||||||
tar czf $_target conf website assets backend
|
tar czf $_target conf website assets backend
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ docker buildx create --use --name builder
|
|||||||
# build demo app
|
# build demo app
|
||||||
for file in pkg/core/*; do
|
for file in pkg/core/*; do
|
||||||
app="$(basename $file)";
|
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 image
|
||||||
docker buildx build --platform "$_platform" \
|
docker buildx build --platform "$_platform" \
|
||||||
-f "build/package/$app.Dockerfile" \
|
-f "build/package/$app.Dockerfile" \
|
||||||
|
|||||||
Reference in New Issue
Block a user