diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index 121db0d14..5a95ce281 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -36,6 +36,7 @@ type OSBuildJobImpl struct { GCPCreds []byte AzureCreds *azure.Credentials AWSCreds string + AWSBucket string } // Returns an *awscloud.AWS object with the credentials of the request. If they @@ -268,13 +269,17 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { key = uuid.New().String() } - _, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), options.Bucket, key) + bucket := options.Bucket + if impl.AWSBucket != "" { + bucket = impl.AWSBucket + } + _, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), bucket, key) if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error()) return nil } - ami, err := a.Register(args.Targets[0].ImageName, options.Bucket, key, options.ShareWithAccounts, common.CurrentArch()) + ami, err := a.Register(args.Targets[0].ImageName, bucket, key, options.ShareWithAccounts, common.CurrentArch()) if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error()) return nil @@ -305,12 +310,16 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { } key += "-" + options.Filename - _, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), options.Bucket, key) + bucket := options.Bucket + if impl.AWSBucket != "" { + bucket = impl.AWSBucket + } + _, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), bucket, key) if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error()) return nil } - url, err := a.S3ObjectPresignedURL(options.Bucket, key) + url, err := a.S3ObjectPresignedURL(bucket, key) if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error()) return nil diff --git a/cmd/osbuild-worker/main.go b/cmd/osbuild-worker/main.go index 5105c3fe3..5e681689c 100644 --- a/cmd/osbuild-worker/main.go +++ b/cmd/osbuild-worker/main.go @@ -137,6 +137,7 @@ func main() { } `toml:"azure"` AWS *struct { Credentials string `toml:"credentials"` + Bucket string `toml:"bucket"` } `toml:"aws"` Authentication *struct { OAuthURL string `toml:"oauth_url"` diff --git a/templates/packer/ansible/roles/common/files/worker-initialization-scripts/worker_service.sh b/templates/packer/ansible/roles/common/files/worker-initialization-scripts/worker_service.sh index 0eb0b7f48..cc848d3a8 100755 --- a/templates/packer/ansible/roles/common/files/worker-initialization-scripts/worker_service.sh +++ b/templates/packer/ansible/roles/common/files/worker-initialization-scripts/worker_service.sh @@ -14,7 +14,8 @@ credentials = "/etc/osbuild-worker/gcp_credentials.json" [azure] credentials = "/etc/osbuild-worker/azure_credentials.toml" [aws] -credentials = "/etc/osbuild-worker/aws_credentials.toml" +credentials = "${WORKER_CONFIG_AWS_CREDENTIALS:-}" +bucket = "${WORKER_CONFIG_AWS_BUCKET:-}" EOF # Prepare osbuild-composer's remote worker services and sockets.