-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild.ts
More file actions
63 lines (44 loc) · 1.51 KB
/
Copy pathbuild.ts
File metadata and controls
63 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { execSync } from 'child_process';
import { readFileSync } from 'fs';
import packageJson from './package.json' with { type: 'json' };
function parseEnvFile(path: string): Record<string, string> {
const result: Record<string, string> = {};
const lines = readFileSync(path, 'utf-8').split('\n');
for (const line of lines) {
if (line.startsWith('#') || !line.includes('=')) continue;
const [key, ...rest] = line.split('=');
const trimmedKey = key.trim();
const trimmedValue = rest.join('=').trim();
result[trimmedKey] = trimmedValue;
}
return result;
}
function getNodeVersion(): string {
return packageJson.volta.node;
}
function main(): void {
const buildArgs: string[] = [];
const nodeVersion = getNodeVersion();
buildArgs.push('--build-arg', `NODE_VERSION=${nodeVersion}`);
const nodeDistrolessVersion = nodeVersion.split('.').at(0);
buildArgs.push(
'--build-arg',
`NODE_DISTROLESS_VERSION=${nodeDistrolessVersion}`
);
const envVars = parseEnvFile('.env.local');
for (const [key, value] of Object.entries(envVars)) {
buildArgs.push('--build-arg', `${key}=${value}`);
}
const cmd = [
'docker build',
...buildArgs,
'--secret id=gh_token,env=GH_TOKEN',
'--secret id=private_secret_key,env=PRIVATE_SECRET_KEY',
'-t ghcr.io/ccrsxx/portofolio:latest',
'.'
].join(' ');
process.env['GH_TOKEN'] = envVars['GH_TOKEN'];
process.env['PRIVATE_SECRET_KEY'] = envVars['PRIVATE_SECRET_KEY'];
execSync(cmd, { stdio: 'inherit' });
}
main();