osbuild-worker: don't use /var/cache for temporary directories
When osbuild-composer crashed, it left temporary directories in `/var/cache`. Use `/var/tmp` for these output directories, because systemd will clean these up (we set PrivateTmp=true). Also, put the store into `/var/cache/osbuild-store`. The worker does not checkpoint anything. The store is only used as a cache for rpms. That can be shared between multiple workers and successive runs of a single worker.
This commit is contained in:
parent
89117ebf3a
commit
33a4c55a6f
1 changed files with 13 additions and 15 deletions
|
|
@ -63,9 +63,17 @@ func (e *TargetsError) Error() string {
|
||||||
return errString
|
return errString
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunJob(job *worker.Job, cacheDir string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*common.ComposeResult, error) {
|
func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*common.ComposeResult, error) {
|
||||||
outputDirectory := path.Join(cacheDir, "output")
|
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-worker-*")
|
||||||
store := path.Join(cacheDir, "store")
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating temporary output directory: %v", err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
err := os.RemoveAll(outputDirectory)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error removing temporary output directory (%s): %v", outputDirectory, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
result, err := RunOSBuild(job.Manifest, store, outputDirectory, os.Stderr)
|
result, err := RunOSBuild(job.Manifest, store, outputDirectory, os.Stderr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -174,6 +182,7 @@ func main() {
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
log.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
||||||
}
|
}
|
||||||
|
store := path.Join(cacheDirectory, "osbuild-store")
|
||||||
|
|
||||||
var client *worker.Client
|
var client *worker.Client
|
||||||
if unix {
|
if unix {
|
||||||
|
|
@ -191,17 +200,6 @@ func main() {
|
||||||
client = worker.NewClient(address, conf)
|
client = worker.NewClient(address, conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir(cacheDirectory, "osbuild-worker-*")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error setting up osbuild output directory: %v", err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err := os.RemoveAll(tmpdir)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error removing osbuild-worker cache (%s): %v", tmpdir, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Println("Waiting for a new job...")
|
fmt.Println("Waiting for a new job...")
|
||||||
job, err := client.AddJob()
|
job, err := client.AddJob()
|
||||||
|
|
@ -212,7 +210,7 @@ func main() {
|
||||||
fmt.Printf("Running job %s\n", job.Id)
|
fmt.Printf("Running job %s\n", job.Id)
|
||||||
|
|
||||||
var status common.ImageBuildState
|
var status common.ImageBuildState
|
||||||
result, err := RunJob(job, tmpdir, client.UploadImage)
|
result, err := RunJob(job, store, client.UploadImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf(" Job failed: %v", err)
|
log.Printf(" Job failed: %v", err)
|
||||||
status = common.IBFailed
|
status = common.IBFailed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue