Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e055b1c
feat(azblob): add azure dependencies
Jonas-Beck Jul 30, 2026
d936010
feat(azblob): add initial implementation
Jonas-Beck Jul 30, 2026
3936c99
feat(azblob): add listStorageFolders implementation
Jonas-Beck Jul 30, 2026
a3bf7b6
feat(azblob): add rest of interface functions
Jonas-Beck Jul 30, 2026
396b3d4
test(azblob): implement test using azurite
Jonas-Beck Jul 31, 2026
de315e6
feat(chart): add azblob config values
Jonas-Beck Aug 4, 2026
8c4d1e6
chore(azblob): use Readable.from instead of casting
Jonas-Beck Sep 16, 2026
feefec7
fix(azblob): add trailing slash to prefix
Jonas-Beck Sep 16, 2026
dec1b55
chore(azblob): use BlobBatchClient for deletion of blobs
Jonas-Beck Sep 16, 2026
b64aa95
chore(azblob): remove connectionString from values and helpers
Jonas-Beck Sep 16, 2026
cc273ef
test(azblob): add test case for createDownloadUrl
Jonas-Beck Sep 18, 2026
0f6458d
feat(azblob): use generateSasUrl for connection string and build endp…
Jonas-Beck Sep 18, 2026
0bca875
feat(azblob): make account optional for connectionstring
Jonas-Beck Sep 18, 2026
318a211
Merge branch 'falcondev-oss:dev' into feature/azblob
Jonas-Beck Oct 10, 2026
7beb250
fix(azblob): implement listFolder instead of getFolderSize
Jonas-Beck Sep 21, 2026
75feae1
chore(deps): pnpm install
Jonas-Beck Oct 10, 2026
4930656
chore(deps): pnpm install
Jonas-Beck Oct 10, 2026
e5870d0
feat(azblob): add support for eager merge
Jonas-Beck Oct 10, 2026
a072f8e
Merge remote-tracking branch 'origin/dev' into feat/azblob-storage
LouisHaftmann Oct 23, 2026
d8964fe
fix(azblob): harden compose, batch delete and container setup
LouisHaftmann Oct 23, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
storage-driver: [filesystem, s3, gcs]
storage-driver: [filesystem, s3, gcs, azblob]
db-driver: [postgres, mysql, sqlite]
steps:
- name: pnpm install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ Generate environment variables from config values.
value: {{ .endpoint | quote }}
{{- end }}
{{- end }}
{{- else if eq .Values.config.storage.driver "azblob" }}
{{- with .Values.config.storage.azblob }}
{{- if .account }}
- name: STORAGE_AZBLOB_ACCOUNT
value: {{ .account | quote }}
{{- end }}
{{- if .container }}
- name: STORAGE_AZBLOB_CONTAINER
value: {{ .container | quote }}
{{- end }}
{{- if .endpoint }}
- name: STORAGE_AZBLOB_ENDPOINT
value: {{ .endpoint | quote }}
{{- end }}
{{- end }}
{{- end }}
{{/* Database driver */}}
- name: DB_DRIVER
Expand Down
16 changes: 14 additions & 2 deletions install/kubernetes/github-actions-cache-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ config:
# -- Storage driver configuration
# See https://gha-cache-server.falcondev.io/storage-drivers
storage:
# -- Storage driver to use: "filesystem", "s3", or "gcs"
# -- Storage driver to use: "filesystem", "s3", "gcs", or "azblob"
driver: filesystem

# -- Filesystem storage driver settings
Expand Down Expand Up @@ -108,6 +108,18 @@ config:
# -- Custom GCS API endpoint
# endpoint: ''

# -- Azure Blob Storage driver settings
# Auth is either a connection string (STORAGE_AZBLOB_CONNECTION_STRING via existingSecret)
# or `account` + workload identity (DefaultAzureCredential). The connection string carries
# its own account and endpoint, so `account` and `endpoint` are ignored in that mode.
azblob:
# -- Azure Blob container name (required when driver is "azblob")
# container: ''
# -- Azure Storage account name (required only when using DefaultAzureCredential; ignored when a connection string is set)
# account: ''
# -- Custom Azure Blob Storage endpoint URL (optional, defaults to https://<account>.blob.core.windows.net; ignored when a connection string is set)
# endpoint: ''

# -- Database driver configuration
# See https://gha-cache-server.falcondev.io/database-drivers
db:
Expand Down Expand Up @@ -153,7 +165,7 @@ config:

# -- Name of an existing Kubernetes Secret containing sensitive environment variables.
# Use this to avoid storing secrets in values.yaml. The secret keys should match
# the env var names (e.g., AWS_SECRET_ACCESS_KEY, DB_POSTGRES_PASSWORD, DB_POSTGRES_URL, etc.)
# the env var names (e.g., AWS_SECRET_ACCESS_KEY, DB_POSTGRES_PASSWORD, DB_POSTGRES_URL, STORAGE_AZBLOB_CONNECTION_STRING etc.)
existingSecret: ''

