mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-01-05 16:29:52 -06:00
Added Dockerfile, changed config path, enable binding port to 0.0.0.0
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
config.json
|
||||
SingleDownload
|
||||
config/
|
||||
data/
|
||||
.idea/
|
||||
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const configDir = "config"
|
||||
const configFile = "config.json"
|
||||
const configPath = configDir + "/" + configFile
|
||||
|
||||
var globalConfig Configuration
|
||||
|
||||
@@ -41,10 +43,11 @@ func (f *FileList) toJsonResult() string {
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
if !fileExists(configFile) {
|
||||
createConfigDir()
|
||||
if !fileExists(configPath) {
|
||||
generateDefaultConfig()
|
||||
}
|
||||
file, err := os.Open(configFile)
|
||||
file, err := os.Open(configPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -63,8 +66,14 @@ func generateDefaultConfig() {
|
||||
password := askForPassword()
|
||||
url := askForUrl()
|
||||
redirect := askForRedirect()
|
||||
localOnly := askForLocalOnly()
|
||||
port := "127.0.0.1:53842"
|
||||
if !localOnly {
|
||||
port = "0.0.0.0:53842"
|
||||
}
|
||||
|
||||
globalConfig = Configuration{
|
||||
Port: "127.0.0.1:53842",
|
||||
Port: port,
|
||||
AdminName: username,
|
||||
AdminPassword: hashPassword(password),
|
||||
ServerUrl: url,
|
||||
@@ -78,7 +87,7 @@ func generateDefaultConfig() {
|
||||
}
|
||||
|
||||
func saveConfig() {
|
||||
file, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading configuration:", err)
|
||||
os.Exit(1)
|
||||
@@ -102,6 +111,15 @@ func askForUsername() string {
|
||||
return askForUsername()
|
||||
}
|
||||
|
||||
func askForLocalOnly() bool {
|
||||
if isDocker() {
|
||||
return false
|
||||
}
|
||||
fmt.Print("Bind port to localhost only? [Y/n]: ")
|
||||
input := strings.ToLower(readLine())
|
||||
return input != "n"
|
||||
}
|
||||
|
||||
func askForPassword() string {
|
||||
fmt.Print("Password: ")
|
||||
password1, err := terminal.ReadPassword(0)
|
||||
@@ -163,3 +181,14 @@ type Result struct {
|
||||
FileInfo *FileList `json:"FileInfo"`
|
||||
Url string `json:"Url"`
|
||||
}
|
||||
|
||||
func createConfigDir() {
|
||||
if !folderExists(configDir) {
|
||||
err := os.Mkdir(configDir, 0770)
|
||||
check(err)
|
||||
}
|
||||
}
|
||||
|
||||
func isDocker() bool {
|
||||
return fileExists(".isdocker")
|
||||
}
|
||||
|
||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM golang:1.16 AS build_base
|
||||
|
||||
## Usage:
|
||||
## docker build . -t gokapi
|
||||
## docker run -it -v gokapi-data:/app/data -v gokapi-config:/app/config -p 127.0.0.1:53842:53842 gokapi
|
||||
|
||||
RUN mkdir /compile
|
||||
|
||||
COPY . /compile
|
||||
|
||||
RUN cd /compile && CGO_ENABLED=0 go build -o /compile/gokapi
|
||||
|
||||
FROM alpine:3.13
|
||||
|
||||
|
||||
RUN apk add ca-certificates && mkdir /app
|
||||
COPY --from=build_base /compile/gokapi /app/gokapi
|
||||
RUN touch /app/.isdocker
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["/app/gokapi"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user