Skip to content

Commit

Permalink
add upx as part of building step to shrink the size of binary files (
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerinus authored Dec 29, 2022
1 parent 8cff99f commit 84f17b4
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 869 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
sudo apt update
sudo apt-get --no-install-recommends --yes install \
libc6-dev-amd64-cross \
upx libc6-dev-amd64-cross \
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
-
Expand Down
9 changes: 0 additions & 9 deletions .goreleaser.debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ builds:
- linux
goarch:
- amd64
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-arm64
binary: build/sysroot/usr/bin/casaos
env:
Expand All @@ -44,9 +41,6 @@ builds:
- linux
goarch:
- arm64
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-arm-7
binary: build/sysroot/usr/bin/casaos
env:
Expand All @@ -65,9 +59,6 @@ builds:
- arm
goarm:
- "7"
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-migration-tool-amd64
binary: build/sysroot/usr/bin/casaos-migration-tool
main: ./cmd/migration-tool
Expand Down
39 changes: 30 additions & 9 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ before:
builds:
- id: casaos-amd64
binary: build/sysroot/usr/bin/casaos
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
env:
- CC=x86_64-linux-gnu-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand All @@ -25,14 +30,16 @@ builds:
- linux
goarch:
- amd64
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-arm64
binary: build/sysroot/usr/bin/casaos
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
env:
- CC=aarch64-linux-gnu-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand All @@ -44,14 +51,16 @@ builds:
- linux
goarch:
- arm64
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-arm-7
binary: build/sysroot/usr/bin/casaos
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
env:
- CC=arm-linux-gnueabihf-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand All @@ -65,15 +74,17 @@ builds:
- arm
goarm:
- "7"
hooks:
post:
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
- id: casaos-migration-tool-amd64
binary: build/sysroot/usr/bin/casaos-migration-tool
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
main: ./cmd/migration-tool
env:
- CC=x86_64-linux-gnu-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand All @@ -87,10 +98,15 @@ builds:
- amd64
- id: casaos-migration-tool-arm64
binary: build/sysroot/usr/bin/casaos-migration-tool
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
main: ./cmd/migration-tool
env:
- CC=aarch64-linux-gnu-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand All @@ -104,10 +120,15 @@ builds:
- arm64
- id: casaos-migration-tool-arm-7
binary: build/sysroot/usr/bin/casaos-migration-tool
hooks:
post:
- upx --best --lzma -v --no-progress "{{ .Path }}"
main: ./cmd/migration-tool
env:
- CC=arm-linux-gnueabihf-gcc
ldflags:
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -s
- -w
- -extldflags "-static"
Expand Down
44 changes: 26 additions & 18 deletions cmd/migration-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (

interfaces "github.com/IceWhaleTech/CasaOS-Common"
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
"github.com/IceWhaleTech/CasaOS-Gateway/common"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/IceWhaleTech/CasaOS/types"
"gorm.io/gorm"
)

Expand All @@ -29,40 +29,35 @@ const (
)

var (
commit = "private build"
date = "private build"

_logger *Logger
sqliteDB *gorm.DB
)

var (
configFlag = ""
dbFlag = ""
)

func init() {
config.InitSetup(configFlag)

if len(dbFlag) == 0 {
dbFlag = config.AppInfo.DBPath + "/db"
}

sqliteDB = sqlite.GetDb(dbFlag)
// gredis.GetRedisConn(config.RedisInfo),

service.MyService = service.NewService(sqliteDB, "", nil)
}

func main() {
versionFlag := flag.Bool("v", false, "version")
debugFlag := flag.Bool("d", true, "debug")
forceFlag := flag.Bool("f", true, "force")

flag.Parse()
_logger = NewLogger()

if *versionFlag {
fmt.Println(common.Version)
fmt.Println("v" + types.CURRENTVERSION)
os.Exit(0)
}

println("git commit:", commit)
println("build date:", date)

_logger = NewLogger()

if os.Getuid() != 0 {
_logger.Info("Root privileges are required to run this program.")
os.Exit(1)
}

Expand All @@ -82,6 +77,19 @@ func main() {
}
}

config.InitSetup(configFlag)

if len(dbFlag) == 0 {
dbFlag = config.AppInfo.DBPath + "/db"
}

sqliteDB = sqlite.GetDb(dbFlag)
// gredis.GetRedisConn(config.RedisInfo),

service.MyService = service.NewService(sqliteDB, "", nil)
}

func main() {
migrationTools := []interfaces.MigrationTool{
// nothing to migrate from last version
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ func (u *migrationTool) PostMigrate() error {
return nil
}

func NewMigrationToolFor_036() interfaces.MigrationTool {
func NewMigrationDummy() interfaces.MigrationTool {
return &migrationTool{}
}
33 changes: 16 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@ go 1.16
require (
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d
github.com/IceWhaleTech/CasaOS-Common v0.4.1-alpha2
github.com/IceWhaleTech/CasaOS-Gateway v0.3.6
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/disintegration/imaging v1.6.2
github.com/dsoprea/go-exif/v3 v3.0.0-20210625224831-a6301f85c82b
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
github.com/dsoprea/go-exif/v3 v3.0.0-20221012082141-d21ac8e2de85
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.8.1
github.com/glebarez/sqlite v1.5.0
github.com/go-ini/ini v1.62.0
github.com/gin-gonic/gin v1.8.2
github.com/glebarez/sqlite v1.6.0
github.com/go-ini/ini v1.67.0
github.com/golang/mock v1.6.0
github.com/gomodule/redigo v1.8.5
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v1.8.9
github.com/google/go-github/v36 v36.0.0
github.com/googollee/go-socket.io v1.6.2
github.com/gorilla/websocket v1.5.0
github.com/hirochachacha/go-smb2 v1.1.0
github.com/klauspost/compress v1.15.13 // indirect
github.com/mholt/archiver/v3 v3.5.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil/v3 v3.22.7
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.10.2
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
gorm.io/gorm v1.24.0
github.com/shirou/gopsutil/v3 v3.22.11
github.com/stretchr/testify v1.8.1
github.com/tidwall/gjson v1.14.4
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.4.0
golang.org/x/oauth2 v0.3.0
gorm.io/gorm v1.24.2
gotest.tools v2.2.0+incompatible
)
Loading

0 comments on commit 84f17b4

Please sign in to comment.