Skip to content

Commit 84f17b4

Browse files
authored
add upx as part of building step to shrink the size of binary files (#797)
1 parent 8cff99f commit 84f17b4

File tree

8 files changed

+179
-869
lines changed

8 files changed

+179
-869
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: |
1818
sudo apt update
1919
sudo apt-get --no-install-recommends --yes install \
20-
libc6-dev-amd64-cross \
20+
upx libc6-dev-amd64-cross \
2121
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
2222
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
2323
-

.goreleaser.debug.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ builds:
2525
- linux
2626
goarch:
2727
- amd64
28-
hooks:
29-
post:
30-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
3128
- id: casaos-arm64
3229
binary: build/sysroot/usr/bin/casaos
3330
env:
@@ -44,9 +41,6 @@ builds:
4441
- linux
4542
goarch:
4643
- arm64
47-
hooks:
48-
post:
49-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
5044
- id: casaos-arm-7
5145
binary: build/sysroot/usr/bin/casaos
5246
env:
@@ -65,9 +59,6 @@ builds:
6559
- arm
6660
goarm:
6761
- "7"
68-
hooks:
69-
post:
70-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
7162
- id: casaos-migration-tool-amd64
7263
binary: build/sysroot/usr/bin/casaos-migration-tool
7364
main: ./cmd/migration-tool

.goreleaser.yaml

+30-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ before:
1111
builds:
1212
- id: casaos-amd64
1313
binary: build/sysroot/usr/bin/casaos
14+
hooks:
15+
post:
16+
- upx --best --lzma -v --no-progress "{{ .Path }}"
1417
env:
1518
- CC=x86_64-linux-gnu-gcc
1619
ldflags:
20+
- -X main.commit={{.Commit}}
21+
- -X main.date={{.Date}}
1722
- -s
1823
- -w
1924
- -extldflags "-static"
@@ -25,14 +30,16 @@ builds:
2530
- linux
2631
goarch:
2732
- amd64
28-
hooks:
29-
post:
30-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
3133
- id: casaos-arm64
3234
binary: build/sysroot/usr/bin/casaos
35+
hooks:
36+
post:
37+
- upx --best --lzma -v --no-progress "{{ .Path }}"
3338
env:
3439
- CC=aarch64-linux-gnu-gcc
3540
ldflags:
41+
- -X main.commit={{.Commit}}
42+
- -X main.date={{.Date}}
3643
- -s
3744
- -w
3845
- -extldflags "-static"
@@ -44,14 +51,16 @@ builds:
4451
- linux
4552
goarch:
4653
- arm64
47-
hooks:
48-
post:
49-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
5054
- id: casaos-arm-7
5155
binary: build/sysroot/usr/bin/casaos
56+
hooks:
57+
post:
58+
- upx --best --lzma -v --no-progress "{{ .Path }}"
5259
env:
5360
- CC=arm-linux-gnueabihf-gcc
5461
ldflags:
62+
- -X main.commit={{.Commit}}
63+
- -X main.date={{.Date}}
5564
- -s
5665
- -w
5766
- -extldflags "-static"
@@ -65,15 +74,17 @@ builds:
6574
- arm
6675
goarm:
6776
- "7"
68-
hooks:
69-
post:
70-
- find build/sysroot -type f | xargs -L 1 realpath --relative-to=build/sysroot > build/sysroot.manifest
7177
- id: casaos-migration-tool-amd64
7278
binary: build/sysroot/usr/bin/casaos-migration-tool
79+
hooks:
80+
post:
81+
- upx --best --lzma -v --no-progress "{{ .Path }}"
7382
main: ./cmd/migration-tool
7483
env:
7584
- CC=x86_64-linux-gnu-gcc
7685
ldflags:
86+
- -X main.commit={{.Commit}}
87+
- -X main.date={{.Date}}
7788
- -s
7889
- -w
7990
- -extldflags "-static"
@@ -87,10 +98,15 @@ builds:
8798
- amd64
8899
- id: casaos-migration-tool-arm64
89100
binary: build/sysroot/usr/bin/casaos-migration-tool
101+
hooks:
102+
post:
103+
- upx --best --lzma -v --no-progress "{{ .Path }}"
90104
main: ./cmd/migration-tool
91105
env:
92106
- CC=aarch64-linux-gnu-gcc
93107
ldflags:
108+
- -X main.commit={{.Commit}}
109+
- -X main.date={{.Date}}
94110
- -s
95111
- -w
96112
- -extldflags "-static"
@@ -104,10 +120,15 @@ builds:
104120
- arm64
105121
- id: casaos-migration-tool-arm-7
106122
binary: build/sysroot/usr/bin/casaos-migration-tool
123+
hooks:
124+
post:
125+
- upx --best --lzma -v --no-progress "{{ .Path }}"
107126
main: ./cmd/migration-tool
108127
env:
109128
- CC=arm-linux-gnueabihf-gcc
110129
ldflags:
130+
- -X main.commit={{.Commit}}
131+
- -X main.date={{.Date}}
111132
- -s
112133
- -w
113134
- -extldflags "-static"

cmd/migration-tool/main.go

+26-18
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
interfaces "github.com/IceWhaleTech/CasaOS-Common"
1919
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
20-
"github.com/IceWhaleTech/CasaOS-Gateway/common"
2120
"github.com/IceWhaleTech/CasaOS/pkg/config"
2221
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
2322
"github.com/IceWhaleTech/CasaOS/service"
23+
"github.com/IceWhaleTech/CasaOS/types"
2424
"gorm.io/gorm"
2525
)
2626

