Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Nov 2, 2022
1 parent e85b06b commit 1052cb7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const schema = Type.Object(
STORAGE_PROVIDER: Type.Optional(
Type.Enum(STORAGE_PROVIDERS, { default: STORAGE_PROVIDERS.LOCAL }),
),
BODY_LIMIT: Type.Number({ default: 104857600 }),
STORAGE_PATH: Type.Optional(Type.String()),
STORAGE_PATH_USE_TMP_FOLDER: Type.Optional(Type.Boolean({ default: true })),
// AWS_ env vars are used as aws-sdk defaults
AWS_ACCESS_KEY_ID: Type.Optional(Type.String()),
AWS_SECRET_ACCESS_KEY: Type.Optional(Type.String()),
Expand Down
10 changes: 3 additions & 7 deletions src/plugins/remote-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ async function turboRemoteCache(
instance: FastifyInstance,
options: {
allowedTokens: string[]
bodyLimit?: number
apiVersion?: `v${number}`
provider?: STORAGE_PROVIDERS
},
) {
const {
allowedTokens,
bodyLimit = 104857600,
apiVersion = 'v8',
provider = STORAGE_PROVIDERS.LOCAL,
} = options
const bodyLimit = instance.config.BODY_LIMIT ?? 104857600
const { allowedTokens, apiVersion = 'v8', provider = STORAGE_PROVIDERS.LOCAL } = options
if (!(Array.isArray(allowedTokens) && allowedTokens.length)) {
throw new Error(
`'allowedTokens' options must be a string[], ${typeof allowedTokens} provided instead`,
Expand Down Expand Up @@ -58,6 +53,7 @@ async function turboRemoteCache(
clientEmail: instance.config.GCS_CLIENT_EMAIL,
privateKey: instance.config.GCS_PRIVATE_KEY,
projectId: instance.config.GCS_PROJECT_ID,
useTmp: instance.config.STORAGE_PATH_USE_TMP_FOLDER ?? true,
}),
)

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/remote-cache/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

const pipeline = promisify(pipelineCallback)
const TURBO_CACHE_FOLDER_NAME = 'turborepocache' as const
const TURBO_CACHE_USE_TMP_FOLDER = true as const

type LocalOptions = Partial<LocalOpts>
type S3Options = Omit<S3Opts, 'bucket'> & LocalOptions
Expand All @@ -37,11 +38,11 @@ function createStorageLocation<Provider extends STORAGE_PROVIDERS>(
provider: Provider,
providerOptions: ProviderOptions<Provider>,
): StorageProvider {
const { path = TURBO_CACHE_FOLDER_NAME } = providerOptions
const { path = TURBO_CACHE_FOLDER_NAME, useTmp = TURBO_CACHE_USE_TMP_FOLDER } = providerOptions

switch (provider) {
case STORAGE_PROVIDERS.LOCAL: {
return createLocal({ path })
return createLocal({ path, useTmp })
}
case STORAGE_PROVIDERS.S3:
case STORAGE_PROVIDERS.s3: {
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/remote-cache/storage/local.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { tmpdir } from 'os'
import { join } from 'path'
import { join, normalize } from 'path'
import fs from 'fs-blob-store'

export type LocalOptions = {
path: string
useTmp: boolean
}

export function createLocal({ path }: LocalOptions) {
return fs(join(tmpdir(), path))
export function createLocal({ path, useTmp }: LocalOptions) {
const fullPath = useTmp ? join(tmpdir(), path) : normalize(path)
return fs(fullPath)
}

0 comments on commit 1052cb7

Please sign in to comment.