Skip to content

Commit

Permalink
fix(arui-scripts): #156
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Komarov authored and Alexander Komarov committed Nov 7, 2023
1 parent 8d7d7fe commit 31f8827
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import exec from '../util/exec';
startScriptTemplate: startScript,
allowLocalDockerfile: false,
allowLocalStartScript: false,
allowLocalDockerIgnore: true,
});

await exec('echo "node_modules" >> .dockerignore');

await exec(getDockerBuildCommand({ tempDirName, imageFullName }));
await fs.remove(pathToTempDir);

Expand Down
1 change: 1 addition & 0 deletions packages/arui-scripts/src/commands/docker-build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getPruningCommand } from '../util/yarn';
startScriptTemplate: startScript,
allowLocalDockerfile: true,
allowLocalStartScript: true,
allowLocalDockerIgnore: false,
});

await fs.remove(configs.buildPath);
Expand Down
13 changes: 13 additions & 0 deletions packages/arui-scripts/src/commands/util/docker-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type PrepareFilesForDockerParams = {
pathToTempDir: string;
allowLocalDockerfile: boolean;
allowLocalStartScript: boolean;
allowLocalDockerIgnore: boolean;
};

export async function prepareFilesForDocker({
Expand All @@ -61,6 +62,7 @@ export async function prepareFilesForDocker({
pathToTempDir,
allowLocalDockerfile,
allowLocalStartScript,
allowLocalDockerIgnore,
}: PrepareFilesForDockerParams) {
await fs.emptyDir(pathToTempDir);

Expand All @@ -78,13 +80,24 @@ export async function prepareFilesForDocker({
? await fs.readFile(configs.localStartScript, 'utf8')
: startScriptTemplate;

const dockerIgnore =
allowLocalDockerIgnore &&
(configs.localDockerIgnore
? await fs
.readFile(configs.localDockerIgnore, 'utf8')
.then((ignores) => `${ignores}\nnode_modules`)
: 'node_modules');

await Promise.all([
fs.writeFile(path.join(pathToTempDir, 'Dockerfile'), dockerfile, 'utf8'),
fs.writeFile(path.join(pathToTempDir, 'nginx.conf'), nginxConf, 'utf8'),
fs.writeFile(path.join(pathToTempDir, 'start.sh'), startScript, {
encoding: 'utf8',
mode: 0o555,
}),
allowLocalDockerIgnore &&
configs.localDockerIgnore &&
fs.writeFile(configs.localDockerIgnore, dockerIgnore, 'utf-8'),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/arui-scripts/src/configs/app-configs/get-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function getDefaultAppContext(): AppContext {
const overridesPath = tryResolve(path.join(CWD, 'arui-scripts.overrides'));
const nginxConfFilePath = path.join(CWD, 'nginx.conf');
const dockerfileFilePath = path.join(CWD, 'Dockerfile');
const dockerIgnoreFilePath = path.join(CWD, '.dockerignore');
const startScriptFilePath = path.join(CWD, 'start.sh');

return {
Expand All @@ -127,6 +128,7 @@ export function getDefaultAppContext(): AppContext {
localNginxConf: fs.existsSync(nginxConfFilePath) ? nginxConfFilePath : null,
localDockerfile: fs.existsSync(dockerfileFilePath) ? dockerfileFilePath : null,
localStartScript: fs.existsSync(startScriptFilePath) ? startScriptFilePath : null,
localDockerIgnore: fs.existsSync(dockerIgnoreFilePath) ? dockerIgnoreFilePath : null,

// Эти пути зависят от других настроек, которые могут быть переопределены пользователем
publicPath: '',
Expand Down
1 change: 1 addition & 0 deletions packages/arui-scripts/src/configs/app-configs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export type AppContext = {
tsconfig: string | null;
localNginxConf: string | null;
localDockerfile: string | null;
localDockerIgnore: string | null;
localStartScript: string | null;

overridesPath: string[];
Expand Down

0 comments on commit 31f8827

Please sign in to comment.