@@ -29,40 +29,35 @@ const (
2929
)
3030

3131
var (
32+
commit = "private build"
33+
date = "private build"
34+
3235
_logger *Logger
3336
sqliteDB *gorm.DB
34-
)
3537

36-
var (
3738
configFlag = ""
3839
dbFlag = ""
3940
)
4041

4142
func init() {
42-
config.InitSetup(configFlag)
43-
44-
if len(dbFlag) == 0 {
45-
dbFlag = config.AppInfo.DBPath + "/db"
46-
}
47-
48-
sqliteDB = sqlite.GetDb(dbFlag)
49-
// gredis.GetRedisConn(config.RedisInfo),
50-
51-
service.MyService = service.NewService(sqliteDB, "", nil)
52-
}
53-
54-
func main() {
5543
versionFlag := flag.Bool("v", false, "version")
5644
debugFlag := flag.Bool("d", true, "debug")
5745
forceFlag := flag.Bool("f", true, "force")
46+
5847
flag.Parse()
59-
_logger = NewLogger()
48+
6049
if *versionFlag {
61-
fmt.Println(common.Version)
50+
fmt.Println("v" + types.CURRENTVERSION)
6251
os.Exit(0)
6352
}
6453

54+
println("git commit:", commit)
55+
println("build date:", date)
56+
57+
_logger = NewLogger()
58+
6559
if os.Getuid() != 0 {
60+
_logger.Info("Root privileges are required to run this program.")
6661
os.Exit(1)
6762
}
6863

@@ -82,6 +77,19 @@ func main() {
8277
}
8378
}
8479

80+
config.InitSetup(configFlag)
81+
82+
if len(dbFlag) == 0 {
83+
dbFlag = config.AppInfo.DBPath + "/db"
84+
}
85+
86+
sqliteDB = sqlite.GetDb(dbFlag)
87+
// gredis.GetRedisConn(config.RedisInfo),
88+
89+
service.MyService = service.NewService(sqliteDB, "", nil)
90+
}
91+
92+
func main() {
8593
migrationTools := []interfaces.MigrationTool{
8694
// nothing to migrate from last version
8795
}

cmd/migration-tool/migration-sample.go renamed to cmd/migration-tool/migration_dummy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ func (u *migrationTool) PostMigrate() error {
5555
return nil
5656
}
5757

58-
func NewMigrationToolFor_036() interfaces.MigrationTool {
58+
func NewMigrationDummy() interfaces.MigrationTool {
5959
return &migrationTool{}
6060
}

go.mod

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,32 @@ go 1.16
55
require (
66
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d
77
github.com/IceWhaleTech/CasaOS-Common v0.4.1-alpha2
8-
github.com/IceWhaleTech/CasaOS-Gateway v0.3.6
9-
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
8+
github.com/benbjohnson/clock v1.3.0 // indirect
9+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
1010
github.com/disintegration/imaging v1.6.2
11-
github.com/dsoprea/go-exif/v3 v3.0.0-20210625224831-a6301f85c82b
12-
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
11+
github.com/dsoprea/go-exif/v3 v3.0.0-20221012082141-d21ac8e2de85
1312
github.com/gin-contrib/gzip v0.0.6
14-
github.com/gin-gonic/gin v1.8.1
15-
github.com/glebarez/sqlite v1.5.0
16-
github.com/go-ini/ini v1.62.0
13+
github.com/gin-gonic/gin v1.8.2
14+
github.com/glebarez/sqlite v1.6.0
15+
github.com/go-ini/ini v1.67.0
1716
github.com/golang/mock v1.6.0
18-
github.com/gomodule/redigo v1.8.5
17+
github.com/golang/snappy v0.0.4 // indirect
18+
github.com/gomodule/redigo v1.8.9
1919
github.com/google/go-github/v36 v36.0.0
2020
github.com/googollee/go-socket.io v1.6.2
2121
github.com/gorilla/websocket v1.5.0
2222
github.com/hirochachacha/go-smb2 v1.1.0
23+
github.com/klauspost/compress v1.15.13 // indirect
2324
github.com/mholt/archiver/v3 v3.5.1
2425
github.com/patrickmn/go-cache v2.1.0+incompatible
2526
github.com/robfig/cron v1.2.0
2627
github.com/satori/go.uuid v1.2.0
27-
github.com/shirou/gopsutil/v3 v3.22.7
28-
github.com/smartystreets/assertions v1.2.0 // indirect
29-
github.com/smartystreets/goconvey v1.6.4 // indirect
30-
github.com/stretchr/testify v1.8.0
31-
github.com/tidwall/gjson v1.10.2
32-
go.uber.org/zap v1.21.0
33-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
34-
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
35-
gorm.io/gorm v1.24.0
28+
github.com/shirou/gopsutil/v3 v3.22.11
29+
github.com/stretchr/testify v1.8.1
30+
github.com/tidwall/gjson v1.14.4
31+
go.uber.org/zap v1.24.0
32+
golang.org/x/crypto v0.4.0
33+
golang.org/x/oauth2 v0.3.0
34+
gorm.io/gorm v1.24.2
3635
gotest.tools v2.2.0+incompatible
3736
)

0 commit comments

Comments
 (0)