Skip to content

Commit

Permalink
Merge pull request #640 from 0chain/sprint-1.17
Browse files Browse the repository at this point in the history
Sprint 1.17
  • Loading branch information
dabasov authored Sep 1, 2024
2 parents 0ad9b62 + 3507632 commit bdaeee4
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/distribute-zboxcli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,22 @@ jobs:
mkdir -p ${{ env.REPO_DIR }}/pool/main/z/${{ env.APP_NAME }}/
find ${{ env.DEB_DIR }} -name "*.deb"
for deb in $(find ${{ env.DEB_DIR }} -name "*.deb"); do
cp $deb ${{ env.REPO_DIR }}/pool/main/z/${{ env.APP_NAME }}/
cp -u $deb ${{ env.REPO_DIR }}/pool/main/z/${{ env.APP_NAME }}/
done
- name: Update APT repo
run: |
cd ${{ env.REPO_DIR }}
for dist in ${{ env.DISTRIBUTIONS }}; do
rm -rf dists/${dist}
mkdir -p dists/${dist}
for arch in ${{ env.ARCHITECTURES }}; do
mkdir -p dists/${dist}/main/binary-${arch}
find "pool/main/z/${{ env.APP_NAME }}" -type f -name "${{ env.APP_NAME }}_*~${dist}_${arch}.deb" | \
xargs -I {} apt-ftparchive -o Tree::dists/${dist}::Sections="main" \
-o Tree::dists/${dist}::Architectures="${arch}" \
-o Dir::ArchiveDir="${{ env.REPO_DIR }}" \
packages {} > dists/${dist}/main/binary-${arch}/Packages
packages {} >> dists/${dist}/main/binary-${arch}/Packages
done
apt-ftparchive -o APT::FTPArchive::Release::Origin="${{ env.APP_NAME }}" \
Expand Down
120 changes: 104 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
description: 'Create release as draft'
required: false
default: 'true'
prerelease:
description: 'Create release as prerelease'
required: false
default: 'false'

env:
GITHUB_TOKEN: ${{ secrets.GOSDK }}
Expand All @@ -22,8 +26,26 @@ env:
GO_VERSION: 1.21

jobs:
create_release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.id }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag }}
release_name: ${{ github.event.inputs.tag }}
draft: ${{ github.event.inputs.draft }}
prerelease: ${{ github.event.inputs.prerelease }}

linux:
runs-on: ubuntu-latest
needs: create_release
env:
SRC_DIR: ${{ github.workspace }}/src
OUTPUT_DIR: ${{ github.workspace }}/output
Expand All @@ -44,6 +66,7 @@ jobs:
- name: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}
- name: Build Docker image for linux/amd64
run: |
Expand All @@ -66,7 +89,7 @@ jobs:
- name: Create Zip File for linux/amd64
run: |
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-amd64.zip ${{ env.APP_NAME }}
zip -qq -r ${{ env.APP_NAME }}-linux-amd64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/amd64
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -95,31 +118,20 @@ jobs:
- name: Create Zip File for linux/arm64
run: |
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-arm64.zip ${{ env.APP_NAME }}
zip -qq -r ${{ env.APP_NAME }}-linux-arm64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-linux-arm64
path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-arm64.zip

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag }}
release_name: ${{ github.event.inputs.tag }}
draft: ${{ github.event.inputs.draft }}
prerelease: false

- name: Upload Release Asset for Linux/amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-amd64.zip
asset_name: ${{ env.APP_NAME }}-linux-amd64.zip
asset_content_type: application/zip
Expand All @@ -129,7 +141,83 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-arm64.zip
asset_name: ${{ env.APP_NAME }}-linux-arm64.zip
asset_content_type: application/zip
asset_content_type: application/zip

darwin:
runs-on: macos-latest
needs: create_release
env:
SRC_DIR: ${{ github.workspace }}/src
OUTPUT_DIR: ${{ github.workspace }}/output
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ env.SRC_DIR }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}/amd64
mkdir -p ${{ env.OUTPUT_DIR }}/arm64
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/amd64/
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/arm64/
- name: Build ${{ env.APP_NAME }} for arm64
run: |
cd ${{ env.SRC_DIR }}
CGO_ENABLED=1 CGO_CFLAGS="-mmacosx-version-min=12.0" CGO_LDFLAGS="-mmacosx-version-min=12.0" GOOS=darwin GOARCH=arm64 SDKROOT=$(xcrun --sdk macosx --show-sdk-path) go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.VERSION }}" -o ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }} .
- name: Build ${{ env.APP_NAME }} for amd64
run: |
cd ${{ env.SRC_DIR }}
CGO_ENABLED=1 CGO_CFLAGS="-mmacosx-version-min=12.0" CGO_LDFLAGS="-mmacosx-version-min=12.0" GOOS=darwin GOARCH=amd64 SDKROOT=$(xcrun --sdk macosx --show-sdk-path) go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.VERSION }}" -o ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }} .
- name: Create Zip File for darwin/amd64
run: |
cd ${{ env.OUTPUT_DIR }}/amd64
zip -qq -r ${{ env.APP_NAME }}-darwin-amd64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-amd64
path: ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }}-darwin-amd64.zip

- name: Create Zip File for darwin/arm64
run: |
cd ${{ env.OUTPUT_DIR }}/arm64
zip -qq -r ${{ env.APP_NAME }}-darwin-arm64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-arm64
path: ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }}-darwin-arm64.zip

- name: Upload Release Asset for Darwin/amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }}-darwin-amd64.zip
asset_name: ${{ env.APP_NAME }}-darwin-amd64.zip
asset_content_type: application/zip

