├── .gitattributes ├── .gitignore ├── Dockerfile ├── README.md ├── app.json ├── entrypoint.sh ├── heroku.yml ├── main └── main.go /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | output/ 4 | dist/ 5 | 6 | # Binaries for programs and plugins 7 | *.exe 8 | *.exe~ 9 | *.dll 10 | *.so 11 | *.dylib 12 | *.db 13 | *.bin 14 | 15 | # Test binary, built with `go test -c` 16 | *.test 17 | 18 | # Output of the go coverage tool, specifically when used with LiteIDE 19 | *.out 20 | 21 | # Dependency directories (remove the comment below to include it) 22 | # vendor/ 23 | bin/* -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM xhofe/alist:v2.6.4 2 | LABEL MAINTAINER="i@nn.ci" 3 | 4 | ARG DATABASE_URL 5 | 6 | WORKDIR /opt/alist/ 7 | ENV DB_TYPE postgres 8 | ENV DB_SLL_MODE require 9 | ADD main /main 10 | RUN chmod +x /main 11 | ADD entrypoint.sh /entrypoint.sh 12 | RUN chmod +x /entrypoint.sh 13 | 14 | ENTRYPOINT ["sh", "/entrypoint.sh"] 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alist-heroku-postgresql 2 | 3 | 4 | ## Deploy alist to heroku 5 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 6 | 7 | Use heroku's add-on postgres database, your settings will be persistent, don't worry about hibernate losing configuration. 8 | 9 | If you can't deploy, and it says "We couldn't deploy your app because the source code violates the Salesforce Acceptable Use and External-Facing Services Policy.", you need to fork this repo and click the `Deploy` button in your own fork. 10 | 11 | ## Get Password 12 | `More` -> `View logs` -> You will see your password, if it is scrolled to the top and out of view, click `Restart all dynos` then the log will be redisplayed. 13 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Alist v2", 3 | "description": "Alist on Heroku", 4 | "keywords": ["Alist"], 5 | "env": { 6 | "CACHE_EXPIRATION": { 7 | "description": "Cache invalidation time (unit: minutes)", 8 | "value": "60" 9 | }, 10 | "CLEANUP_INTERVAL": { 11 | "description": "Clear the invalidation cache interval", 12 | "value": "120" 13 | }, 14 | "ASSETS": { 15 | "description": "static resources(refer to https://alist-doc.nn.ci/en/docs/setting/config#assets)", 16 | "value": "https://npm.elemecdn.com/alist-web@$version/dist/" 17 | } 18 | }, 19 | "addons": [ 20 | { 21 | "plan": "heroku-postgresql" 22 | } 23 | ], 24 | "website": "https://github.com/Xhofe/alist", 25 | "repository": "https://github.com/alist-org/alist-heroku-postgres", 26 | "logo": "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", 27 | "stack": "container" 28 | } 29 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | mkdir -p /opt/alist/data/ 2 | /main 3 | 4 | cd /opt/alist 5 | ./alist -conf data/config.json -docker -------------------------------------------------------------------------------- /heroku.yml: -------------------------------------------------------------------------------- 1 | build: 2 | docker: 3 | web: Dockerfile -------------------------------------------------------------------------------- /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlistGo/alist-heroku-postgres/a7b88a319b503a7188ef70e056111fc89fff5308/main -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net/url" 9 | "os" 10 | "strconv" 11 | ) 12 | 13 | type Database struct { 14 | Type string `json:"type" env:"DB_TYPE"` 15 | Host string `json:"host" env:"DB_HOST"` 16 | Port int `json:"port" env:"DB_PORT"` 17 | User string `json:"user" env:"DB_USER"` 18 | Password string `json:"password" env:"DB_PASS"` 19 | Name string `json:"name" env:"DB_NAME"` 20 | DBFile string `json:"db_file" env:"DB_FILE"` 21 | TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"` 22 | SslMode string `json:"ssl_mode" env:"DB_SLL_MODE"` 23 | } 24 | 25 | type Scheme struct { 26 | Https bool `json:"https" env:"HTTPS"` 27 | CertFile string `json:"cert_file" env:"CERT_FILE"` 28 | KeyFile string `json:"key_file" env:"KEY_FILE"` 29 | } 30 | 31 | type CacheConfig struct { 32 | Expiration int64 `json:"expiration" env:"CACHE_EXPIRATION"` 33 | CleanupInterval int64 `json:"cleanup_interval" env:"CLEANUP_INTERVAL"` 34 | } 35 | 36 | type Config struct { 37 | Force bool `json:"force"` 38 | Address string `json:"address" env:"ADDR"` 39 | Port int `json:"port" env:"PORT"` 40 | Assets string `json:"assets" env:"ASSETS"` 41 | Database Database `json:"database"` 42 | Scheme Scheme `json:"scheme"` 43 | Cache CacheConfig `json:"cache"` 44 | TempDir string `json:"temp_dir" env:"TEMP_DIR"` 45 | } 46 | 47 | func main() { 48 | DATABASE_URL := os.Getenv("DATABASE_URL") 49 | fmt.Println("DatabaseUrl", DATABASE_URL) 50 | //DATABASE_URL = "postgres://hfhgpvbymdzusj:39d7f6f3ee4288103e382d5dec22ce668c4e5cb65120f64d574b808775674eb4@ec2-3-218-171-44.compute-1.amazonaws.com:5432/d4o07n33pf6ot7" 51 | u, err := url.Parse(DATABASE_URL) 52 | if err != nil { 53 | fmt.Println(err) 54 | } 55 | user := u.User.Username() 56 | pass, _ := u.User.Password() 57 | host := u.Hostname() 58 | port, _ := strconv.Atoi(u.Port()) 59 | name := u.Path[1:] 60 | config := Config{ 61 | Address: "0.0.0.0", 62 | TempDir: "data/temp", 63 | Database: Database{ 64 | User: user, 65 | Password: pass, 66 | Host: host, 67 | Port: port, 68 | Name: name, 69 | }, 70 | } 71 | confBody, err := json.MarshalIndent(config, "", " ") 72 | if err != nil { 73 | log.Fatalf("failed marshal json: %s", err.Error()) 74 | } 75 | err = ioutil.WriteFile("/opt/alist/data/config.json", confBody, 0777) 76 | if err != nil { 77 | log.Fatalf("failed write json: %s", err.Error()) 78 | } 79 | } 80 | --------------------------------------------------------------------------------