分离静态文件
This commit is contained in:
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@@ -45,14 +45,14 @@ jobs:
|
|||||||
- name: Create ZIP archive
|
- name: Create ZIP archive
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: |
|
run: |
|
||||||
cp -v ./config_example.ini ./build || exit 1
|
cp -v ./config_example.ini ./assets ./build/ || exit 1
|
||||||
pushd build || exit 1
|
pushd build || exit 1
|
||||||
ls -1 yggdrasil-* | while read LINE; do
|
ls -1 yggdrasil-* | while read LINE; do
|
||||||
PREFIX="${LINE%.*}"
|
PREFIX="${LINE%.*}"
|
||||||
SUFFIX="$(echo "$LINE" | grep -osE '\.\w+' || printf '')"
|
SUFFIX="$(echo "$LINE" | grep -osE '\.\w+' || printf '')"
|
||||||
cp -v "$LINE" "yggdrasil$SUFFIX"
|
cp -v "$LINE" "yggdrasil$SUFFIX"
|
||||||
FILE="../$PREFIX.zip"
|
FILE="../$PREFIX.zip"
|
||||||
zip -9v "$FILE" "yggdrasil$SUFFIX" *.ini
|
zip -9v "$FILE" "yggdrasil$SUFFIX" *.ini assets
|
||||||
DGST="$FILE.dgst"
|
DGST="$FILE.dgst"
|
||||||
openssl dgst -md5 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
openssl dgst -md5 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
||||||
openssl dgst -sha1 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
openssl dgst -sha1 "$FILE" | sed 's/([^)]*)//g' >>"$DGST"
|
||||||
|
@@ -10,6 +10,7 @@ COPY "build/yggdrasil-${TARGETOS}-${TARGETARCH}" /app/yggdrasil
|
|||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
VOLUME /app/data
|
VOLUME /app/data
|
||||||
|
COPY assets /app/data/assets/
|
||||||
|
|
||||||
WORKDIR /app/data
|
WORKDIR /app/data
|
||||||
ENTRYPOINT ["/app/yggdrasil"]
|
ENTRYPOINT ["/app/yggdrasil"]
|
||||||
|
2
Makefile
2
Makefile
@@ -23,7 +23,7 @@ assets:
|
|||||||
cp -r frontend/dist/. assets/
|
cp -r frontend/dist/. assets/
|
||||||
|
|
||||||
package:$(BINARY)
|
package:$(BINARY)
|
||||||
tar -zcf $(PACKAGE_NAME) $(BINARY) config_example.ini
|
tar -zcf $(PACKAGE_NAME) $(BINARY) config_example.ini assets
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(GO_CLEAN)
|
-$(GO_CLEAN)
|
||||||
|
11
main.go
11
main.go
@@ -22,13 +22,11 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"embed"
|
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"io/fs"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -40,9 +38,6 @@ import (
|
|||||||
"yggdrasil-go/util"
|
"yggdrasil-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed assets/*
|
|
||||||
var f embed.FS
|
|
||||||
|
|
||||||
type MetaCfg struct {
|
type MetaCfg struct {
|
||||||
ServerName string `ini:"server_name"`
|
ServerName string `ini:"server_name"`
|
||||||
ImplementationName string `ini:"implementation_name"`
|
ImplementationName string `ini:"implementation_name"`
|
||||||
@@ -139,11 +134,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
router.InitRouters(r, db, &serverMeta, meta.SkinRootUrl)
|
router.InitRouters(r, db, &serverMeta, meta.SkinRootUrl)
|
||||||
assetsFs, err := fs.Sub(f, "assets")
|
r.Static("/profile", "assets")
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
r.StaticFS("/profile", http.FS(assetsFs))
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: serverCfg.ServerAddress,
|
Addr: serverCfg.ServerAddress,
|
||||||
Handler: r,
|
Handler: r,
|
||||||
|
Reference in New Issue
Block a user