Skip to content

Commit

Permalink
feat: docker download dir move to /app/Download (GopeedLab#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Mar 12, 2024
1 parent e39d50f commit c81ca7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ jobs:
VERSION: ${{ needs.get-release.outputs.version }}
with:
push: ${{ github.event.inputs.test == 'true' && 'false' || 'true' }}
build-args: VERSION=${{ env.VERSION }}
build-args:
- VERSION=${{ env.VERSION }}
- IN_DOCKER=true
platforms: |
linux/386
linux/amd64
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ RUN go mod download
COPY . .
COPY --from=flutter /app/build/web ./cmd/web/dist
ARG VERSION=dev
RUN CGO_ENABLED=0 go build -tags nosqlite,web -ldflags="-s -w -X github.com/GopeedLab/gopeed/pkg/base.Version=${VERSION}" -o dist/gopeed github.com/GopeedLab/gopeed/cmd/web
RUN CGO_ENABLED=0 go build -tags nosqlite,web -ldflags="-s -w \
-X github.com/GopeedLab/gopeed/pkg/base.Version=${VERSION}" \
-X github.com/GopeedLab/gopeed/pkg/base.InDocker=${IN_DOCKER}" \
-o dist/gopeed github.com/GopeedLab/gopeed/cmd/web
FROM alpine:3.14.2
LABEL maintainer="monkeyWie"
Expand Down
17 changes: 12 additions & 5 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
_ "embed"
"fmt"
"github.com/GopeedLab/gopeed/pkg/base"
"github.com/GopeedLab/gopeed/pkg/rest"
"github.com/GopeedLab/gopeed/pkg/rest/model"
"net/http"
Expand All @@ -24,14 +25,20 @@ func Start(cfg *model.StartConfig) {
panic(err)
}
if downloadCfg.FirstLoad {
// Set default download dir to user download dir
userDir, err := os.UserHomeDir()
if err == nil {
downloadDir := filepath.Join(userDir, "Downloads")
// Set default download dir, in docker, it will be ${exe}/Downloads, else it will be ${user}/Downloads
var downloadDir string
if base.InDocker {
downloadDir = filepath.Join(filepath.Dir(cfg.StorageDir), "Downloads")
} else {
userDir, err := os.UserHomeDir()
if err == nil {
downloadDir = filepath.Join(userDir, "Downloads")
}
}
if downloadDir != "" {
downloadCfg.DownloadDir = downloadDir
rest.Downloader.PutConfig(downloadCfg)
}

}
fmt.Printf("Server start success on http://%s\n", listener.Addr().String())
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
Expand Down
1 change: 1 addition & 0 deletions pkg/base/version.go → pkg/base/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package base

// Version is the build version, set at build time, using `go build -ldflags "-X github.com/GopeedLab/gopeed/pkg/base.Version=1.0.0"`.
var Version string
var InDocker bool

func init() {
if Version == "" {
Expand Down

0 comments on commit c81ca7f

Please sign in to comment.