mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
[version] add version info
This commit is contained in:
parent
05661032b3
commit
993ce2a4ed
@ -4,7 +4,7 @@ tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
bin = "tmp/main.exe"
|
||||
cmd = "go build -o ./tmp/main.exe ./cmd/sms-gateway"
|
||||
cmd = "go build -ldflags='-X github.com/capcom6/sms-gateway/internal/version.AppVersion=dev -X github.com/capcom6/sms-gateway/internal/version.AppRelease=1' -o ./tmp/main.exe ./cmd/sms-gateway"
|
||||
delay = 1000
|
||||
exclude_dir = ["api", "assets", "tmp", "vendor", "testdata", "tmp", "web"]
|
||||
exclude_file = []
|
||||
|
||||
10
.github/workflows/docker-build.yml
vendored
10
.github/workflows/docker-build.yml
vendored
@ -46,11 +46,19 @@ jobs:
|
||||
username: ${{ secrets.username }}
|
||||
password: ${{ secrets.password }}
|
||||
|
||||
- name: Set APP_VERSION env
|
||||
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
|
||||
- name: Set APP_RELEASE env
|
||||
run: echo APP_RELEASE=$(( ($(date +%s) - $(date -d "2022-06-15" +%s)) / 86400 )) >> ${GITHUB_ENV}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
file: build/package/Dockerfile
|
||||
build-args: APP=${{ inputs.app-name }}
|
||||
build-args: |
|
||||
APP=${{ inputs.app-name }}
|
||||
APP_VERSION=${{ env.APP_VERSION }}
|
||||
APP_RELEASE_ID=${{ env.APP_RELEASE }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
FROM golang:1.22-alpine AS build
|
||||
|
||||
ARG APP
|
||||
ARG APP_VERSION=1.0.0
|
||||
ARG APP_RELEASE_ID=1
|
||||
WORKDIR /go/src
|
||||
|
||||
# Copy go.mod and go.sum
|
||||
@ -15,7 +17,7 @@ COPY . .
|
||||
|
||||
# Builds the application as a staticly linked one, to allow it to run on alpine
|
||||
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .
|
||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app ./cmd/${APP}/main.go
|
||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-w -s -X github.com/capcom6/${APP}/internal/version.AppVersion=${APP_VERSION} -X github.com/capcom6/${APP}/internal/version.AppRelease=${APP_RELEASE_ID}" -o app ./cmd/${APP}/main.go
|
||||
|
||||
# Build MkDocs
|
||||
FROM squidfunk/mkdocs-material:9.5.15 AS mkdocs
|
||||
|
||||
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"github.com/capcom6/sms-gateway/internal/sms-gateway/modules/health"
|
||||
"github.com/capcom6/sms-gateway/internal/version"
|
||||
"github.com/capcom6/sms-gateway/pkg/maps"
|
||||
"github.com/capcom6/sms-gateway/pkg/smsgateway"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -42,7 +43,9 @@ func (h *healthHandler) getHealth(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
res := smsgateway.HealthResponse{
|
||||
Status: smsgateway.HealthStatus(check.Status),
|
||||
Status: smsgateway.HealthStatus(check.Status),
|
||||
Version: version.AppVersion,
|
||||
ReleaseID: version.AppReleaseID(),
|
||||
Checks: maps.MapValues(
|
||||
check.Checks,
|
||||
func(c health.CheckDetail) smsgateway.HealthCheck {
|
||||
|
||||
17
internal/version/version.go
Normal file
17
internal/version/version.go
Normal file
@ -0,0 +1,17 @@
|
||||
package version
|
||||
|
||||
import "strconv"
|
||||
|
||||
const notSet string = "not set"
|
||||
|
||||
// these information will be collected when build, by `-ldflags "-X main.appVersion=0.1"`
|
||||
var (
|
||||
AppVersion = notSet
|
||||
AppRelease = notSet
|
||||
)
|
||||
|
||||
func AppReleaseID() int {
|
||||
id, _ := strconv.Atoi(AppRelease)
|
||||
|
||||
return id
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user