Skip to content

Commit

Permalink
syz-ci: introduce gitArchive parameters
Browse files Browse the repository at this point in the history
Some commits don't live long remotely.
It sometimes happens we need them later to:
1. Merge coverage.
2. Mention during communication.
  • Loading branch information
tarasmadan committed Oct 7, 2024
1 parent a4c7fd3 commit 1b61881
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/vcs/fuchsia.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ func (ctx *fuchsia) MergeBases(firstCommit, secondCommit string) ([]*Commit, err
func (ctx *fuchsia) CommitExists(string) (bool, error) {
return false, fmt.Errorf("not implemented for fuchsia")
}

func (ctx *fuchsia) ArchiveHeadCommit(repo, commit string) error {
return ctx.repo.ArchiveHeadCommit(repo, commit)
}
10 changes: 10 additions & 0 deletions pkg/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,13 @@ func (git *git) CommitExists(commit string) (bool, error) {
}
return true, nil
}

func (git *git) ArchiveHeadCommit(repo, commit string) error {
tagName := "tag-" + commit
git.git("remote", "add", "syz-gitarchive", repo) // ignore errors on re-adding
git.git("tag", tagName) // ignore errors on re-tagging
if _, err := git.git("push", "syz-gitarchive", tagName); err != nil {
return fmt.Errorf("git push syz-gitarchive %s: %w", tagName, err)
}
return nil
}
3 changes: 3 additions & 0 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type Repo interface {

// CommitExists check for the commit presence in local checkout.
CommitExists(commit string) (bool, error)

// ArchiveHeadCommit is used to store commits elsewhere.
ArchiveHeadCommit(repo, commit string) error
}

// Bisecter may be optionally implemented by Repo.
Expand Down
15 changes: 14 additions & 1 deletion syz-ci/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ loop:
log.Logf(0, "%v: stopped", mgr.name)
}

func (mgr *Manager) archiveHeadCommit(headCommit string) {
if mgr.cfg.GitArchive == "" || mgr.mgrcfg.DisableGitArchive {
return
}
log.Logf(0, "%v: archiving commit %s", mgr.name, headCommit)
if err := mgr.repo.ArchiveHeadCommit(mgr.cfg.GitArchive, headCommit); err != nil {
log.Logf(0, "%v: failed to archive commit %s from repo %s: %s",
mgr.name, headCommit, mgr.mgrcfg.Repo, err.Error())
}
}

func (mgr *Manager) pollAndBuild(lastCommit string, latestInfo *BuildInfo) (
string, *BuildInfo, time.Duration) {
rebuildAfter := buildRetryPeriod
Expand All @@ -277,7 +288,9 @@ func (mgr *Manager) pollAndBuild(lastCommit string, latestInfo *BuildInfo) (
if err := mgr.build(commit); err != nil {
log.Logf(0, "%v: %v", mgr.name, err)
} else {
log.Logf(0, "%v: build successful, [re]starting manager", mgr.name)
log.Logf(0, "%v: build successful", mgr.name)
mgr.archiveHeadCommit(lastCommit)
log.Logf(0, "%v: [re]starting manager", mgr.name)
mgr.buildFailed = false
rebuildAfter = kernelRebuildPeriod
latestInfo = mgr.checkLatest()
Expand Down
6 changes: 6 additions & 0 deletions syz-ci/syz-ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type Config struct {
// Per-vm type JSON diffs that will be applied to every instace of the
// corresponding VM type.
PatchVMConfigs map[string]json.RawMessage `json:"patch_vm_configs"`
// Some commits don't live long. Cache them somewhere to increase lifetime.
// The cache is used by coverage merger.
GitArchive string `json:"git_archive"`
}

type ManagerConfig struct {
Expand Down Expand Up @@ -210,6 +213,9 @@ type ManagerConfig struct {
BisectBackports []vcs.BackportCommit `json:"bisect_backports"`
// Base syz-manager config for the instance.
ManagerConfig json.RawMessage `json:"manager_config"`
// By default we want to archive git commits.
// This opt-out is needed for *BSD systems.
DisableGitArchive bool `json:"disable_git_archive"`
// If the kernel's commit is older than MaxKernelLagDays days,
// fuzzing won't be started on this instance.
// By default it's 30 days.
Expand Down
8 changes: 8 additions & 0 deletions tools/docker/syzbot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ RUN test "$(uname -m)" != x86_64 && exit 0 || \
qemu-utils qemu-system-misc qemu-system-x86 qemu-system-arm qemu-system-aarch64 \
qemu-system-s390x qemu-system-mips qemu-system-ppc

# Install gcloud https://cloud.google.com/sdk/docs/install#deb.
RUN apt-get install -y -q apt-transport-https ca-certificates gnupg curl
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
RUN apt-get update
RUN apt-get install -y google-cloud-cli
RUN git config --global credential.'https://*.*.sourcemanager.dev'.helper gcloud.sh

# pkg/osutil uses syzkaller user for sandboxing.
RUN useradd --create-home syzkaller
RUN echo "export PS1='\n\W🤖 '" >> /root/.bashrc
Expand Down

0 comments on commit 1b61881

Please sign in to comment.