Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git info for logger #135

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=main
COMMIT=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 4 additions & 1 deletion .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name: Create and publish a Docker image

on:
push:
branches: ["release"]
branches: ['release']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
Expand Down Expand Up @@ -66,6 +66,9 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=release
COMMIT=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
5 changes: 4 additions & 1 deletion .github/workflows/version_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name: Create and publish a Docker image
on:
push:
tags:
- "v*.*.*"
- 'v*.*.*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
Expand Down Expand Up @@ -67,6 +67,9 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=${{ steps.meta.outputs.tags }}
COMMIT=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

FROM golang:1.20-buster AS backend

WORKDIR /app
COPY backend/go.mod backend/go.sum ./

RUN go mod download

COPY backend/. .
RUN go build -o main .
ARG VERSION=unknown
ARG COMMIT=unknown
RUN go build -ldflags="-X main.Version=$VERSION -X main.GitHash=$COMMIT" -o main .

FROM debian:bullseye-slim
WORKDIR /app
Expand Down
8 changes: 5 additions & 3 deletions backend/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

git_repository="https://github.com/HuolalaTech/page-spy-web"
git_version=$(git describe --tags $(git rev-list --tags --max-count=1))
git_hash=$(git rev-parse HEAD)
npm_version=$(echo "$git_version" | sed 's/^v//')
project_name="page-spy-api"
organization="@huolala-tech"
build_with_git_info="-X main.Version=$npm_version -X main.GitHash=$git_hash"


GenerateMainPackageJson() {
Expand Down Expand Up @@ -141,7 +143,7 @@ BuildRelease() {

for arch in ${archs[@]}
do
env GOOS=linux GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-linux-${arch}
env GOOS=linux GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-linux-${arch} -ldflags="${build_with_git_info}"
mkdir -p npm/linux-${arch}/bin
cp -r ./build/${project_name}-linux-${arch} npm/linux-${arch}/bin/${project_name}
PublishAndGeneratePackageJson "linux" "${arch}" "npm/linux-${arch}"
Expand All @@ -151,7 +153,7 @@ BuildRelease() {

for arch in ${win_archs[@]}
do
env GOOS=windows GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-win32-${arch}.exe
env GOOS=windows GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-win32-${arch}.exe -ldflags="${build_with_git_info}"
mkdir -p npm/win32-${arch}
cp -r ./build/${project_name}-win32-${arch}.exe npm/win32-${arch}/${project_name}.exe
PublishAndGeneratePackageJson "win32" "${arch}" "npm/win32-${arch}"
Expand All @@ -161,7 +163,7 @@ BuildRelease() {

for arch in ${mac_archs[@]}
do
env GOOS=darwin GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-darwin-${arch}
env GOOS=darwin GOARCH=${arch} CGO_ENABLED=0 go build -o ./build/${project_name}-darwin-${arch} -ldflags="${build_with_git_info}"
mkdir -p npm/darwin-${arch}/bin
cp -r ./build/${project_name}-darwin-${arch} npm/darwin-${arch}/bin/${project_name}
PublishAndGeneratePackageJson "darwin" "${arch}" "npm/darwin-${arch}"
Expand Down
7 changes: 7 additions & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ import (
//go:embed dist/*
var publicContent embed.FS

var (
Version string
GitHash string
)

func main() {
container := container.Container()
err := container.Provide(func() *config.StaticConfig {
return &config.StaticConfig{
DirName: "dist",
Files: publicContent,
Version: Version,
GitHash: GitHash,
}
})

Expand Down