mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-22 19:49:25 +00:00
build: Inject version when build the binaries
The version include git current commit and branch info.
This commit is contained in:
parent
f69a232c22
commit
0d72dd9995
9 changed files with 113 additions and 23 deletions
|
@ -5,9 +5,9 @@ tmp_dir = "tmp"
|
|||
[build]
|
||||
args_bin = []
|
||||
bin = "./tmp/main"
|
||||
cmd = "go build -tags server -o ./tmp/main ."
|
||||
cmd = "make dev"
|
||||
delay = 0
|
||||
exclude_dir = ["assets", "tmp", "testdata", "frontend/node_modules", "data", "bin", "tools"]
|
||||
exclude_dir = ["assets", "tmp", "testdata", "frontend/node_modules", "data", "bin"]
|
||||
exclude_file = []
|
||||
exclude_regex = ["_test.go"]
|
||||
exclude_unchanged = false
|
||||
|
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
|
@ -39,7 +39,7 @@ jobs:
|
|||
goarch: ${{ matrix.goarch }}
|
||||
overwrite: true
|
||||
pre_command: export CGO_ENABLED=0
|
||||
ldflags: -s -w
|
||||
ldflags: -s -w -X xmr-remote-nodes/internal/config.Version=${{github.ref_name}}
|
||||
build_flags: -tags server
|
||||
project_path: .
|
||||
binary_name: server
|
||||
|
@ -53,7 +53,7 @@ jobs:
|
|||
goarch: ${{ matrix.goarch }}
|
||||
overwrite: true
|
||||
pre_command: export CGO_ENABLED=0
|
||||
ldflags: -s -w
|
||||
ldflags: -s -w -X xmr-remote-nodes/internal/config.Version=${{github.ref_name}}
|
||||
binary_name: client
|
||||
project_path: .
|
||||
extra_files: LICENSE README.md
|
||||
|
|
51
Makefile
51
Makefile
|
@ -1,5 +1,39 @@
|
|||
BINARY_NAME = xmr-nodes
|
||||
|
||||
# These build are modified version of rclone's Makefile
|
||||
# https://github.com/rclone/rclone/blob/master/Makefile
|
||||
VERSION := $(shell cat VERSION)
|
||||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
# Last tag on this branch (eg. v1.0.0)
|
||||
LAST_TAG := $(shell git describe --tags --abbrev=0)
|
||||
# Tag of the current commit, if any. If this is not "" then we are building a release
|
||||
RELEASE_TAG := $(shell git tag -l --points-at HEAD)
|
||||
# If we are working on a release, override branch to main
|
||||
ifdef RELEASE_TAG
|
||||
BRANCH := main
|
||||
LAST_TAG := $(shell git describe --abbrev=0 --tags $(VERSION)^)
|
||||
endif
|
||||
# Make version suffix -beta.NNNN.CCCCCCCC (N=Commit number, C=Commit)
|
||||
VERSION_SUFFIX := -beta.$(shell git rev-list --count HEAD).$(shell git show --no-patch --no-notes --pretty='%h' HEAD)
|
||||
TAG_BRANCH := .$(BRANCH)
|
||||
# If building HEAD or master then unset TAG_BRANCH
|
||||
ifeq ($(subst HEAD,,$(subst master,,$(BRANCH))),)
|
||||
TAG_BRANCH :=
|
||||
endif
|
||||
# TAG is current version + commit number + commit + branch
|
||||
TAG := $(VERSION)$(VERSION_SUFFIX)$(TAG_BRANCH)
|
||||
ifdef RELEASE_TAG
|
||||
TAG := $(RELEASE_TAG)
|
||||
endif
|
||||
# end modified rclone's Makefile
|
||||
|
||||
BUILD_LDFLAGS := -s -w -X xmr-remote-nodes/internal/config.Version=$(TAG)
|
||||
|
||||
# This called from air cmd (see .air.toml)
|
||||
.PHONY: dev
|
||||
dev:
|
||||
go build -ldflags="$(BUILD_LDFLAGS)" -tags server -o ./tmp/main .
|
||||
|
||||
.PHONY: build
|
||||
build: client server
|
||||
|
||||
|
@ -9,13 +43,21 @@ ui:
|
|||
|
||||
.PHONY: client
|
||||
client:
|
||||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/${BINARY_NAME}-client-linux-amd64
|
||||
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -ldflags="-s -w" -o bin/${BINARY_NAME}-client-linux-arm64
|
||||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build \
|
||||
-ldflags="$(BUILD_LDFLAGS)" \
|
||||
-o bin/${BINARY_NAME}-client-linux-amd64
|
||||
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build \
|
||||
-ldflags="$(BUILD_LDFLAGS)" \
|
||||
-o bin/${BINARY_NAME}-client-linux-arm64
|
||||
|
||||
.PHONY: server
|
||||
server: ui
|
||||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags server -o bin/${BINARY_NAME}-server-linux-amd64
|
||||
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -ldflags="-s -w" -tags server -o bin/${BINARY_NAME}-server-linux-arm64
|
||||
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build \
|
||||
-ldflags="$(BUILD_LDFLAGS)" -tags server \
|
||||
-o bin/${BINARY_NAME}-server-linux-amd64
|
||||
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build \
|
||||
-ldflags="$(BUILD_LDFLAGS)" -tags server \
|
||||
-o bin/${BINARY_NAME}-server-linux-arm64
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
@ -26,7 +68,6 @@ clean:
|
|||
# Deploying new binary file to server and probers host
|
||||
# The deploy-* command doesn't build the binary file, so you need to run `make build` first.
|
||||
# And make sure the inventory and deploy-*.yml file is properly configured.
|
||||
|
||||
.PHONY: deploy-server
|
||||
deploy-server:
|
||||
ansible-playbook -i ./deployment/ansible/inventory.ini -l server ./deployment/ansible/deploy-server.yml -K
|
||||
|
|
|
@ -8,14 +8,12 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const AppVer = "0.0.1"
|
||||
|
||||
var configFile string
|
||||
|
||||
var Root = &cobra.Command{
|
||||
Use: "xmr-nodes",
|
||||
Short: "XMR Nodes",
|
||||
Version: AppVer,
|
||||
Version: config.Version,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
|
|
|
@ -55,7 +55,11 @@ func serve() {
|
|||
}
|
||||
|
||||
// Define Fiber config & app.
|
||||
app := fiber.New(fiberConfig())
|
||||
app := fiber.New(fiber.Config{
|
||||
Prefork: appCfg.Prefork,
|
||||
ProxyHeader: appCfg.ProxyHeader,
|
||||
AppName: "ditatompel's XMR Nodes HTTP server",
|
||||
})
|
||||
|
||||
// recover
|
||||
app.Use(recover.New(recover.Config{EnableStackTrace: true}))
|
||||
|
@ -97,11 +101,3 @@ func serve() {
|
|||
slog.Error(fmt.Sprintf("[HTTP] Server is not running! error: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func fiberConfig() fiber.Config {
|
||||
return fiber.Config{
|
||||
Prefork: config.AppCfg().Prefork,
|
||||
ProxyHeader: config.AppCfg().ProxyHeader,
|
||||
AppName: "ditatompel's XMR Nodes HTTP server",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "xmr-nodes-frontend",
|
||||
"version": "0.0.1",
|
||||
"version": "v0.0.3",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "VITE_API_URL=http://127.0.0.1:18901 vite dev --host 127.0.0.1",
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
<script>
|
||||
import { version } from '$app/environment';
|
||||
</script>
|
||||
|
||||
<div class="flex w-full items-end border-t border-surface-500/10 bg-surface-50 dark:bg-surface-900">
|
||||
<footer class="w-full">
|
||||
<div class="bg-surface-500/5">
|
||||
<div class="container mx-auto px-5 py-4">
|
||||
<!-- prettier-ignore -->
|
||||
<p class="text-center text-sm">
|
||||
XMR Nodes by <a href="https://www.ditatompel.com" class="anchor">ditatompel.com</a>,
|
||||
XMR Nodes {version} by <a href="https://www.ditatompel.com" class="anchor">ditatompel.com</a>,
|
||||
<a href="https://github.com/ditatompel/xmr-remote-nodes" class="anchor">source code</a> licensed under <strong>GLWTPL</strong>.
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -1,10 +1,53 @@
|
|||
import adapter from '@sveltejs/adapter-static';
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
import * as child_process from 'node:child_process';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
// Helper function to execute shell commands
|
||||
function execSync(cmd) {
|
||||
return child_process.execSync(cmd).toString().trim();
|
||||
}
|
||||
|
||||
// Read version from package.json
|
||||
const packageJsonPath = join(process.cwd(), 'package.json');
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
||||
const VERSION = packageJson.version;
|
||||
|
||||
// Retrieve current branch
|
||||
const BRANCH = execSync('git rev-parse --abbrev-ref HEAD');
|
||||
|
||||
// Retrieve current tag if it exists
|
||||
const RELEASE_TAG = execSync('git tag -l --points-at HEAD');
|
||||
|
||||
// Generate version suffix
|
||||
const commitCount = execSync('git rev-list --count HEAD');
|
||||
const shortCommitHash = execSync('git show --no-patch --no-notes --pretty="%h" HEAD');
|
||||
const VERSION_SUFFIX = `-beta.${commitCount}.${shortCommitHash}`;
|
||||
|
||||
// Determine branch-specific values
|
||||
let TAG_BRANCH = `.${BRANCH}`;
|
||||
|
||||
if (BRANCH === 'HEAD' || BRANCH === 'main') {
|
||||
TAG_BRANCH = '';
|
||||
}
|
||||
|
||||
// Determine final tag
|
||||
let TAG = `${VERSION}${VERSION_SUFFIX}${TAG_BRANCH}`;
|
||||
if (RELEASE_TAG) {
|
||||
TAG = RELEASE_TAG;
|
||||
TAG_BRANCH = 'main';
|
||||
}
|
||||
|
||||
console.log('Building with tag', TAG);
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
preprocess: vitePreprocess(),
|
||||
kit: {
|
||||
version: {
|
||||
name: TAG
|
||||
},
|
||||
// paths: {
|
||||
// base: '/'
|
||||
// },
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
var Version string
|
||||
|
||||
type App struct {
|
||||
// general config
|
||||
LogLevel string
|
||||
|
@ -24,6 +26,12 @@ type App struct {
|
|||
TorSOCKS string
|
||||
}
|
||||
|
||||
func init() {
|
||||
if Version == "" {
|
||||
Version = "v0.0.0-alpha.0.000000.dev"
|
||||
}
|
||||
}
|
||||
|
||||
var app = &App{}
|
||||
|
||||
func AppCfg() *App {
|
||||
|
|
Loading…
Reference in a new issue