Skip to content

Commit

Permalink
osbuildexecutor: write the job-id intro control.json
Browse files Browse the repository at this point in the history
Set the jobID into control.json so that the osbuild-worker-executor
can set the hostname based on the jobID.
  • Loading branch information
mvo5 committed Jun 14, 2024
1 parent aa3d70a commit c13d37c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/osbuildexecutor/runner-impl-aws-ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ func waitForSI(ctx context.Context, host string) bool {
}
}

func writeInputArchive(cacheDir, store string, exports []string, manifestData []byte) (string, error) {
func writeInputArchive(cacheDir, store, jobID string, exports []string, manifestData []byte) (string, error) {
archive := filepath.Join(cacheDir, "input.tar")
control := filepath.Join(cacheDir, "control.json")
manifest := filepath.Join(cacheDir, "manifest.json")

controlData := struct {
Exports []string `json:"exports"`
JobID string `json:"job-id"`
}{
Exports: exports,
JobID: jobID,
}
controlDataBytes, err := json.Marshal(controlData)
if err != nil {
Expand Down Expand Up @@ -287,7 +289,7 @@ func (ec2e *awsEC2Executor) RunOSBuild(manifest []byte, opts *OsbuildOpts, error
return nil, fmt.Errorf("Timeout waiting for executor to come online")
}

inputArchive, err := writeInputArchive(ec2e.tmpDir, opts.StoreDir, opts.Exports, manifest)
inputArchive, err := writeInputArchive(ec2e.tmpDir, opts.StoreDir, opts.JobID, opts.Exports, manifest)
if err != nil {
logrus.Errorf("Unable to write input archive: %v", err)
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion internal/osbuildexecutor/runner-impl-aws-ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestWriteInputArchive(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "contents"), []byte("storedata"), 0600))
require.NoError(t, os.WriteFile(filepath.Join(storeSubDir, "contents"), []byte("storedata"), 0600))

archive, err := osbuildexecutor.WriteInputArchive(cacheDir, storeDir, []string{"image"}, []byte("{\"version\": 2}"))
archive, err := osbuildexecutor.WriteInputArchive(cacheDir, storeDir, "some-job-id", []string{"image"}, []byte("{\"version\": 2}"))
require.NoError(t, err)

cmd := exec.Command("tar",
Expand All @@ -64,6 +64,10 @@ func TestWriteInputArchive(t *testing.T) {
"store/contents",
"",
}, strings.Split(string(out), "\n"))

output, err := exec.Command("tar", "xOf", archive, "control.json").CombinedOutput()
require.NoError(t, err)
require.Equal(t, `{"exports":["image"],"job-id":"some-job-id"}`, string(output))
}

func TestHandleBuild(t *testing.T) {
Expand Down

0 comments on commit c13d37c

Please sign in to comment.