diff --git a/.github/workflows/build-arm.yaml b/.github/workflows/build-arm.yaml deleted file mode 100644 index 525d3f3..0000000 --- a/.github/workflows/build-arm.yaml +++ /dev/null @@ -1,72 +0,0 @@ ---- -name: build-arm - -# Trigger the workflow on push or pull request -on: - push: - branches: - - '*' - tags: - - '*' - pull_request: - -jobs: - build_job: - runs-on: ubuntu-20.04 - name: linux_${{ matrix.arch }} - strategy: - matrix: - include: - - arch: armv7 - go: 1.20.7 - go_arch: armv6l - - arch: aarch64 - go: 1.20.7 - go_arch: arm64 - steps: - - uses: actions/checkout@v4 - name: Checkout - with: - fetch-depth: 0 - - uses: uraimo/run-on-arch-action@v2.5.1 - name: Test and Build - id: runcmd - with: - arch: ${{ matrix.arch }} - distro: ubuntu20.04 - githubToken: ${{ github.token }} - - setup: | - mkdir -p "/tmp/artifacts" - dockerRunArgs: | - --volume "/tmp/artifacts:/artifacts" - install: | - apt update - apt install -y fuse libfuse-dev rpm pkg-config curl git make gcc g++ - apt upgrade -y - run: | - export PATH=$PATH:/usr/local/go/bin - rm -rf /usr/local/go - mkdir -p /usr/local/go - curl -s -L https://golang.org/dl/go${{ matrix.go }}.linux-${{ matrix.go_arch }}.tar.gz | tar -C /usr/local -xz - go version - - make test - make build - cp bin/* /artifacts - - name: Show artifacts - run: | - ls -al "/tmp/artifacts" - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - if-no-files-found: error - name: build-${{ matrix.arch }} - path: "/tmp/artifacts/*" - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - files: "/tmp/artifacts/*" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 4a14b92..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,126 +0,0 @@ ---- -name: build - -# Trigger the workflow on push or pull request -on: - push: - branches: - - '*' - tags: - - '*' - pull_request: - -jobs: - build: - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - job_name: ['linux', 'mac', 'windows_amd64'] - - include: - - job_name: linux - os: ubuntu-latest - - - job_name: mac - os: macOS-11 - - - job_name: windows_amd64 - os: windows-latest - - name: ${{ matrix.job_name }} - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: ^1.20 - - - name: Install Libraries on Linux - shell: bash - run: | - sudo modprobe fuse - sudo chmod 666 /dev/fuse - sudo chown root:$USER /etc/fuse.conf - sudo apt-get install fuse libfuse-dev rpm pkg-config - if: matrix.os == 'ubuntu-latest' - - - name: Install Libraries on macOS - shell: bash - run: | - brew update - brew install --cask osxfuse - if: matrix.os == 'macOS-11' - - - name: Install Libraries on Windows - shell: powershell - run: | - $ProgressPreference = 'SilentlyContinue' - choco install -y winfsp zip - echo "CPATH=C:\Program Files\WinFsp\inc\fuse;C:\Program Files (x86)\WinFsp\inc\fuse" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - if ($env:GOARCH -eq "386") { - choco install -y mingw --forcex86 --force - echo "C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw32\\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - } - # Copy mingw32-make.exe to make.exe so the same command line - # can be used on Windows as on macOS and Linux - $path = (get-command mingw32-make.exe).Path - Copy-Item -Path $path -Destination (Join-Path (Split-Path -Path $path) 'make.exe') - if: matrix.os == 'windows-latest' - - - name: Print Go version and environment - shell: bash - run: | - printf "Using go at: $(which go)\n" - printf "Go version: $(go version)\n" - printf "\n\nGo environment:\n\n" - go env - printf "\n\nSystem environment:\n\n" - env - - - name: Go module cache - uses: actions/cache@v3.3.2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Run tests - shell: bash - run: | - make test-race - - name: Convert coverage.out to coverage.lcov - uses: jandelgado/gcov2lcov-action@v1.0.9 - if: matrix.os == 'ubuntu-latest' - - name: Coveralls - uses: coverallsapp/github-action@v2.2.3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: coverage.lcov - if: matrix.os == 'ubuntu-latest' - - - name: Build - shell: bash - run: | - make build - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - if-no-files-found: error - name: build-${{ matrix.job_name }} - path: bin/* - - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - files: bin/* diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f1d968d..3c7e138 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,48 +8,61 @@ on: - "v*" jobs: - main: + build-docker: + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/386 + - inux/arm/v6 + - linux/arm/v7 + - linux/arm64 runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Docker meta id: meta - uses: crazy-max/ghaction-docker-meta@v5.0.0 + uses: docker/metadata-action@v5 with: - images: tstor/tstor + # list of Docker images to use as base name for tags + images: ghcr.io/${{ github.repository }} + # generate Docker tags based on the following events/attributes tags: | + type=schedule type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.0.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3.0.0 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v5.0.0 + - name: Build and push Docker image + uses: docker/build-push-action@v4 with: context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} + push: true + pull: true + platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} - platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 - - - name: Update repo description - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: tstor/tstor + sbom: true + provenance: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index ae9df9a..d75f316 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Stage 1: Build #=============== -FROM golang:1.20-alpine as builder +FROM golang:1.20 as builder ENV BIN_REPO=git.kmsign.ru/royalcat/tstor ENV BIN_PATH=$GOPATH/src/$BIN_REPO diff --git a/cmd/tstor/main.go b/cmd/tstor/main.go index c68daae..71cc7d9 100644 --- a/cmd/tstor/main.go +++ b/cmd/tstor/main.go @@ -66,7 +66,7 @@ func main() { } func setupStorage(tcfg config.TorrentClient) (storage.ClientImplCloser, storage.PieceCompletion, error) { - pcp := filepath.Join(tcfg.MetadataFolder, "piece-completion") + pcp := filepath.Join(tcfg.DataFolder, "piece-completion") if err := os.MkdirAll(pcp, 0744); err != nil { return nil, nil, fmt.Errorf("error creating piece completion folder: %w", err) } @@ -87,7 +87,7 @@ func setupStorage(tcfg config.TorrentClient) (storage.ClientImplCloser, storage. // log.Info().Msg(fmt.Sprintf("setting cache size to %d MB", tcfg.GlobalCacheSize)) // fc.SetCapacity(tcfg.GlobalCacheSize * 1024 * 1024) - filesDir := filepath.Join(tcfg.MetadataFolder, "files") + filesDir := filepath.Join(tcfg.DataFolder, "files") if err := os.MkdirAll(pcp, 0744); err != nil { return nil, nil, fmt.Errorf("error creating piece completion folder: %w", err) } diff --git a/src/config/default.go b/src/config/default.go index 7367e84..1be76be 100644 --- a/src/config/default.go +++ b/src/config/default.go @@ -1,12 +1,5 @@ package config -const ( - metadataFolder = "./tstor-data/metadata" - mountFolder = "./tstor-data/mount" - logsFolder = "./tstor-data/logs" - serverFolder = "./tstor-data/served-folders/server" -) - var defaultConfig = Config{ WebUi: WebUi{ Port: 4444, @@ -24,21 +17,22 @@ var defaultConfig = Config{ Pass: "admin", }, Fuse: Fuse{ - Enabled: false, - AllowOther: false, - Path: mountFolder, + Enabled: false, }, }, TorrentClient: TorrentClient{ - GlobalCacheSize: 2048, - MetadataFolder: metadataFolder, - AddTimeout: 60, - ReadTimeout: 120, + DataFolder: "data", + MetadataFolder: "metadata", + + // GlobalCacheSize: 2048, + + AddTimeout: 60, + ReadTimeout: 120, }, Log: Log{ - Path: logsFolder, + Path: "/tmp/tstor", MaxBackups: 2, MaxSize: 50, }, @@ -69,7 +63,7 @@ var defaultRoutes = []Route{ var defaultServers = []Server{ { Name: "server", - Path: serverFolder, + Path: "server", Trackers: []string{ "wss://tracker.btorrent.xyz", "wss://tracker.openwebtorrent.com", diff --git a/src/config/load.go b/src/config/load.go index 363c678..5ccb1d9 100644 --- a/src/config/load.go +++ b/src/config/load.go @@ -24,9 +24,9 @@ func Load(path string) (*Config, error) { _ = k.Load(file.Provider(path), yaml.Parser()) // its ok if file doesnt exist } - err = k.Load(env.Provider("tstor_", ".", func(s string) string { + err = k.Load(env.Provider("TSTOR_", ".", func(s string) string { return strings.Replace(strings.ToLower( - strings.TrimPrefix(s, "tstor_")), "_", ".", -1) + strings.TrimPrefix(s, "TSTOR_")), "_", ".", -1) }), nil) if err != nil { return nil, err diff --git a/src/config/model.go b/src/config/model.go index 65e9e57..ff10a27 100644 --- a/src/config/model.go +++ b/src/config/model.go @@ -22,11 +22,15 @@ type Log struct { } type TorrentClient struct { - ReadTimeout int `koanf:"read_timeout,omitempty"` - AddTimeout int `koanf:"add_timeout,omitempty"` - GlobalCacheSize int64 `koanf:"global_cache_size,omitempty"` - MetadataFolder string `koanf:"metadata_folder,omitempty"` - DisableIPv6 bool `koanf:"disable_ipv6,omitempty"` + ReadTimeout int `koanf:"read_timeout,omitempty"` + AddTimeout int `koanf:"add_timeout,omitempty"` + + DisableIPv6 bool `koanf:"disable_ipv6,omitempty"` + + DataFolder string `koanf:"data_folder,omitempty"` + MetadataFolder string `koanf:"metadata_folder,omitempty"` + + // GlobalCacheSize int64 `koanf:"global_cache_size,omitempty"` Routes []Route `koanf:"routes"` Servers []Server `koanf:"servers"`