Skip to content

Commit

Permalink
RC updage
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Jul 27, 2024
1 parent 5301b71 commit cd5915d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lib/commands/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const awaitPools = {
}

const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => {
log('Checking for changes');
log('Checking for changes ...');
const changes = [];

await Promise.all(resource.map(async (localResource) => {
Expand Down Expand Up @@ -881,7 +881,7 @@ const pushSettings = async () => {
const remoteSettings = localConfig.createSettingsObject(response ?? {});
const localSettings = localConfig.getProject().projectSettings ?? {};

log('Checking for changes');
log('Checking for changes ...');
const changes = [];

changes.push(...(getObjectChanges(remoteSettings, localSettings, 'services', 'Service')));
Expand Down
30 changes: 16 additions & 14 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils');
const { runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils');
const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull } = require('../emulation/docker');

const runFunction = async ({ port, functionId, noVariables, noReload, userId } = {}) => {
const runFunction = async ({ port, functionId, variables, reload, userId } = {}) => {
console.log(variables);
console.log(reload);
// Selection
if(!functionId) {
const answers = await inquirer.prompt(questionsRunFunctions[0]);
Expand Down Expand Up @@ -113,17 +115,17 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
}

const userVariables = {};
const variables = {};
const allVariables = {};

if(!noVariables) {
if(variables) {
try {
const { variables: remoteVariables } = await paginate(functionsListVariables, {
functionId: func['$id'],
parseOutput: false
}, 100, 'variables');

remoteVariables.forEach((v) => {
variables[v.key] = v.value;
allVariables[v.key] = v.value;
userVariables[v.key] = v.value;
});
} catch(err) {
Expand All @@ -137,18 +139,18 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
const env = parseDotenv(fs.readFileSync(envPath).toString() ?? '');

Object.keys(env).forEach((key) => {
variables[key] = env[key];
allVariables[key] = env[key];
userVariables[key] = env[key];
});
}

variables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint');
variables['APPWRITE_FUNCTION_ID'] = func.$id;
variables['APPWRITE_FUNCTION_NAME'] = func.name;
variables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant
variables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId;
variables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? '';
variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime;
allVariables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint');
allVariables['APPWRITE_FUNCTION_ID'] = func.$id;
allVariables['APPWRITE_FUNCTION_NAME'] = func.name;
allVariables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant
allVariables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId;
allVariables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? '';
allVariables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime;

try {
await JwtManager.setup(userId, func.scopes ?? []);
Expand All @@ -162,7 +164,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
headers['x-appwrite-event'] = '';
headers['x-appwrite-user-id'] = userId ?? '';
headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? '';
variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers);
allVariables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers);

if(Object.keys(userVariables).length > 0) {
drawTable(Object.keys(userVariables).map((key) => ({
Expand All @@ -180,7 +182,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
process.stdout.write(chalk.white(`${data}\n`));
});

if(!noReload) {
if(reload) {
const ignorer = ignore();
ignorer.add('.appwrite');
ignorer.add('code.tar.gz');
Expand Down
50 changes: 25 additions & 25 deletions lib/emulation/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ async function dockerBuild(func, variables) {

const id = func.$id;

const ignorer = ignore();
ignorer.add('.appwrite');
if (func.ignore) {
ignorer.add(func.ignore);
} else if (fs.existsSync(path.join(functionDir, '.gitignore'))) {
ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString());
}

const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file));
const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build');
if (!fs.existsSync(tmpBuildPath)) {
fs.mkdirSync(tmpBuildPath, { recursive: true });
}

for(const f of files) {
const filePath = path.join(tmpBuildPath, f);
const fileDir = path.dirname(filePath);
if (!fs.existsSync(fileDir)) {
fs.mkdirSync(fileDir, { recursive: true });
}

const sourcePath = path.join(functionDir, f);
fs.copyFileSync(sourcePath, filePath);
}

const params = [ 'run' ];
params.push('--name', id);
params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`);
Expand Down Expand Up @@ -131,31 +156,6 @@ async function dockerStart(func, variables, port) {
// Pack function files
const functionDir = path.join(process.cwd(), func.path);

const ignorer = ignore();
ignorer.add('.appwrite');
if (func.ignore) {
ignorer.add(func.ignore);
} else if (fs.existsSync(path.join(functionDir, '.gitignore'))) {
ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString());
}

const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file));
const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build');
if (!fs.existsSync(tmpBuildPath)) {
fs.mkdirSync(tmpBuildPath, { recursive: true });
}

for(const f of files) {
const filePath = path.join(tmpBuildPath, f);
const fileDir = path.dirname(filePath);
if (!fs.existsSync(fileDir)) {
fs.mkdirSync(fileDir, { recursive: true });
}

const sourcePath = path.join(functionDir, f);
fs.copyFileSync(sourcePath, filePath);
}

const runtimeChunks = func.runtime.split("-");
const runtimeVersion = runtimeChunks.pop();
const runtimeName = runtimeChunks.join("-");
Expand Down

0 comments on commit cd5915d

Please sign in to comment.