Skip to content

Commit

Permalink
fix: fix unknown deployment error in Linux (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjk7989 authored Nov 8, 2023
1 parent b2123b9 commit 90abd45
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
13 changes: 3 additions & 10 deletions src/cli/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
updateSwaCliConfigFile,
} from "../../../core";
import { chooseOrCreateProjectDetails, getStaticSiteDeployment } from "../../../core/account";
import { DEFAULT_RUNTIME_LANGUAGE, STATIC_SITE_CLIENT_WORKING_FOLDER } from "../../../core/constants";
import { DEFAULT_RUNTIME_LANGUAGE } from "../../../core/constants";
import { cleanUp, getDeployClientPath } from "../../../core/deploy-client";
import { swaCLIEnv } from "../../../core/env";
import { getDefaultVersion } from "../../../core/functions-versions";
Expand Down Expand Up @@ -255,11 +255,6 @@ export async function deploy(options: SWACLIConfig) {
FUNCTION_LANGUAGE_VERSION: apiVersion,
};

const clientWorkingDir = path.resolve(deployClientEnv.REPOSITORY_BASE ?? "", STATIC_SITE_CLIENT_WORKING_FOLDER);
if (!fs.existsSync(clientWorkingDir)) {
fs.mkdirSync(clientWorkingDir);
}

// set the DEPLOYMENT_ENVIRONMENT env variable only when the user has provided
// a deployment environment which is not "production".
if (options.env?.toLowerCase() !== "production" && options.env?.toLowerCase() !== "prod") {
Expand All @@ -280,15 +275,13 @@ export async function deploy(options: SWACLIConfig) {
logger.silly(`Deploying using ${cliEnv.SWA_CLI_DEPLOY_BINARY}`);
logger.silly(`Deploying using the following options:`);
logger.silly({ env: { ...cliEnv, ...deployClientEnv } });
logger.silly(`StaticSiteClient working directory: ${clientWorkingDir}`);

spinner.start(`Preparing deployment. Please wait...`);

const child = spawn(binary, [], {
env: {
...swaCLIEnv(cliEnv, deployClientEnv),
},
cwd: clientWorkingDir,
});

let projectUrl = "";
Expand Down Expand Up @@ -330,7 +323,7 @@ export async function deploy(options: SWACLIConfig) {
});

child.on("close", (code) => {
cleanUp(clientWorkingDir);
cleanUp();

if (code === 0) {
spinner.succeed(chalk.green(`Project deployed to ${chalk.underline(projectUrl)} 🚀`));
Expand All @@ -347,7 +340,7 @@ export async function deploy(options: SWACLIConfig) {
);
logGitHubIssueMessageAndExit();
} finally {
cleanUp(clientWorkingDir);
cleanUp();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const DEPLOY_BINARY_NAME = "StaticSitesClient";
export const DEPLOY_BINARY_STABLE_TAG = "stable";
export const DEPLOY_FOLDER = path.join(os.homedir(), ".swa", "deploy");
export const STATIC_SITE_CLIENT_RELEASE_METADATA_URL = "https://swalocaldeploy.azureedge.net/downloads/versions.json";
export const STATIC_SITE_CLIENT_WORKING_FOLDER = "staticsites-cli";

// Data-api-builder related constants
export const DATA_API_BUILDER_BINARY_NAME = "DataApiBuilder";
Expand Down
10 changes: 2 additions & 8 deletions src/core/deploy-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export async function fetchClientVersionDefinition(releaseVersion: string): Prom

// TODO: get StaticSiteClient to remove zip files
// TODO: can these ZIPs be created under /tmp?
export function cleanUp(clientWorkingDir: string) {
export function cleanUp() {
const clean = (file: string) => {
const filepath = path.join(clientWorkingDir, file);
const filepath = path.join(process.cwd(), file);
if (fs.existsSync(filepath)) {
try {
fs.unlinkSync(filepath);
Expand All @@ -121,10 +121,4 @@ export function cleanUp(clientWorkingDir: string) {

clean(".\\app.zip");
clean(".\\api.zip");

if (fs.existsSync(clientWorkingDir)) {
try {
fs.rmdirSync(clientWorkingDir, { recursive: true });
} catch {}
}
}

0 comments on commit 90abd45

Please sign in to comment.