Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiesun committed May 16, 2024
1 parent 848d2e9 commit 810dd5f
Show file tree
Hide file tree
Showing 749 changed files with 317,310 additions and 21 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
root = true

# all files
[*.go]
indent_style = tab
indent_size = 4
insert_final_newline = true

[*.py]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.js]
charset = utf-8
indent_style = space
indent_size = 4

[*.json]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
assets/translate.db filter=lfs diff=lfs merge=lfs -text
*.css linguist-language=go
*.html linguist-language=go
*.go linguist-language=go
53 changes: 53 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: toughradius docker build and publish

on:
# run it on push to the default repository branch
push:
branches: [main]
# run it during pull request
pull_request:

jobs:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to repositories
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest

# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v3

# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.MY_GITHUB_TOKEN }}

- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2
with:
# 指向带有 Dockerfile 的源代码所在位置的相对路径
context: ./
# Note: tags has to be all lower-case
tags: |
talkincode/toughradius:latest
ghcr.io/talkincode/toughradius:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
107 changes: 107 additions & 0 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: toughradius release

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build and Release
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: Check out code
uses: actions/checkout@v3

# Build for ARM64
- name: Build for ARM64
run: |
mkdir -p ./release
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags '-s -w -extldflags "-static"' -o ./release/toughradius_arm64 main.go
# Build for AMD64
- name: Build for AMD64
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w -extldflags "-static"' -o ./release/toughradius_amd64 main.go
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

# Upload ARM64 Asset
- name: Upload Release Asset for ARM64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/toughradius_arm64
asset_name: toughradius_arm64
asset_content_type: application/octet-stream

# Upload AMD64 Asset
- name: Upload Release Asset for AMD64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/toughradius_amd64
asset_name: toughradius_amd64
asset_content_type: application/octet-stream

# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to repositories
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest

# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v3

# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.MY_GITHUB_TOKEN }}

- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2
with:
# 指向带有 Dockerfile 的源代码所在位置的相对路径
context: ./
# Note: tags has to be all lower-case
tags: |
talkincode/toughradius:${{ github.ref_name }}
ghcr.io/talkincode/toughradius:${{ github.ref_name }}
# build on feature branches, push only on main branch
push: ${{ startsWith(github.ref, 'refs/tags/') }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
37 changes: 16 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.idea
.vscode
assets/build.txt
assets/buildver.txt
/release/
release
__debug_bin
.DS_Store
/.fleet/
/testdatas/
/toughradius.yml
/tmp/
log_info.log
__debug_bin*
.log
debian
83 changes: 83 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
BUILD_ORG := talkincode
BUILD_VERSION := latest
BUILD_TIME := $(shell date "+%F %T")
BUILD_NAME := logsight
RELEASE_VERSION := v1.0.1
SOURCE := main.go
RELEASE_DIR := ./release
COMMIT_SHA1 := $(shell git show -s --format=%H )
COMMIT_DATE := $(shell git show -s --format=%cD )
COMMIT_USER := $(shell git show -s --format=%ce )
COMMIT_SUBJECT := $(shell git show -s --format=%s )

buildpre:
echo "BuildVersion=${BUILD_VERSION} ${RELEASE_VERSION} ${BUILD_TIME}" > assets/buildinfo.txt
echo "ReleaseVersion=${RELEASE_VERSION}" >> assets/buildinfo.txt
echo "BuildTime=${BUILD_TIME}" >> assets/buildinfo.txt
echo "BuildName=${BUILD_NAME}" >> assets/buildinfo.txt
echo "CommitID=${COMMIT_SHA1}" >> assets/buildinfo.txt
echo "CommitDate=${COMMIT_DATE}" >> assets/buildinfo.txt
echo "CommitUser=${COMMIT_USER}" >> assets/buildinfo.txt
echo "CommitSubject=${COMMIT_SUBJECT}" >> assets/buildinfo.txt

fastpub:
docker buildx build --platform=linux/amd64 --build-arg BTIME="$(shell date "+%F %T")" -t logsight .
docker tag logsight ${BUILD_ORG}/logsight:latest
docker push ${BUILD_ORG}/logsight:latest

fastpubm1:
make build
docker buildx build --platform=linux/amd64 --build-arg BTIME="$(shell date "+%F %T")" -t logsight . -f Dockerfile.local
docker tag logsight ${BUILD_ORG}/logsight:latest-amd64
docker push ${BUILD_ORG}/logsight:latest-amd64
make buildarm64
docker buildx build --platform=linux/arm64 --build-arg BTIME="$(shell date "+%F %T")" -t logsight . -f Dockerfile.local
docker tag logsight ${BUILD_ORG}/logsight:latest-arm64
docker push ${BUILD_ORG}/logsight:latest-arm64
docker manifest create ${BUILD_ORG}/logsight:latest ${BUILD_ORG}/logsight:latest-arm64 ${BUILD_ORG}/logsight:latest-amd64
# 标注不同架构镜像
docker manifest annotate ${BUILD_ORG}/logsight:latest ${BUILD_ORG}/logsight:latest-amd64 --os linux --arch amd64
docker manifest annotate ${BUILD_ORG}/logsight:latest ${BUILD_ORG}/logsight:latest-arm64 --os linux --arch arm64
# 推送镜像
docker manifest push ${BUILD_ORG}/logsight:latest

build:
test -d ./release || mkdir -p ./release
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w -extldflags "-static"' -o ./release/logsight main.go
upx ./release/logsight

buildarm64:
test -d ./release || mkdir -p ./release
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags '-s -w -extldflags "-static"' -o ./release/logsight main.go
upx ./release/logsight

syncdev:
make buildpre
@read -p "提示:同步操作尽量在完成一个完整功能特性后进行,请输入提交描述 (develop): " cimsg; \
git commit -am "$(shell date "+%F %T") : $${cimsg}"
# 切换主分支并更新
git checkout main
git pull origin main
# 切换开发分支变基合并提交
git checkout develop
git rebase -i main
# 切换回主分支并合并开发者分支,推送主分支到远程,方便其他开发者合并
git checkout main
git merge --no-ff develop
git push origin main
# 切换回自己的开发分支继续工作
git checkout develop


updev:
make buildpre
make build
scp ${RELEASE_DIR}/${BUILD_NAME} trdev-server:/tmp/logsight
ssh trdev-server "systemctl stop logsight && /tmp/logsight -install && systemctl start logsight"

swag:
swag fmt && swag init


.PHONY: clean build

Loading

0 comments on commit 810dd5f

Please sign in to comment.