- name: Upload Release Asset for Darwin/arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }}-darwin-arm64.zip
asset_name: ${{ env.APP_NAME }}-darwin-arm64.zip
asset_content_type: application/zip
2 changes: 1 addition & 1 deletion network/config.yaml → cmd/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
block_worker: https://demo.zus.network/dns
block_worker: https://mainnet.zus.network/dns
signature_scheme: bls0chain
min_submit: 50
min_confirmation: 50
Expand Down
5 changes: 4 additions & 1 deletion cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ var newallocationCmd = &cobra.Command{
}

thirdPartyExtendable, _ := flags.GetBool("third_party_extendable")
isEnterprise, _ := flags.GetBool("enterprise")
force, _ := flags.GetBool("force")

// Read the file options flags
Expand Down Expand Up @@ -256,6 +257,7 @@ var newallocationCmd = &cobra.Command{
FileOptionsParams: &fileOptionParams,
ThirdPartyExtendable: thirdPartyExtendable,
Force: force,
IsEnterprise: isEnterprise,
}
allocationID, _, _, err = sdk.CreateAllocationWith(options)
if err != nil {
Expand All @@ -273,7 +275,7 @@ var newallocationCmd = &cobra.Command{
}

allocationID, _, _, err = sdk.CreateAllocationForOwner(owner, ownerPublicKey, *datashards, *parityshards,
*size, readPrice, writePrice, lock, preferred_blobbers, blobber_auth_tickets, thirdPartyExtendable, force, &fileOptionParams)
*size, readPrice, writePrice, lock, preferred_blobbers, blobber_auth_tickets, thirdPartyExtendable, isEnterprise, force, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand Down Expand Up @@ -346,6 +348,7 @@ func init() {

newallocationCmd.Flags().Bool("force", false, "(default false) force to get blobbers even if required number of blobbers are not available (should be passed true in case of restricted blobbers)")
newallocationCmd.Flags().Bool("third_party_extendable", false, "(default false) specify if the allocation can be extended by users other than the owner")
newallocationCmd.Flags().Bool("enterprise", false, "(default false) specify if the allocation is for enterprise")
newallocationCmd.Flags().Bool("forbid_upload", false, "(default false) specify if users cannot upload to this allocation")
newallocationCmd.Flags().Bool("forbid_delete", false, "(default false) specify if the users cannot delete objects from this allocation")
newallocationCmd.Flags().Bool("forbid_update", false, "(default false) specify if the users cannot update objects in this allocation")
Expand Down
28 changes: 27 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package cmd

import (
_ "embed"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/logger"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/0chain/gosdk/zboxcore/blockchain"
"github.com/0chain/zboxcli/util"
Expand All @@ -34,6 +37,9 @@ var allocUnderRepair bool

var walletJSON string

//go:embed config.yaml
var configStr string

var rootCmd = &cobra.Command{
Use: "zbox",
Short: "zbox is a decentralized storage application written on the 0Chain platform",
Expand Down Expand Up @@ -77,7 +83,20 @@ func initConfig() {
cfg, err := conf.LoadConfigFile(filepath.Join(configDir, cfgFile))
if err != nil {
fmt.Println("Can't read config:", err)
os.Exit(1)
fmt.Println("using default config")
fmt.Printf("config: %v", configStr)
v := viper.New()
v.SetConfigType("yaml")
err := v.ReadConfig(strings.NewReader(configStr))
if err != nil {
fmt.Println("error reading default config:", err)
os.Exit(1)
}
cfg, err = conf.LoadConfig(v)
if err != nil {
fmt.Println("error loading default config:", err)
os.Exit(1)
}
}

if networkFile == "" {
Expand Down Expand Up @@ -192,6 +211,13 @@ func initConfig() {
os.Exit(1)
}

// set wallet info along whether split key is used
err = zcncore.SetWalletInfo(walletJSON, false)
if err != nil {
fmt.Println("Error in wallet info initialization", err)
os.Exit(1)
}

// additional settings depending network latency
blockchain.SetMaxTxnQuery(cfg.MaxTxnQuery)
blockchain.SetQuerySleepTime(cfg.QuerySleepTime)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ go 1.21

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.16.5
github.com/0chain/gosdk v1.17.0-RC1
github.com/icza/bitio v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
)

Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565 h1:z+DtCR8mBsjPnEs
github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565/go.mod h1:UyDC8Qyl5z9lGkCnf9RHJPMektnFX8XtCJZHXCCVj8E=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.16.5 h1:EGtndZLj5+m8OAIzfAfjqu4llEolWuxgKQxXS0tfe7Q=
github.com/0chain/gosdk v1.16.5/go.mod h1:y7Ucdmv40VltqulZnncMNjNQ4piX5Dta5ujNmPmXnxg=
github.com/0chain/gosdk v1.17.0-RC1 h1:D3OwgmfkqW/2FR+JtjmDx+KhlCINXL5/ZWNMbbPh4lc=
github.com/0chain/gosdk v1.17.0-RC1/go.mod h1:y7Ucdmv40VltqulZnncMNjNQ4piX5Dta5ujNmPmXnxg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw=
Expand Down
2 changes: 1 addition & 1 deletion scripts/debian/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ COPY go.mod go.sum .
RUN go mod download
COPY . .
RUN go env
RUN CGO_ENABLED=1 go build -x -v -tags bn256 -ldflags "-X main.VersionStr=${VERSION} -linkmode 'external' -extldflags '-static'" -o /zbox .
RUN CGO_ENABLED=1 go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${VERSION} -linkmode 'external' -extldflags '-static'" -o /zbox .

0 comments on commit bdaeee4

Please sign in to comment.