Skip to content

Commit

Permalink
cloudapi: make Bucket optional in GCPUploadOptions
Browse files Browse the repository at this point in the history
GCP Bucket to use can be now configured in the worker configuration.
Make the `Bucket` optional in the Cloud API when uploading image to GCP.

Adjust the Cloud API test case to configure GCP Bucket on the worker and
not provide it in the API request.
  • Loading branch information
thozza committed Sep 27, 2022
1 parent c4fa53e commit c767835
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 73 deletions.
6 changes: 5 additions & 1 deletion internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,14 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
}

imageName := fmt.Sprintf("composer-api-%s", uuid.New().String())
var bucket string
if gcpUploadOptions.Bucket != nil {
bucket = *gcpUploadOptions.Bucket
}
t := target.NewGCPTarget(&target.GCPTargetOptions{
Region: gcpUploadOptions.Region,
Os: imageType.Arch().Distro().Name(), // not exposed in cloudapi
Bucket: gcpUploadOptions.Bucket,
Bucket: bucket,
// the uploaded object must have a valid extension
Object: fmt.Sprintf("%s.tar.gz", imageName),
ShareWithAccounts: share,
Expand Down
138 changes: 69 additions & 69 deletions internal/cloudapi/v2/openapi.v2.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/cloudapi/v2/openapi.v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ components:
type: object
required:
- region
- bucket
properties:
region:
type: string
Expand Down
1 change: 0 additions & 1 deletion test/cases/api/gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function createReqFile() {
"image_type": "${IMAGE_TYPE}",
"repositories": $(jq ".\"$ARCH\"" /usr/share/tests/osbuild-composer/repositories/"$DISTRO".json),
"upload_options": {
"bucket": "${GCP_BUCKET}",
"region": "${GCP_REGION}",
"image_name": "${GCP_IMAGE_NAME}",
"share_with_accounts": ["${GCP_API_TEST_SHARE_ACCOUNT}"]
Expand Down
7 changes: 6 additions & 1 deletion tools/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ EOF
# it into /tmp and as a result, the worker would not see it due to using PrivateTmp=true.
GCP_CREDS_WORKER_PATH="/etc/osbuild-worker/gcp-credentials.json"
sudo cp "$GOOGLE_APPLICATION_CREDENTIALS" "$GCP_CREDS_WORKER_PATH"
echo -e "\n[gcp]\ncredentials = \"$GCP_CREDS_WORKER_PATH\"\n" | sudo tee -a /etc/osbuild-worker/osbuild-worker.toml
sudo tee -a /etc/osbuild-worker/osbuild-worker.toml > /dev/null << EOF
[gcp]
credentials = "$GCP_CREDS_WORKER_PATH"
bucket = "$GCP_BUCKET"
EOF
fi

# if Azure credentials are defined in the env, create the credentials file
Expand Down

0 comments on commit c767835

Please sign in to comment.