From 819596cb1fcbf33d992c855757839c7aea15bc7d Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Sat, 20 Aug 2022 22:19:09 +0200 Subject: [PATCH] Enable arm64 and MacOS Docker build --- build/templates/backend/debian/control | 2 +- build/templates/blockbook/debian/control | 2 +- build/tools/image_status.sh | 6 +-- build/tools/templates.go | 66 ++++++++++++++++-------- configs/coins/bitcoin_regtest.json | 6 +++ 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/build/templates/backend/debian/control b/build/templates/backend/debian/control index 4093b52e..cdc74d4e 100644 --- a/build/templates/backend/debian/control +++ b/build/templates/backend/debian/control @@ -7,7 +7,7 @@ Build-Depends: debhelper, wget, tar, gzip, make, dh-exec Standards-Version: 3.9.5 Package: {{.Backend.PackageName}} -Architecture: amd64 +Architecture: {{.Env.Architecture}} Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate Description: Satoshilabs packaged {{.Coin.Name}} server {{end}} diff --git a/build/templates/blockbook/debian/control b/build/templates/blockbook/debian/control index c269337b..e596de01 100644 --- a/build/templates/blockbook/debian/control +++ b/build/templates/blockbook/debian/control @@ -7,7 +7,7 @@ Build-Depends: debhelper, dh-exec Standards-Version: 3.9.5 Package: {{.Blockbook.PackageName}} -Architecture: amd64 +Architecture: {{.Env.Architecture}} Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, {{.Backend.PackageName}} Description: Satoshilabs blockbook server ({{.Coin.Name}}) {{end}} diff --git a/build/tools/image_status.sh b/build/tools/image_status.sh index 5c4397b7..c8dc4283 100755 --- a/build/tools/image_status.sh +++ b/build/tools/image_status.sh @@ -16,10 +16,10 @@ if [ -z "$IMG_CREATED_TIME" ]; then exit 0 fi -IMG_CREATED_TS=$(date -d $IMG_CREATED_TIME +%s) -GIT_COMMIT_TS=$(date -d $(git log --pretty="format:%cI" -1 $DIR) +%s) +IMG_CREATED_TS=$IMG_CREATED_TIME +GIT_COMMIT_TS=$(git log --pretty="format:%cI" -1 $DIR) -if [ $IMG_CREATED_TS -lt $GIT_COMMIT_TS ]; then +if [[ "$IMG_CREATED_TS" < "$GIT_COMMIT_TS" ]]; then echo "out-of-time" else echo "ok" diff --git a/build/tools/templates.go b/build/tools/templates.go index 5612c522..13f1d5c7 100644 --- a/build/tools/templates.go +++ b/build/tools/templates.go @@ -8,10 +8,36 @@ import ( "os" "os/exec" "path/filepath" + "reflect" + "runtime" "text/template" "time" ) +// Backend contains backend specific fields +type Backend struct { + PackageName string `json:"package_name"` + PackageRevision string `json:"package_revision"` + SystemUser string `json:"system_user"` + Version string `json:"version"` + BinaryURL string `json:"binary_url"` + VerificationType string `json:"verification_type"` + VerificationSource string `json:"verification_source"` + ExtractCommand string `json:"extract_command"` + ExcludeFiles []string `json:"exclude_files"` + ExecCommandTemplate string `json:"exec_command_template"` + LogrotateFilesTemplate string `json:"logrotate_files_template"` + PostinstScriptTemplate string `json:"postinst_script_template"` + ServiceType string `json:"service_type"` + ServiceAdditionalParamsTemplate string `json:"service_additional_params_template"` + ProtectMemory bool `json:"protect_memory"` + Mainnet bool `json:"mainnet"` + ServerConfigFile string `json:"server_config_file"` + ClientConfigFile string `json:"client_config_file"` + AdditionalParams interface{} `json:"additional_params,omitempty"` + Platforms map[string]Backend `json:"platforms,omitempty"` +} + // Config contains the structure of the config type Config struct { Coin struct { @@ -33,27 +59,7 @@ type Config struct { RPCTimeout int `json:"rpc_timeout"` MessageQueueBindingTemplate string `json:"message_queue_binding_template"` } `json:"ipc"` - Backend struct { - PackageName string `json:"package_name"` - PackageRevision string `json:"package_revision"` - SystemUser string `json:"system_user"` - Version string `json:"version"` - BinaryURL string `json:"binary_url"` - VerificationType string `json:"verification_type"` - VerificationSource string `json:"verification_source"` - ExtractCommand string `json:"extract_command"` - ExcludeFiles []string `json:"exclude_files"` - ExecCommandTemplate string `json:"exec_command_template"` - LogrotateFilesTemplate string `json:"logrotate_files_template"` - PostinstScriptTemplate string `json:"postinst_script_template"` - ServiceType string `json:"service_type"` - ServiceAdditionalParamsTemplate string `json:"service_additional_params_template"` - ProtectMemory bool `json:"protect_memory"` - Mainnet bool `json:"mainnet"` - ServerConfigFile string `json:"server_config_file"` - ClientConfigFile string `json:"client_config_file"` - AdditionalParams interface{} `json:"additional_params,omitempty"` - } `json:"backend"` + Backend Backend `json:"backend"` Blockbook struct { PackageName string `json:"package_name"` SystemUser string `json:"system_user"` @@ -87,6 +93,7 @@ type Config struct { BackendDataPath string `json:"backend_data_path"` BlockbookInstallPath string `json:"blockbook_install_path"` BlockbookDataPath string `json:"blockbook_data_path"` + Architecture string `json:"architecture"` } `json:"-"` } @@ -136,6 +143,16 @@ func (c *Config) ParseTemplate() *template.Template { return t } +func copyNonZeroBackendFields(toValue *Backend, fromValue *Backend) { + from := reflect.ValueOf(*fromValue) + to := reflect.ValueOf(toValue).Elem() + for i := 0; i < from.NumField(); i++ { + if from.Field(i).IsValid() && !from.Field(i).IsZero() { + to.Field(i).Set(from.Field(i)) + } + } +} + // LoadConfig loads the config files func LoadConfig(configsDir, coin string) (*Config, error) { config := new(Config) @@ -161,8 +178,15 @@ func LoadConfig(configsDir, coin string) (*Config, error) { } config.Meta.BuildDatetime = time.Now().Format("Mon, 02 Jan 2006 15:04:05 -0700") + config.Env.Architecture = runtime.GOARCH if !isEmpty(config, "backend") { + // set platform specific fields to config + platform, found := config.Backend.Platforms[runtime.GOARCH] + if found { + copyNonZeroBackendFields(&config.Backend, &platform) + } + switch config.Backend.ServiceType { case "forking": case "simple": diff --git a/configs/coins/bitcoin_regtest.json b/configs/coins/bitcoin_regtest.json index dd025911..45ebef2f 100644 --- a/configs/coins/bitcoin_regtest.json +++ b/configs/coins/bitcoin_regtest.json @@ -41,6 +41,12 @@ "client_config_file": "bitcoin_client.conf", "additional_params": { "deprecatedrpc": "estimatefee" + }, + "platforms": { + "arm64": { + "binary_url": "https://bitcoincore.org/bin/bitcoin-core-23.0/bitcoin-23.0-aarch64-linux-gnu.tar.gz", + "verification_source": "06f4c78271a77752ba5990d60d81b1751507f77efda1e5981b4e92fd4d9969fb" + } } }, "blockbook": {