Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/services/vercel_artifacts/default/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: default
description: 'Behavior test for Vercel Remote Cache'

runs:
using: "composite"
steps:
- name: Setup
uses: 1Password/load-secrets-action@92467eb28f72e8255933372f1e0707c567ce2259 # v4.0.0
with:
export-env: true
env:
OPENDAL_VERCEL_ARTIFACTS_ACCESS_TOKEN: op://services/vercel_artifacts/access_token
OPENDAL_VERCEL_ARTIFACTS_TEAM_ID: op://services/vercel_artifacts/team_id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test Vercel Remote Cache without team_id?

33 changes: 31 additions & 2 deletions core/services/vercel-artifacts/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl Builder for VercelArtifactsBuilder {
stat: true,

read: true,
read_with_suffix: true,

write: true,

Expand Down Expand Up @@ -166,23 +165,44 @@ impl Service for VercelArtifactsBackend {
_path: &str,
_args: OpCreateDir,
) -> Result<RpCreateDir> {
// Vercel Remote Cache is append-only and does not support folder operations.
Err(Error::new(
ErrorKind::Unsupported,
"operation is not supported",
))
}

async fn stat(&self, ctx: &OperationContext, path: &str, _args: OpStat) -> Result<RpStat> {
if path == "/" || path.ends_with('/') {
return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
}

let response = self.core.vercel_artifacts_stat(ctx, path).await?;

let status = response.status();

match status {
StatusCode::PARTIAL_CONTENT => {
// 206: Content-Range header encodes total artifact size.
let meta = parse_into_metadata(path, response.headers())?;
Ok(RpStat::new(meta))
}
StatusCode::OK => {
// 200: server returned full content (Range header not honoured).
// Content-Length may be absent when transfer is chunked; fall back
// to body length so that stat always returns the correct file size.
let (parts, body) = response.into_parts();
let mut meta = parse_into_metadata(path, &parts.headers)?;
if meta.content_length() == 0 && !body.is_empty() {
meta.set_content_length(body.len() as u64);
}
Ok(RpStat::new(meta))
}
StatusCode::RANGE_NOT_SATISFIABLE => {
// 416: artifact exists but is empty (size = 0).
let meta = parse_into_metadata(path, response.headers())?;
Ok(RpStat::new(meta))
}

_ => Err(parse_error(response)),
}
}
Expand All @@ -200,6 +220,14 @@ impl Service for VercelArtifactsBackend {
}

fn write(&self, ctx: &OperationContext, path: &str, args: OpWrite) -> Result<Self::Writer> {
// Vercel Remote Cache is key-based; paths ending with '/' are treated as directories.
if path.ends_with('/') {
return Err(Error::new(
ErrorKind::IsADirectory,
"write to a directory path is not supported",
));
}

let output: oio::OneShotWriter<VercelArtifactsWriter> = {
Ok(oio::OneShotWriter::new(VercelArtifactsWriter::new(
self.core.clone(),
Expand All @@ -213,6 +241,7 @@ impl Service for VercelArtifactsBackend {
}

fn delete(&self, _ctx: &OperationContext) -> Result<Self::Deleter> {
// Vercel Remote Cache is append-only and does not support artifact deletion.
Err(Error::new(
ErrorKind::Unsupported,
"operation is not supported",
Expand Down
26 changes: 15 additions & 11 deletions core/services/vercel-artifacts/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ impl VercelArtifactsCore {
self.query_string
);

let mut req = Request::head(&url);

let auth_header_content = format!("Bearer {}", self.access_token);
req = req.header(header::AUTHORIZATION, auth_header_content);
req = req.header(header::CONTENT_LENGTH, 0);

req = req
// Use a Range request instead of HEAD so that the Content-Range response
// header gives us the total artifact size (Vercel's HEAD responses do not
// include Content-Length). Matches the pattern used by the ghac backend.
let req = Request::get(&url)
.header(
header::AUTHORIZATION,
format!("Bearer {}", self.access_token),
)
.header(header::RANGE, "bytes=0-0")
.extension(Operation::Stat)
.extension(ServiceOperation("ArtifactExists"));

let req = req.body(Buffer::new()).map_err(new_request_build_error)?;
.extension(ServiceOperation("ArtifactExists"))
.body(Buffer::new())
.map_err(new_request_build_error)?;

ctx.http_transport().send(req).await
}
Expand All @@ -144,7 +146,9 @@ mod error {

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
(ErrorKind::PermissionDenied, false)
}
StatusCode::INTERNAL_SERVER_ERROR
| StatusCode::BAD_GATEWAY
| StatusCode::SERVICE_UNAVAILABLE
Expand Down
8 changes: 8 additions & 0 deletions core/services/vercel-artifacts/src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ This service can be used to:
- [ ] ~~rename~~
- [ ] ~~presign~~

## Limitations

Vercel Remote Cache stores build artifacts addressed by a hash of the task inputs.
Because of its append-only, hash-keyed design, it has the following limitations:
- **Folder Operations**: It does not support creating directories (`create_dir`) or listing files (`list`).
- **Resource Deletion**: It does not support deleting individual remote cache artifacts (`delete`). Cache invalidation is handled automatically by Vercel or locally via input changes (which produce a new task hash).
- **Suffix Range Reads**: `read_with_suffix` is not declared because suffix range reads (`Range: bytes=-N`) have not been verified against the Vercel Remote Cache API. Full reads and standard range reads (`Range: bytes=X-Y`) are supported.

## Configuration

- `access_token`: set the access_token for Rest API
Expand Down
9 changes: 7 additions & 2 deletions core/services/vercel-artifacts/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ impl VercelArtifactsWriter {

impl oio::OneShotWrite for VercelArtifactsWriter {
async fn write_once(&self, bs: Buffer) -> Result<Metadata> {
let size = bs.len() as u64;
let response = self
.core
.vercel_artifacts_put(&self.ctx, self.path.as_str(), bs.len() as u64, bs)
.vercel_artifacts_put(&self.ctx, self.path.as_str(), size, bs)
.await?;

let status = response.status();

match status {
StatusCode::OK | StatusCode::ACCEPTED => Ok(Metadata::default()),
StatusCode::OK | StatusCode::ACCEPTED => {
let mut meta = Metadata::default();
meta.set_content_length(size);
Ok(meta)
}
_ => Err(parse_error(response)),
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/tests/behavior/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ pub async fn test_writer_write_with_overwrite(op: Operator) -> Result<()> {
if op.info().scheme() == services::GHAC_SCHEME {
return Ok(());
}
// vercel-artifacts does not support overwrite: a PUT to an existing
// artifact hash returns 200 (cache hit) without updating the stored content.
#[cfg(feature = "services-vercel-artifacts")]
if op.info().scheme() == services::VERCEL_ARTIFACTS_SCHEME {
return Ok(());
}

let path = uuid::Uuid::new_v4().to_string();
let (content_one, _) = gen_bytes(op.info().capability());
Expand Down
Loading