S3
如果你想使用 S3 对象存储来获取你的包,可以使用 s3:// 协议作为通道。
在存储桶中,你的对象需要遵循标准的 conda 仓库结构:
Pixi 支持两种配置访问 S3 存储桶的方式:
- 使用来自环境变量或 AWS 配置文件的 AWS 凭据,像任何其他 AWS 工具一样
- 使用 pixi 配置并将凭据存储在 pixi 的认证存储中
这两个选项是互斥的!
指定 s3-options(见下文)将停用 AWS 凭据获取。
你可以使用来自常规位置的 AWS 凭据(不指定 s3-options)或来自 pixi 认证存储的凭据(指定 s3-options)。
使用 AWS 配置#
你可以在环境变量中指定 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 供 Pixi 使用。
你也可以指定 AWS_CONFIG_FILE 和 AWS_PROFILE 以使用自定义 AWS 配置文件和配置文件。
[profile conda]
sso_account_id = 123456789012
sso_role_name = PowerUserAccess
sso_start_url = https://my-company.awsapps.com/start
sso_region = eu-central-1
region = eu-central-1
output = json
$ export AWS_CONFIG_FILE=/path/to/aws.config
$ export AWS_PROFILE=conda
$ aws sso login
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
https://my-company.awsapps.com/start/#/device
Then enter the code:
DTBC-WFXC
Successfully logged into Start URL: https://my-company.awsapps.com/start
$ pixi search -c s3://my-s3-bucket/channel my-private-package
# ...
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
# 通过 OIDC 的临时凭据
- name: Log in to AWS
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-poweruser
aws-region: eu-central-1
- name: Set up pixi
# AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 由 aws-actions/configure-aws-credentials 设置
uses: prefix-dev/setup-pixi@v0.8.3
使用 Pixi 配置#
你可以在 pixi.toml 文件中指定 workspace.s3-options。
当你想要使用自定义 S3 兼容主机而不是 AWS 的配置时,这可能很有用。
[workspace.s3-options.my-bucket]
endpoint-url = "https://my-s3-host"
region = "us-east-1"
force-path-style = false
你需要为你使用的每个存储桶配置此配置,即使用 [workspace.s3-options.<bucket-name>]。
$ pixi auth login --aws-access-key-id=... --aws-secret-access-key=... s3://my-s3-bucket
Authenticating with s3://my-s3-bucket
$ pixi search my-private-package
# ...
你也可以在 Pixi 配置中指定 s3-options。
[s3-options.my-bucket]
endpoint-url = "https://my-s3-host"
region = "us-east-1"
force-path-style = false
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
# 通过 OIDC 的临时凭据
- name: Log in to AWS
uses: aws-actions/configure-aws-credentials@v4
id: aws
with:
role-to-assume: arn:aws:iam::123456789012:role/github-poweruser
aws-region: eu-central-1
- name: Set up pixi
# AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 由 aws-actions/configure-aws-credentials 设置
uses: prefix-dev/setup-pixi@v0.8.3
with:
auth-s3-access-key-id: ${{ steps.aws.outputs.aws-access-key-id }}
auth-s3-secret-access-key: ${{ steps.aws.outputs.aws-secret-access-key }}
auth-s3-session-token: ${{ steps.aws.outputs.aws-session-token }}
auth-host: s3://my-s3-bucket
公共 S3 存储桶#
可以通过将端点指定为常规 https URL 来使用不需要认证的公共存储桶。例如,在 AWS 上,你可能有一个可通过 https://my-public-bucket.s3.eu-central-1.amazonaws.com 公开访问的存储桶。
请注意,为此,你需要以允许公共访问的方式配置你的 S3 存储桶。
在 AWS 上,你需要具有 GetObject 和 ListBucket 权限。
以下是 AWS S3 的示例策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-public-bucket/*"
},
{
"Sid": "PublicReadListBucket",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::my-public-bucket"
}
]
}
Cloudflare R2 还支持通过 Cloudflare 管理的 r2.dev 子域或你控制下的自定义域访问公共存储桶,请参阅此处。
S3 兼容存储#
许多其他云提供商提供 S3 兼容存储 API。
你可以通过在 manifest 文件中指定 s3-options 来与 Pixi 一起使用它们。
MinIO#
Cloudflare R2#
endpoint-url = "https://<account-id>.eu.r2.cloudflarestorage.com"
region = "WEUR"
force-path-style = false
Wasabi#
Backblaze B2#
endpoint-url = "https://s3.us-west-004.backblazeb2.com"
region = "us-west-004"
force-path-style = true
Google Cloud Storage#
注意 Pixi 还支持 gcs:// URL。
endpoint-url = "https://storage.googleapis.com"
region = "us-east-1"
force-path-style = false
Hetzner 对象存储#
endpoint-url = "https://fsn1.your-objectstorage.com"
region = "US"
force-path-style = false
上传到 S3#
你可以使用 pixi upload s3 将包上传到 S3:
pixi upload s3 \
--bucket my-s3-bucket \
--channel my-channel \
--region us-east-1 \
--endpoint-url https://my-s3-host \
my_package.conda
使用 pixi upload s3 --help 查看所有可用选项。
使用 rattler-build 构建 .conda 包时,你也可以使用 rattler-build upload s3:有关更多信息,请参阅 rattler-build 文档。
上传新包后重新索引 S3 存储桶#
每次将新包上传到你的包仓库时,都需要更新 repodata.json 文件。
这对于 conda 包服务器(如 anaconda.org 或 prefix.dev)会自动完成。
另一方面,对于 S3 存储桶,我们需要手动执行此操作,因为 S3 存储桶只是一个存储系统,而不是包服务器。
要重新索引 S3 存储桶,你可以使用 rattler-index 包,该包在 conda-forge 上可用。