Compare commits

...

2 Commits

Author SHA1 Message Date
8934da692b feat: 添加 gitea 构建脚本
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 5m9s
2025-06-05 02:25:55 +08:00
e7c4dc58b7 feat: 添加公钥缓存功能 2025-06-05 02:25:03 +08:00
2 changed files with 76 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
name: Build and Push Docker Image
on:
push:
branches:
- dev
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
CGO_ENABLED: 1
steps:
- name: Checkout codebase
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Pre Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: For act to work
run: npm -g install yarn
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'yarn'
cache-dependency-path: frontend
- name: Build Frontend
run: |
make assets
rm -rf /host/${{ gitea.workspace }} && mkdir -p /host/${{ gitea.workspace }}
cp -a . /host/${{ gitea.workspace }}/
- name: Build Yggdrasil Server
uses: crazy-max/ghaction-xgo@v2
with:
xgo_version: latest
go_version: 1.24
dest: build
prefix: yggdrasil
targets: linux/amd64,linux/arm64
v: true
x: false
race: false
ldflags: -s -w -buildid=
tags: nomsgpack sqlite mysql
trimpath: true
- name: Store Back Binaries
run: |
cp -a /host/${{ gitea.workspace }}/build/. build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: docker.sunxinao.cn
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: docker.sunxinao.cn/gardel/yggdrasil-go:latest

View File

@@ -62,8 +62,9 @@ type HomeRouter interface {
}
type homeRouterImpl struct {
serverMeta ServerMeta
myPubKey KeyPair
serverMeta ServerMeta
myPubKey KeyPair
cachedPubKey *PublicKeys
}
func NewHomeRouter(meta *ServerMeta) HomeRouter {
@@ -81,6 +82,10 @@ func (h *homeRouterImpl) Home(c *gin.Context) {
}
func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
if h.cachedPubKey != nil {
c.JSON(http.StatusOK, h.cachedPubKey)
return
}
publicKeys := PublicKeys{}
err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
if err != nil {
@@ -90,4 +95,5 @@ func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
c.JSON(http.StatusOK, publicKeys)
h.cachedPubKey = &publicKeys
}