defmodule GitGud.Storage.Garage do
@moduledoc """
S3-flavored object storage via [Garage](https://garagehq.deuxfleurs.fr/).
Garage exposes a Reduced S3 API; ExAws.S3 talks to it unchanged once
the endpoint is pointed at the Garage server.
Configure with:
config :ex_aws,
access_key_id: [{:system, "GARAGE_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "GARAGE_SECRET_ACCESS_KEY"}, :instance_role]
config :ex_aws, :s3,
scheme: "http://",
host: "garage.internal",
port: 3900,
region: "garage"
Buckets used:
* `gitgud-artifacts` — CI artifacts
* `gitgud-lfs` — Git LFS objects
* `gitgud-registry` — optional OCI mirror (zot has its own storage)
"""
@behaviour GitGud.Storage
@impl true
def put(bucket, key, body, opts) do
ExAws.S3.put_object(bucket, key, body, opts)
|> ExAws.request()
|> case do
{:ok, _} -> :ok
{:error, reason} -> {:error, reason}
end
end
@impl true
def get(bucket, key) do
ExAws.S3.get_object(bucket, key)
|> ExAws.request()
|> case do
{:ok, %{body: body}} -> {:ok, body}
{:error, reason} -> {:error, reason}
end
end
@impl true
def delete(bucket, key) do
ExAws.S3.delete_object(bucket, key)
|> ExAws.request()
|> case do
{:ok, _} -> :ok
{:error, reason} -> {:error, reason}
end
end
@impl true
def presign_url(bucket, key, method, opts) do
expires_in = Keyword.get(opts, :expires_in, 300)
ExAws.S3.presigned_url(ExAws.Config.new(:s3), method, bucket, key, expires_in: expires_in)
end
end
1.6 KiB · text
5af55d9