Merge branch 'go-sonic:master' into master

pull/203/head^2
李远君 2 years ago committed by GitHub
commit a4c667d91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,10 +1,6 @@
name: Linter
on:
push:
paths:
- "**/*.go"
- ".github/workflows/linter.yml"
pull_request:
types: [opened, synchronize, reopened]
paths:

@ -0,0 +1,38 @@
name: Release-Docker
on:
release:
types: [published]
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set build time
run: |
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
-
name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/arm64,linux/amd64
push: true
file: ./scripts/Dockerfile
tags: gosonic/sonic:latest,gosonic/sonic:${{github.ref_name}}
build-args: |
SONIC_VERSION=${{github.ref_name}}
BUILD_COMMIT=${{github.sha}}
BUILD_TIME=${{env.BUILD_TIME}}

@ -54,6 +54,7 @@ jobs:
- name: Show workflow information
run: |
echo "GOOS: $GOOS, GOARCH: $GOARCH"
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
- name: Build
uses: crazy-max/ghaction-xgo@v2
@ -66,7 +67,7 @@ jobs:
v: true
x: false
race: false
ldflags: -s -w
ldflags: -s -w -X 'github.com/go-sonic/sonic/consts.SonicVersion=${{github.ref_name}}' -X 'github.com/go-sonic/sonic/consts.BuildCommit=${{github.sha}}' -X 'github.com/go-sonic/sonic/consts.BuildTime=${{env.BUILD_TIME}}'
buildmode: default
trimpath: true

1
.gitignore vendored

@ -4,6 +4,7 @@
/upload
/.vscode
sonic.db
sonic
__debug_bin
/resources/template/theme/
!/resources/template/theme/default-theme-anatole

@ -19,7 +19,6 @@ const (
)
const (
SonicVersion = "1.0.0"
SonicBackupPrefix = "sonic-backup-"
SonicDataExportPrefix = "sonic-data-export-"
SonicBackupMarkdownPrefix = "sonic-backup-markdown-"
@ -40,7 +39,10 @@ const (
ThemeCustomPostPrefix = "post_"
)
// StartTime 系统启动时间
var StartTime time.Time
var DatabaseVersion string
var (
StartTime time.Time = time.Now()
DatabaseVersion string
SonicVersion = "v1.0.0"
BuildTime string
BuildCommit string
)

@ -3,7 +3,6 @@ package listener
import (
"context"
"fmt"
"time"
"go.uber.org/zap"
"gorm.io/gorm"
@ -37,7 +36,6 @@ func (s *StartListener) HandleEvent(ctx context.Context, startEvent event.Event)
if _, ok := startEvent.(*event.StartEvent); !ok {
return nil
}
consts.StartTime = time.Now()
err := s.createOptions()
if err != nil {

@ -1,14 +1,16 @@
FROM golang:1.19.3-alpine as builder
RUN apk --no-cache add git ca-certificates gcc g++
WORKDIR /go/src/github.com/go-sonic/
COPY . /go/src/github.com/go-sonic/sonic/
WORKDIR /go/src/github.com/go-sonic/sonic
RUN git clone --recursive --depth 1 https://github.com/go-sonic/sonic.git
ARG BUILD_COMMIT
ARG BUILD_TIME
ARG SONIC_VERSION
WORKDIR /go/src/github.com/go-sonic/sonic
RUN GOPROXY=https://goproxy.cn CGO_ENABLED=1 GOOS=linux go build -o sonic -ldflags="-s -w" -trimpath .
RUN CGO_ENABLED=1 GOOS=linux && \
go build -o sonic -ldflags="-s -w -X github.com/go-sonic/sonic/consts.SonicVersion=${SONIC_VERSION} -X github.com/go-sonic/sonic/consts.BuildCommit=${BUILD_COMMIT} -X github.com/go-sonic/sonic/consts.BuildTime=${BUILD_TIME}" -trimpath .
RUN mkdir -p /app/conf && \
mkdir /app/resources && \
@ -17,12 +19,14 @@ RUN mkdir -p /app/conf && \
cp -r /go/src/github.com/go-sonic/sonic/resources /app/ && \
cp /go/src/github.com/go-sonic/sonic/scripts/docker_init.sh /app/
FROM alpine:latest as prod
COPY --from=builder /app/ /app/
RUN apk update \
&& apk add --no-cache tzdata \
RUN apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

@ -8,7 +8,6 @@ import (
"math/rand"
"os"
"path/filepath"
"runtime"
"time"
uuid2 "github.com/google/uuid"
@ -184,7 +183,7 @@ func (a *adminServiceImpl) RefreshToken(ctx context.Context, refreshToken string
func (a *adminServiceImpl) GetEnvironments(ctx context.Context) *dto.EnvironmentDTO {
environments := &dto.EnvironmentDTO{
Database: string(dal.DBType) + " " + consts.DatabaseVersion,
Version: runtime.Version(),
Version: consts.SonicVersion,
StartTime: consts.StartTime.UnixMilli(),
Mode: util.IfElse(a.Config.Sonic.Mode == "", "production", a.Config.Sonic.Mode).(string),
}

@ -158,7 +158,7 @@ func (a *attachmentServiceImpl) Upload(ctx context.Context, fileHeader *multipar
Path: strings.ReplaceAll(attachmentDTO.Path, string(os.PathSeparator), "/"),
Size: attachmentDTO.Size,
Suffix: attachmentDTO.Suffix,
ThumbPath: attachmentDTO.ThumbPath,
ThumbPath: strings.ReplaceAll(attachmentDTO.Path, string(os.PathSeparator), "/"),
Type: attachmentDTO.AttachmentType,
Width: attachmentDTO.Width,
}
@ -168,6 +168,14 @@ func (a *attachmentServiceImpl) Upload(ctx context.Context, fileHeader *multipar
return nil, WrapDBErr(err)
}
attachmentDTO.ID = attachmentEntity.ID
attachmentDTO.Path, err = fileStorage.GetFilePath(ctx, attachmentEntity.Path)
if err != nil {
return nil, err
}
attachmentDTO.ThumbPath, err = fileStorage.GetFilePath(ctx, attachmentEntity.ThumbPath)
if err != nil {
return nil, err
}
return attachmentDTO, nil
}

Loading…
Cancel
Save