-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
externalized commands impl into dedicated modules
- Loading branch information
Showing
10 changed files
with
257 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
export function auth(opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tmpLocalFile = `/tmp/google-service-account.json`; | ||
yield $ `curl -sSL ${opts.keyConfig} > ${tmpLocalFile}`; | ||
yield $ `gcloud auth activate-service-account -q --key-file ${tmpLocalFile}`; | ||
yield $ `rm -f ${tmpLocalFile}`; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { cacheableCommand } from "../cacheableCommand.js"; | ||
export function cachedFS(opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield cacheableCommand(opts.coords, { | ||
compressContent: opts.compressed, | ||
checksumCommand: () => $ `md5 -q "${opts.checksumFile}"`, | ||
cachedPaths: opts.directories | ||
}, () => { | ||
const [command, ...args] = opts.cacheableCommand.split(" "); | ||
console.info(`Executing cacheable command: ${command} ${args}`); | ||
return $ `${command} ${args}`; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { CachePersistor } from "../CachePersistor.js"; | ||
export function loadFS(opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cacheMetadata = yield CachePersistor.loadCacheMetadata(opts.coords); | ||
if (!cacheMetadata) { | ||
const message = `No cache metadata found for coordinates=${JSON.stringify(opts.coords)}`; | ||
switch (opts.onInexistantCache) { | ||
case 'fail': throw new Error(message); | ||
case 'warn': | ||
console.log(message); | ||
return; | ||
// default ('ignore'): do nothing | ||
} | ||
} | ||
const cachePersistor = CachePersistor.compressed(cacheMetadata.compressed); | ||
const namedCachedPaths = cacheMetadata.all | ||
? [{ pathName: "__all__", path: "" }] | ||
: opts.directories.map(dir => ({ pathName: dir, path: dir })); | ||
yield Promise.all(namedCachedPaths.map(ncp => { | ||
console.log(`Loading ${ncp.pathName} from cache:${opts.coords.cacheName}`); | ||
return cachePersistor.loadCache(opts.coords, ncp.path, ncp.pathName); | ||
})); | ||
console.log(`Directories loaded from cache !`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { CachePersistor } from "../CachePersistor.js"; | ||
export function storeFS(opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cachePersistor = CachePersistor.compressed(opts.compressed); | ||
const synchronizeAll = !opts.directories.length; | ||
const namedCachedPaths = synchronizeAll | ||
? [{ pathName: "__all__", path: "." }] | ||
: opts.directories.map(dir => ({ pathName: dir, path: dir })); | ||
yield Promise.all(namedCachedPaths.map(ncp => { | ||
console.log(`Storing ${ncp.pathName} into cache:${opts.coords.cacheName}`); | ||
return cachePersistor.pushCache(opts.coords, ncp.path, ncp.pathName); | ||
})); | ||
yield CachePersistor.storeCacheMetadata(opts.coords, { | ||
compressed: opts.compressed, | ||
// No need to provide any checksum when storing non-cacheable fs | ||
checksum: undefined, | ||
all: synchronizeAll | ||
}); | ||
console.log(`Directories stored in cache !`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export type AuthOptions = { | ||
keyConfig: string; | ||
}; | ||
|
||
export async function auth(opts: AuthOptions) { | ||
const tmpLocalFile = `/tmp/google-service-account.json`; | ||
await $`curl -sSL ${opts.keyConfig} > ${tmpLocalFile}` | ||
await $`gcloud auth activate-service-account -q --key-file ${tmpLocalFile}` | ||
await $`rm -f ${tmpLocalFile}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {cacheableCommand} from "../cacheableCommand.js"; | ||
import {CacheCoordinates} from "../CachePersistor.js"; | ||
|
||
|
||
export type CachedFSOptions = { | ||
coords: CacheCoordinates; | ||
compressed: boolean; | ||
checksumFile: string; | ||
cacheableCommand: string; | ||
directories: string[]; | ||
}; | ||
|
||
export async function cachedFS(opts: CachedFSOptions) { | ||
await cacheableCommand(opts.coords, { | ||
compressContent: opts.compressed, | ||
checksumCommand: () => $`md5 -q "${opts.checksumFile}"`, | ||
cachedPaths: opts.directories | ||
}, () => { | ||
const [command, ...args] = opts.cacheableCommand.split(" "); | ||
console.info(`Executing cacheable command: ${command} ${args}`) | ||
return $`${command} ${args}` | ||
}) | ||
} |
Oops, something went wrong.