mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-03-13 13:39:02 -05:00
Enhanced Docker build / release build
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
name: Docker Publish Release Multiarch
|
||||
name: Docker Publish Dev Multiarch
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
6
BuildVars.go
Normal file
6
BuildVars.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package main
|
||||
|
||||
// compiler sets this to true if compiled with the Docker image
|
||||
var IS_DOCKER = "false"
|
||||
var BUILD_TIME = "Dev Build"
|
||||
var BUILDER = "Manual Build"
|
||||
@@ -112,7 +112,7 @@ func askForUsername() string {
|
||||
}
|
||||
|
||||
func askForLocalOnly() bool {
|
||||
if isDocker() {
|
||||
if IS_DOCKER != "false" {
|
||||
return false
|
||||
}
|
||||
fmt.Print("Bind port to localhost only? [Y/n]: ")
|
||||
|
||||
@@ -5,15 +5,17 @@ FROM golang:1.16 AS build_base
|
||||
## 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 go.mod /compile
|
||||
RUN cd /compile && go mod download
|
||||
|
||||
COPY . /compile
|
||||
|
||||
RUN cd /compile && CGO_ENABLED=0 go build -o /compile/gokapi
|
||||
RUN cd /compile && CGO_ENABLED=0 go build -ldflags="-s -w -X 'main.IS_DOCKER=true' -X 'main.BUILDER=Project Docker File' -X 'main.BUILD_TIME=$(date)'" -o /compile/gokapi
|
||||
|
||||
FROM alpine:3.13
|
||||
|
||||
|
||||
RUN apk add ca-certificates && mkdir /app && touch /app/.isdocker
|
||||
RUN apk add ca-certificates && mkdir /app && touch /app/.isdocker
|
||||
COPY --from=build_base /compile/gokapi /app/gokapi
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -111,8 +111,4 @@ func readLine() string {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
text, _ := reader.ReadString('\n')
|
||||
return strings.Replace(text, "\n", "", -1)
|
||||
}
|
||||
|
||||
func isDocker() bool {
|
||||
return fileExists(".isdocker")
|
||||
}
|
||||
}
|
||||
15
Main.go
15
Main.go
@@ -11,6 +11,7 @@ import (
|
||||
const VERSION = "1.1.0"
|
||||
|
||||
func main() {
|
||||
checkPrimaryArguments()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
fmt.Println("Gokapi v" + VERSION + " starting")
|
||||
createDataDir()
|
||||
@@ -21,11 +22,23 @@ func main() {
|
||||
startWebserver()
|
||||
}
|
||||
|
||||
func checkPrimaryArguments() {
|
||||
if len(os.Args) > 1 {
|
||||
if os.Args[1] == "--version" || os.Args[1] == "-v" {
|
||||
fmt.Println("Gokapi v" + VERSION)
|
||||
fmt.Println("Builder: " + BUILDER)
|
||||
fmt.Println("Build Date: " + BUILD_TIME)
|
||||
fmt.Println("Docker Version: " + IS_DOCKER)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkArguments() {
|
||||
if len(os.Args) > 1 {
|
||||
if os.Args[1] == "--reset-pw" {
|
||||
fmt.Println("Password change requested")
|
||||
globalConfig.AdminPassword = hashPassword(askForPassword(),SALT_PW_ADMIN)
|
||||
globalConfig.AdminPassword = hashPassword(askForPassword(), SALT_PW_ADMIN)
|
||||
saveConfig()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ RUN \
|
||||
update-ca-certificates && \
|
||||
rm -rf /var/lib/apt
|
||||
|
||||
COPY go.mod /tmp/tmp/go.mod
|
||||
|
||||
RUN cd /tmp/tmp/ && go mod download && rm -r /tmp/tmp
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
@@ -16,7 +16,7 @@ for target in $targets; do
|
||||
fi
|
||||
|
||||
echo "----> Building project for: $target"
|
||||
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -o $output
|
||||
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags="-s -w -X 'main.BUILDER=Github Release Builder' -X 'main.BUILD_TIME=$(date)'" -o $output
|
||||
zip -j $output.zip $output > /dev/null
|
||||
rm $output
|
||||
done
|
||||
|
||||
8
release/go.mod
Normal file
8
release/go.mod
Normal file
@@ -0,0 +1,8 @@
|
||||
module SingleDownload
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
|
||||
)
|
||||
Reference in New Issue
Block a user