Skip to content

Commit

Permalink
Tame agent size (#72)
Browse files Browse the repository at this point in the history
I've noticed the build started to take longer recently... and [found the
culpid](#17 (comment))
(thanks `git bisect`):
30ad492
balooned the agent size.

I'm not totally sure why that is, as I'd expect the go compiler to not
include all non-used symbols in the agent package, but... I've also read
some coments on "if you use reflect all bets are off", so... ¯\_(ツ)_/¯

Whatever the case... let's rollback the change, and get back to tame
levels.

I've also added a check on CI, to prevent agent size from balooning
without notice again.

Closes #17.
  • Loading branch information
fornellas authored Aug 14, 2024
1 parent bcd0687 commit 0a46cf1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ else
GO_BUILD_AGENT_GOARCHS := $(GOARCH)
endif

GO_BUILD_MAX_AGENT_SIZE := 5242880

##
## rrb
##
Expand Down Expand Up @@ -427,13 +429,16 @@ help: build-help

.PHONY: build-agent-%
build-agent-%: go-generate
set -e
GOARCH=$* GOOS=linux $(GO) \
build \
-o internal/host/agent_server/agent_server_linux_$* \
$(GO_BUILD_FLAGS_COMMON) \
$(GO_BUILD_FLAGS) \
./internal/host/agent_server/
gzip < internal/host/agent_server/agent_server_linux_$* > internal/host/agent_server/agent_server_linux_$*.gz
if ! size=$$(stat -f %z internal/host/agent_server/agent_server_linux_$*.gz 2>/dev/null) ; then size=$$(stat --printf=%s internal/host/agent_server/agent_server_linux_$*.gz) ; fi
[ "$$size" -gt $(GO_BUILD_MAX_AGENT_SIZE) ] && { echo "Compressed agent size exceeds $(GO_BUILD_MAX_AGENT_SIZE) bytes" ; exit 1 ; }
cat << EOF > internal/host/agent_server_linux_$*_gz.go
package host
import _ "embed"
Expand Down
4 changes: 2 additions & 2 deletions internal/host/agent_server/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"gopkg.in/yaml.v3"

"github.com/fornellas/resonance/host"
iHost "github.com/fornellas/resonance/internal/host"
"github.com/fornellas/resonance/internal/host/agent_server/api"
aNet "github.com/fornellas/resonance/internal/host/agent_server/net"
"github.com/fornellas/resonance/internal/host/local_run"
)

func internalServerError(w http.ResponseWriter, err error) {
Expand Down Expand Up @@ -267,7 +267,7 @@ func PostRunFn(ctx context.Context) func(http.ResponseWriter, *http.Request) {
Stderr: stderrBuff,
}

waitStatus, err := iHost.LocalRun(ctx, cmd)
waitStatus, err := local_run.Run(ctx, cmd)
if err != nil {
internalServerError(w, err)
return
Expand Down
3 changes: 2 additions & 1 deletion internal/host/local_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall"

"github.com/fornellas/resonance/host"
"github.com/fornellas/resonance/internal/host/local_run"
"github.com/fornellas/resonance/log"
)

Expand Down Expand Up @@ -78,7 +79,7 @@ func (l Local) Remove(ctx context.Context, name string) error {
func (l Local) Run(ctx context.Context, cmd host.Cmd) (host.WaitStatus, error) {
logger := log.MustLogger(ctx)
logger.Debug("Run", "cmd", cmd)
return LocalRun(ctx, cmd)
return local_run.Run(ctx, cmd)
}

func (l Local) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package host
package local_run

import (
"context"
Expand All @@ -11,7 +11,7 @@ import (
)

// Implements Host.Run for unix locahost.
func LocalRun(ctx context.Context, cmd host.Cmd) (host.WaitStatus, error) {
func Run(ctx context.Context, cmd host.Cmd) (host.WaitStatus, error) {
execCmd := exec.CommandContext(ctx, cmd.Path, cmd.Args...)
if len(cmd.Env) == 0 {
cmd.Env = []string{"LANG=en_US.UTF-8"}
Expand Down

0 comments on commit 0a46cf1

Please sign in to comment.