serviceAccount:
Expand Down
14 changes: 14 additions & 0 deletions lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export const envStorageDriverSchema = type.or(
'STORAGE_GCS_SERVICE_ACCOUNT_KEY?': 'string',
'STORAGE_GCS_ENDPOINT?': 'string.url',
},
{
'STORAGE_DRIVER': type.unit('azblob'),
'STORAGE_AZBLOB_CONTAINER': 'string',
'STORAGE_AZBLOB_CONNECTION_STRING': 'string',
'STORAGE_AZBLOB_ACCOUNT?': 'undefined',
'STORAGE_AZBLOB_ENDPOINT?': 'undefined',
},
{
'STORAGE_DRIVER': type.unit('azblob'),
'STORAGE_AZBLOB_CONTAINER': 'string',
'STORAGE_AZBLOB_ACCOUNT': 'string',
'STORAGE_AZBLOB_ENDPOINT?': 'string.url',
'STORAGE_AZBLOB_CONNECTION_STRING?': 'undefined',
},
)
export const envDbDriverSchema = type.or(
type.or(
Expand Down
189 changes: 189 additions & 0 deletions lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable ts/method-signature-style */
import type { ContainerClient } from '@azure/storage-blob'
import type { Kysely } from 'kysely'
import type { Database, StorageLocation } from './db'
import type { Env } from './schemas'
Expand All @@ -25,6 +26,13 @@ import {
} from '@aws-sdk/client-s3'
import { Upload as S3Upload } from '@aws-sdk/lib-storage'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import { DefaultAzureCredential } from '@azure/identity'
import {
BlobSASPermissions,
BlobServiceClient,
generateBlobSASQueryParameters,
StorageSharedKeyCredential,
} from '@azure/storage-blob'
import { Storage as GcsClient } from '@google-cloud/storage'
import { NodeHttpHandler } from '@smithy/node-http-handler'
import { sql } from 'kysely'
Expand Down Expand Up @@ -79,6 +87,7 @@ export class Storage {
.with({ STORAGE_DRIVER: 's3' }, S3Adapter.fromEnv)
.with({ STORAGE_DRIVER: 'filesystem' }, FileSystemAdapter.fromEnv)
.with({ STORAGE_DRIVER: 'gcs' }, GcsAdapter.fromEnv)
.with({ STORAGE_DRIVER: 'azblob' }, AzBlobAdapter.fromEnv)
.exhaustive()
}

Expand Down Expand Up @@ -1401,3 +1410,183 @@ class GcsAdapter implements StorageAdapter {
.then((res) => res[0])
}
}

class AzBlobAdapter implements StorageAdapter {
static async fromEnv(env: Extract<Env, { STORAGE_DRIVER: 'azblob' }>) {
const service = env.STORAGE_AZBLOB_CONNECTION_STRING
? BlobServiceClient.fromConnectionString(env.STORAGE_AZBLOB_CONNECTION_STRING)
: new BlobServiceClient(
env.STORAGE_AZBLOB_ENDPOINT ??
`https://${env.STORAGE_AZBLOB_ACCOUNT}.blob.core.windows.net`,
new DefaultAzureCredential(),
)
const container = service.getContainerClient(env.STORAGE_AZBLOB_CONTAINER)
if (!(await container.exists()))
throw new Error(`Container ${env.STORAGE_AZBLOB_CONTAINER} does not exist`)

return new AzBlobAdapter({ service, container })
}

private service
private container
private keyPrefix = 'gh-actions-cache'

// Put Block From URL, service version 2020-04-08+: 4000 MiB per block, 50000 blocks per blob.
// https://learn.microsoft.com/en-us/rest/api/storageservices/put-block-from-url
composeParts = {
minPartBytes: 0,
maxPartBytes: 4000 * 1024 ** 2,
maxParts: 50_000,
run: async (folderName: string, partCount: number) => {
const merged = this.blob(`${folderName}/merged`).getBlockBlobClient()
// Put Block From URL reads each Part through a SAS URL. The SAS is
// checked when each request starts, so it must outlive the whole run.
const sign = await this.sasSigner(Date.now() + 60 * 60 * 1000)
const blockIds = []
for (let index = 0; index < partCount; index++) {
const blockId = Buffer.from(String(index).padStart(10, '0')).toString('base64')
await merged.stageBlockFromURL(blockId, await sign(`${folderName}/parts/${index}`))
blockIds.push(blockId)
}
// Committing the block list makes `merged` appear atomically (ADR-0004).
await merged.commitBlockList(blockIds)
},
}

constructor({ service, container }: { service: BlobServiceClient; container: ContainerClient }) {
this.service = service
this.container = container
}

private blob(objectName: string) {
return this.container.getBlobClient(`${this.keyPrefix}/${objectName}`)
}

/** Returns a signer for read-only SAS URLs, fetching the user delegation key once. */
private async sasSigner(expiresAt: number) {
// Backdated so clock skew doesn't make the SAS "not yet valid".
const startsOn = new Date(Date.now() - 5 * 60 * 1000)
const expiresOn = new Date(expiresAt)
const permissions = BlobSASPermissions.parse('r')
// A shared key signs directly; Entra ID credentials need a user delegation key.
const delegationKey =
this.service.credential instanceof StorageSharedKeyCredential
? undefined
: await this.service.getUserDelegationKey(startsOn, expiresOn)

return (objectName: string) => {
const blob = this.blob(objectName)
if (!delegationKey) return blob.generateSasUrl({ permissions, startsOn, expiresOn })
const sas = generateBlobSASQueryParameters(
{
containerName: blob.containerName,
blobName: blob.name,
permissions,
startsOn,
expiresOn,
},
delegationKey,
blob.accountName,
)
return Promise.resolve(`${blob.url}?${sas.toString()}`)
}
}

private async deleteByPrefix(prefix: string) {
const deleted = { objects: 0, bytes: 0 }
const batch = this.container.getBlobBatchClient()
// A batch takes at most 256 subrequests, so each listed page is one batch.
const pages = this.container.listBlobsFlat({ prefix }).byPage({ maxPageSize: 256 })

for await (const page of pages) {
const blobs = page.segment.blobItems
if (blobs.length === 0) continue

// Sub-requests fail individually without rejecting the batch.
const { subResponses } = await batch.deleteBlobs(
blobs.map((blob) => this.container.getBlobClient(blob.name)),
)
const failed = blobs.flatMap((blob, index) => {
const response = subResponses[index]
return response?.status === 202
? []
: [`${blob.name} (${response?.errorCode ?? 'no response'})`]
})
if (failed.length > 0)
throw new Error(
`Azure Blob failed to delete ${failed.length} blob(s): ${failed.join(', ')}`,
)

deleted.objects += blobs.length
deleted.bytes += blobs.reduce(
(total, blob) => total + (blob.properties.contentLength ?? 0),
0,
)
}

return deleted
}

async createDownloadStream(objectName: string) {
const response = await this.blob(objectName).download()
if (!response.readableStreamBody) throw new Error(`No stream for blob "${objectName}"`)
return Readable.from(response.readableStreamBody)
}

async uploadStream(objectName: string, stream: Readable) {
await this.blob(objectName).getBlockBlobClient().uploadStream(stream)
}

async objectExists(objectName: string) {
return this.blob(objectName).exists()
}

async deleteFolder(folderName: string) {
return this.deleteByPrefix(`${this.keyPrefix}/${folderName}/`)
}

async clear() {
await this.deleteByPrefix(`${this.keyPrefix}/`)
}

async countFilesInFolder(folderName: string) {
const objects = await this.listFolder(folderName)
return objects.length
}

async listFolder(folderName: string) {
const prefix = `${this.keyPrefix}/${folderName}/`
const objects: StorageObject[] = []
const blobs = this.container.listBlobsFlat({ prefix })
for await (const blob of blobs)
objects.push({
name: blob.name.slice(prefix.length),
bytes: blob.properties.contentLength ?? 0,
})
return objects
}

async listStorageFolders() {
const folders = new Map<string, StorageFolder>()
const prefix = `${this.keyPrefix}/`

const blobs = this.container.listBlobsFlat({ prefix })
for await (const blob of blobs) {
const folderName = blob.name.slice(prefix.length).split('/', 1)[0]
if (!folderName) continue
accumulateFolder(
folders,
folderName,
blob.properties.contentLength ?? 0,
blob.properties.lastModified?.getTime() ?? 0,
)
}

return [...folders.values()]
}

async createDownloadUrl(objectName: string, expiresAt: number) {
const sign = await this.sasSigner(expiresAt)
return sign(objectName)
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:fix": "eslint --fix --cache . && prettier --write --cache .",
"type-check": "tsc --noEmit",
"test:run": "DEBUG=true vitest run",
"test:matrix": "for db in sqlite postgres mysql; do for st in filesystem s3 gcs; do echo \"### $db + $st\"; VITEST_DB_DRIVER=$db VITEST_STORAGE_DRIVER=$st pnpm run test:run || exit 1; done; done"
"test:matrix": "for db in sqlite postgres mysql; do for st in filesystem s3 gcs azblob; do echo \"### $db + $st\"; VITEST_DB_DRIVER=$db VITEST_STORAGE_DRIVER=$st pnpm run test:run || exit 1; done; done"
},
"changelogithub": {
"extends": "gh:falcondev-it/configs/changelogithub"
Expand All @@ -25,6 +25,8 @@
"@aws-sdk/client-s3": "^3.1085.0",
"@aws-sdk/lib-storage": "^3.1085.0",
"@aws-sdk/s3-request-presigner": "^3.1085.0",
"@azure/identity": "^4.13.1",
"@azure/storage-blob": "^12.33.0",
"@google-cloud/storage": "^7.21.0",
"@orpc/client": "^1.14.7",
"@orpc/json-schema": "^1.14.7",
Expand Down
Loading
Loading