Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Mar 21, 2022
1 parent e771a3a commit f9ed0aa
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 22 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ FROM golang:1.17-alpine AS backend-builder

WORKDIR /app

COPY backend/go.mod .
COPY backend/go.sum .
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY backend/ .
COPY . .

RUN go build -o backend .
RUN go build -o gose ./cmd

FROM node:17 AS frontend-builder

Expand All @@ -25,13 +25,15 @@ COPY frontend/ .

RUN npm run build

FROM scratch
FROM alpine:3.15

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

COPY --from=frontend-builder /app/dist/ /dist/
COPY --from=backend-builder /app/backend /
COPY --from=backend-builder /app/gose /
COPY --from=backend-builder /app/config.yaml /

ENV GIN_MODE=release
ENV GOSE_SERVER_STATIC=/dist

CMD ["/backend", "-config", "/config.yaml"]
ENTRYPOINT [ "/gose" ]
9 changes: 7 additions & 2 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM scratch
ENTRYPOINT ["/gose"]
FROM alpine:3.15

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

ENV GIN_MODE=release

COPY gose /

ENTRYPOINT ["/gose"]
67 changes: 61 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,74 @@
## Roadmap

- Resumable uploads

- Configurable retention time

- Server-side encryption

- End-to-end encryption
- Using [streaming requests](https://web.dev/fetch-upload-streaming/)

- Using [streaming requests](https://web.dev/fetch-upload-streaming/)
- Support for multiple buckets

- Torrent web-seeding
- [BEP-17](http://bittorrent.org/beps/bep_0017.html) and/or [BEP-19](http://bittorrent.org/beps/bep_0019.html)

## Installation

### Pre-compiled binaries from GitHub releases

Take the download link for your OS/Arch from the [Releases Page](https://github.com/stv0g/gose/releases/) and run:

```bash
export RELEASE_URL=https://github.com/stv0g/gose/releases/download/v0.0.2/gose_0.0.2_linux_amd64
wget "${RELEASE_URL}" -O gose
chmod +x gose
mv gose /usr/local/bin
```

### Docker

Via environment variables in `.env` file:

```bash
docker run -v$(pwd)/config.yaml:/config.yaml --publish=8080:8080 ghcr.io/stv0g/gose -config config.yaml
```

or via a configuration file:

```bash
docker run -v$(pwd)/config.yaml:/config.yaml --publish=8080:8080 ghcr.io/stv0g/gose -config /config.yaml
```

## Configuration

Gose can be configured via a configuration file and/or environment variables

### File

For reference have a look at the [example configuration file](config.yaml).

### Environment variables

All settings from the configuration file can also be set via environment variables:

| Variable | Example Value | Description |
| :-- | :-- | :-- |
| `GOSE_S3_BUCKET` | `gose-uploads` | Name of S3 bucket |
| `GOSE_S3_ENDPOINT` | `s3.0l.de` | Hostname of S3 server |
| `GOSE_S3_REGION` | `s3` | Region of S3 server |
| `GOSE_S3_PATH_STYLE` | `true` | Prepend bucket name to path |
| `GOSE_S3_NO_SSL` | `false` | Disable SSL encryption for S3 |
| `GOSE_S3_ACCESS_KEY` | `""` | S3 Access Key |
| `GOSE_S3_SECRET_KEY` | `""` | S3 Secret Key |
| `AWS_ACCESS_KEY_ID` | `` | alias for `GOSE_S3_ACCESS_KEY` |
| `AWS_SECRET_ACCESS_KEY` | `` | alias for `AWS_SECRET_ACCESS_KEY` |
| `GOSE_S3_MAX_UPLOAD_SIZE` | `5TB` | Maximum upload size |
| `GOSE_S3_PART_SIZE` | `5MB` | Part-size for multi-part uploads |
| `GOSE_S3_EXPIRATION_DEFAULT_CLASS` | `1week # one of the tags below` | Default expiration class |
| `GOSE_SERVER_LISTEN` | `":8080"` | Listen address and port of Gose |
| `GOSE_SHORTENER_ENDPOINT` | `"https://shlink-api/rest/v2/short-urls/shorten?apiKey=<your-api-token>&format=txt&longUrl={{.UrlEscaped}}"` | API Endpoint of link shortener |
| `GOSE_SHORTENER_METHOD` | `GET` | HTTP method for link shortener |
| `GOSE_SHORTENER_RESPONSE` | `raw` | Response type of link shortener |
| `GOSE_NOTIFICATION_URLS` | `pushover://shoutrrr:<api-token>@<user-key>?devices=laptop1&title=Upload` | Service URLs for [shoutrrr notifications](https://containrrr.dev/shoutrrr/) |
| `GOSE_NOTIFICATION_TEMPLATE` | `"New Upload: {{.URL}}"` | Notification message template |

## Author

GoSƐ has been written by [Steffen Vogel](mailto:post@steffenvogel.de).
Expand Down
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ s3:
secret_key: ""

max_upload_size: 5TB
part_size: 5MB
part_size: 16MB

expiration:
default_class: 1week # one of the tags below
Expand Down Expand Up @@ -40,7 +40,7 @@ shortener:
# Available template args:
# .Url
# .UrlEscaped
endpoint: "https://shlink-api/rest/v2/short-urls/shorten?apiKey=<your-api-token>&format=txt&longUrl={{.UrlEscaped}}"
endpoint: "https://shlink-api/rest/v2/short-urls/shorten?apiKey=<your-api-token>&format=txt&longUrl={{.URLEscaped}}"
method: GET
response: raw

Expand Down
14 changes: 9 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"flag"
"fmt"
"log"
"net/url"
"strings"

Expand Down Expand Up @@ -117,7 +118,7 @@ func NewConfig(configFile string) (*Config, error) {
}

cfg.SetDefault("s3.max_upload_size", "1TB")
cfg.SetDefault("s3.part_size", "5MB")
cfg.SetDefault("s3.part_size", "16MB")
cfg.SetDefault("server.listen", ":8080")
cfg.SetDefault("server.static", "./dist")

Expand All @@ -129,16 +130,19 @@ func NewConfig(configFile string) (*Config, error) {
cfg.BindEnv("s3.access_key", "AWS_ACCESS_KEY_ID", "MINIO_ACCESS_KEY")
cfg.BindEnv("s3.secret_key", "AWS_SECRET_ACCESS_KEY", "MINIO_SECRET_KEY")

cfg.SetConfigFile(configFile)
if configFile != "" {
cfg.SetConfigFile(configFile)

if err := cfg.ReadInConfig(); err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
if err := cfg.ReadInConfig(); err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
}

if err := cfg.UnmarshalExact(cfg, viper.DecodeHook(mapstructure.TextUnmarshallerHookFunc())); err != nil {
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
}

log.Printf("Loaded configuration:\n")
bs, _ := yaml.Marshal(cfg)
fmt.Print(string(bs))

Expand All @@ -153,7 +157,7 @@ func ParseFlags() (string, error) {

// Set up a CLI flag called "-config" to allow users
// to supply the configuration file
flag.StringVar(&configPath, "config", "./config.yaml", "path to config file")
flag.StringVar(&configPath, "config", "", "path to config file")

// Actually parse the flags
flag.Parse()
Expand Down

0 comments on commit f9ed0aa

Please sign in to comment.