diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..b32ee13 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,27 @@ +name: Docker +on: + release: + types: [created] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + - name: get version + run: | + VER=$(cat VERSION) + echo "VERSION=$VER" >> $GITHUB_ENV + - name: login + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: build and push + uses: docker/build-push-action@v2 + with: + push: true + tags: ghcr.io/superioz/aqua:${{ env.VERSION }},ghcr.io/superioz/aqua:latest + build-args: | + version=${{ env.VERSION }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..5ec6576 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,12 @@ +name: golangci-lint +on: [push, pull_request] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d8539ef --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,18 @@ +on: [push, pull_request] +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.17.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: go test ./... diff --git a/Dockerfile b/Dockerfile index a9008bf..083cb71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17.2 AS builder +FROM golang:1.17.2-alpine AS builder WORKDIR /build diff --git a/cmd/aqua/main.go b/cmd/aqua/main.go index ef13c44..7154f4d 100644 --- a/cmd/aqua/main.go +++ b/cmd/aqua/main.go @@ -11,7 +11,6 @@ import ( "time" ) -// TODO add github workflows for linting and building docker image // TODO how can we add binaries to github releases? we need it for the cli func main() { @@ -33,12 +32,15 @@ func main() { // scheduler to do the cleanup every x minutes s := gocron.NewScheduler(time.UTC) - s.Every(env.IntOrDefault("FILE_EXPIRATION_CYCLE", 15)).Minutes().StartImmediately().Do(func() { + _, err = s.Every(env.IntOrDefault("FILE_EXPIRATION_CYCLE", 15)).Minutes().StartImmediately().Do(func() { err = uh.FileStorage.Cleanup() if err != nil { klog.Errorln(err) } }) + if err != nil { + klog.Fatalf("could not start cleanup scheduler: %v", err) + } s.StartAsync() r.GET("/healthz", func(c *gin.Context) { diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 84f49ea..1ed510f 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -75,12 +75,12 @@ func (fs *FileStorage) Cleanup() error { // delete this file err = fs.fileSystem.DeleteFile(file.Id) if err != nil { - return errors.New(fmt.Sprintf("Could not delete file with id=%s: %v", file.Id, err)) + return fmt.Errorf("could not delete file with id=%s: %v", file.Id, err) } err = fs.fileMetaDb.DeleteFile(file.Id) if err != nil { - return errors.New(fmt.Sprintf("Could not delete file with id=%s: %v", file.Id, err)) + return fmt.Errorf("could not delete file with id=%s: %v", file.Id, err) } } return nil @@ -111,7 +111,10 @@ func (fs *FileStorage) StoreFile(of multipart.File, expiration int64) (*StoredFi } // write to meta database - fs.fileMetaDb.WriteFile(sf) + err = fs.fileMetaDb.WriteFile(sf) + if err != nil { + return nil, err + } return sf, nil } diff --git a/pkg/shttp/shttp.go b/pkg/shttp/shttp.go index 1b2423c..ef16ded 100644 --- a/pkg/shttp/shttp.go +++ b/pkg/shttp/shttp.go @@ -97,7 +97,10 @@ func GetFileType(file *os.File) (string, error) { } head := make([]byte, 261) - f.Read(head) + _, err = f.Read(head) + if err != nil { + return "", err + } kind, err := filetype.Match(head) if err != nil {