@akanjs/config 0.9.13 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,6 +31,7 @@ __export(akanConfig_exports, {
31
31
  getLibConfig: () => getLibConfig,
32
32
  getNextConfig: () => getNextConfig,
33
33
  makeAppConfig: () => makeAppConfig,
34
+ makeDockerfile: () => makeDockerfile,
34
35
  makeLibConfig: () => makeLibConfig
35
36
  });
36
37
  module.exports = __toCommonJS(akanConfig_exports);
@@ -43,43 +44,11 @@ const makeAppConfig = (config, props) => {
43
44
  rootLib: config.rootLib,
44
45
  libs: config.libs ?? [],
45
46
  backend: {
46
- dockerfile: config.backend?.dockerfile ?? `FROM node:22-slim
47
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
48
- RUN apt-get update && apt-get upgrade -y && apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
49
- ARG TARGETARCH
50
- RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
51
- RUN mkdir -p /workspace
52
- WORKDIR /workspace
53
- COPY ./package.json ./package.json
54
- RUN npx pnpm i --prod
55
- COPY . .
56
- ENV PORT 8080
57
- ENV NODE_OPTIONS=--max_old_space_size=8192
58
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
59
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
60
- ENV NEXT_PUBLIC_APP_NAME=${name}
61
- ENV NEXT_PUBLIC_ENV=${env}
62
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
63
- CMD ["node", "main.js"]`,
47
+ docker: makeDockerfile("backend", config.backend?.docker ?? {}, props),
64
48
  explicitDependencies: config.backend?.explicitDependencies ?? []
65
49
  },
66
50
  frontend: {
67
- dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
68
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
69
- RUN apk --no-cache add git
70
- RUN mkdir -p /workspace
71
- WORKDIR /workspace
72
- COPY ./package.json ./package.json
73
- RUN npx pnpm i --prod
74
- COPY . .
75
- ENV PORT 4200
76
- ENV NODE_OPTIONS=--max_old_space_size=8192
77
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
78
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
79
- ENV NEXT_PUBLIC_APP_NAME=${name}
80
- ENV NEXT_PUBLIC_ENV=${env}
81
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
82
- CMD ["npm", "start"]`,
51
+ docker: makeDockerfile("frontend", config.frontend?.docker ?? {}, props),
83
52
  nextConfig: (0, import_nextConfig.withBase)(
84
53
  name,
85
54
  config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
@@ -139,3 +108,85 @@ const getNextConfig = (configImp, appData) => {
139
108
  const akanConfig = makeAppConfig(config, props);
140
109
  return akanConfig.frontend.nextConfig;
141
110
  };
111
+ const getDockerRunScripts = (runs) => {
112
+ return runs.map((run) => {
113
+ if (typeof run === "string")
114
+ return `RUN ${run}`;
115
+ else
116
+ return Object.entries(run).map(([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then ${script}; fi`).join("\n");
117
+ });
118
+ };
119
+ const getDockerImageScript = (image) => {
120
+ if (typeof image === "string")
121
+ return `FROM ${image}`;
122
+ else
123
+ return Object.entries(image).map(([arch, image2]) => `FROM ${image2} AS ${arch}`).join("\n");
124
+ };
125
+ const makeDockerfile = (type, config, props) => {
126
+ const { name, repoName, serveDomain, env } = props;
127
+ if (config.content)
128
+ return { content: config.content, image: {}, preRuns: [], postRuns: [], command: [] };
129
+ const preRunScripts = getDockerRunScripts(config.preRuns ?? []);
130
+ const postRunScripts = getDockerRunScripts(config.postRuns ?? []);
131
+ if (type === "backend") {
132
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-slim";
133
+ const command = config.command ?? ["node", "main.js"];
134
+ const content = `${imageScript}
135
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
136
+ RUN apt-get update && apt-get upgrade -y
137
+ RUN apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
138
+ ARG TARGETARCH
139
+ RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
140
+ ${preRunScripts.join("\n")}
141
+ RUN mkdir -p /workspace
142
+ WORKDIR /workspace
143
+ COPY ./package.json ./package.json
144
+ RUN npx pnpm i --prod
145
+ COPY . .
146
+ ENV PORT 8080
147
+ ENV NODE_OPTIONS=--max_old_space_size=8192
148
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
149
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
150
+ ENV NEXT_PUBLIC_APP_NAME=${name}
151
+ ENV NEXT_PUBLIC_ENV=${env}
152
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
153
+ ${postRunScripts.join("\n")}
154
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
155
+ return {
156
+ content,
157
+ image: imageScript,
158
+ preRuns: config.preRuns ?? [],
159
+ postRuns: config.postRuns ?? [],
160
+ command
161
+ };
162
+ } else {
163
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-alpine";
164
+ const command = config.command ?? ["npm", "start"];
165
+ const content = `${imageScript}
166
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
167
+ ARG TARGETARCH
168
+ RUN apk --no-cache add git
169
+ ${preRunScripts.join("\n")}
170
+ RUN mkdir -p /workspace
171
+ WORKDIR /workspace
172
+ COPY ./package.json ./package.json
173
+ RUN npx pnpm i --prod
174
+ COPY . .
175
+ ENV PORT 4200
176
+ ENV NODE_OPTIONS=--max_old_space_size=8192
177
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
178
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
179
+ ENV NEXT_PUBLIC_APP_NAME=${name}
180
+ ENV NEXT_PUBLIC_ENV=${env}
181
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
182
+ ${postRunScripts.join("\n")}
183
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
184
+ return {
185
+ content,
186
+ image: imageScript,
187
+ preRuns: config.preRuns ?? [],
188
+ postRuns: config.postRuns ?? [],
189
+ command
190
+ };
191
+ }
192
+ };
@@ -7,43 +7,11 @@ const makeAppConfig = (config, props) => {
7
7
  rootLib: config.rootLib,
8
8
  libs: config.libs ?? [],
9
9
  backend: {
10
- dockerfile: config.backend?.dockerfile ?? `FROM node:22-slim
11
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
12
- RUN apt-get update && apt-get upgrade -y && apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
13
- ARG TARGETARCH
14
- RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
15
- RUN mkdir -p /workspace
16
- WORKDIR /workspace
17
- COPY ./package.json ./package.json
18
- RUN npx pnpm i --prod
19
- COPY . .
20
- ENV PORT 8080
21
- ENV NODE_OPTIONS=--max_old_space_size=8192
22
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
23
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
24
- ENV NEXT_PUBLIC_APP_NAME=${name}
25
- ENV NEXT_PUBLIC_ENV=${env}
26
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
27
- CMD ["node", "main.js"]`,
10
+ docker: makeDockerfile("backend", config.backend?.docker ?? {}, props),
28
11
  explicitDependencies: config.backend?.explicitDependencies ?? []
29
12
  },
30
13
  frontend: {
31
- dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
32
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
33
- RUN apk --no-cache add git
34
- RUN mkdir -p /workspace
35
- WORKDIR /workspace
36
- COPY ./package.json ./package.json
37
- RUN npx pnpm i --prod
38
- COPY . .
39
- ENV PORT 4200
40
- ENV NODE_OPTIONS=--max_old_space_size=8192
41
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
42
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
43
- ENV NEXT_PUBLIC_APP_NAME=${name}
44
- ENV NEXT_PUBLIC_ENV=${env}
45
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
46
- CMD ["npm", "start"]`,
14
+ docker: makeDockerfile("frontend", config.frontend?.docker ?? {}, props),
47
15
  nextConfig: withBase(
48
16
  name,
49
17
  config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
@@ -103,10 +71,93 @@ const getNextConfig = (configImp, appData) => {
103
71
  const akanConfig = makeAppConfig(config, props);
104
72
  return akanConfig.frontend.nextConfig;
105
73
  };
74
+ const getDockerRunScripts = (runs) => {
75
+ return runs.map((run) => {
76
+ if (typeof run === "string")
77
+ return `RUN ${run}`;
78
+ else
79
+ return Object.entries(run).map(([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then ${script}; fi`).join("\n");
80
+ });
81
+ };
82
+ const getDockerImageScript = (image) => {
83
+ if (typeof image === "string")
84
+ return `FROM ${image}`;
85
+ else
86
+ return Object.entries(image).map(([arch, image2]) => `FROM ${image2} AS ${arch}`).join("\n");
87
+ };
88
+ const makeDockerfile = (type, config, props) => {
89
+ const { name, repoName, serveDomain, env } = props;
90
+ if (config.content)
91
+ return { content: config.content, image: {}, preRuns: [], postRuns: [], command: [] };
92
+ const preRunScripts = getDockerRunScripts(config.preRuns ?? []);
93
+ const postRunScripts = getDockerRunScripts(config.postRuns ?? []);
94
+ if (type === "backend") {
95
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-slim";
96
+ const command = config.command ?? ["node", "main.js"];
97
+ const content = `${imageScript}
98
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
99
+ RUN apt-get update && apt-get upgrade -y
100
+ RUN apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
101
+ ARG TARGETARCH
102
+ RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
103
+ ${preRunScripts.join("\n")}
104
+ RUN mkdir -p /workspace
105
+ WORKDIR /workspace
106
+ COPY ./package.json ./package.json
107
+ RUN npx pnpm i --prod
108
+ COPY . .
109
+ ENV PORT 8080
110
+ ENV NODE_OPTIONS=--max_old_space_size=8192
111
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
112
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
113
+ ENV NEXT_PUBLIC_APP_NAME=${name}
114
+ ENV NEXT_PUBLIC_ENV=${env}
115
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
116
+ ${postRunScripts.join("\n")}
117
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
118
+ return {
119
+ content,
120
+ image: imageScript,
121
+ preRuns: config.preRuns ?? [],
122
+ postRuns: config.postRuns ?? [],
123
+ command
124
+ };
125
+ } else {
126
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-alpine";
127
+ const command = config.command ?? ["npm", "start"];
128
+ const content = `${imageScript}
129
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
130
+ ARG TARGETARCH
131
+ RUN apk --no-cache add git
132
+ ${preRunScripts.join("\n")}
133
+ RUN mkdir -p /workspace
134
+ WORKDIR /workspace
135
+ COPY ./package.json ./package.json
136
+ RUN npx pnpm i --prod
137
+ COPY . .
138
+ ENV PORT 4200
139
+ ENV NODE_OPTIONS=--max_old_space_size=8192
140
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
141
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
142
+ ENV NEXT_PUBLIC_APP_NAME=${name}
143
+ ENV NEXT_PUBLIC_ENV=${env}
144
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
145
+ ${postRunScripts.join("\n")}
146
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
147
+ return {
148
+ content,
149
+ image: imageScript,
150
+ preRuns: config.preRuns ?? [],
151
+ postRuns: config.postRuns ?? [],
152
+ command
153
+ };
154
+ }
155
+ };
106
156
  export {
107
157
  getAppConfig,
108
158
  getLibConfig,
109
159
  getNextConfig,
110
160
  makeAppConfig,
161
+ makeDockerfile,
111
162
  makeLibConfig
112
163
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/config",
3
- "version": "0.9.13",
3
+ "version": "0.9.14",
4
4
  "sourceType": "module",
5
5
  "module": {
6
6
  "access": "public"
@@ -1,7 +1,8 @@
1
- import type { AppConfig, AppConfigResult, DeepPartial, LibConfigResult, RunnerProps } from "@akanjs/config";
1
+ import type { AppConfig, AppConfigResult, DeepPartial, DockerConfig, LibConfigResult, RunnerProps } from "@akanjs/config";
2
2
  import type { NextConfig } from "next";
3
3
  export declare const makeAppConfig: (config: DeepPartial<AppConfigResult>, props: RunnerProps) => AppConfigResult;
4
4
  export declare const getAppConfig: (appRoot: string, props: RunnerProps) => Promise<AppConfigResult>;
5
5
  export declare const makeLibConfig: (config: DeepPartial<LibConfigResult>, props: RunnerProps) => LibConfigResult;
6
6
  export declare const getLibConfig: (libRoot: string, props: RunnerProps) => Promise<LibConfigResult>;
7
7
  export declare const getNextConfig: (configImp: AppConfig, appData: any) => NextConfig | (() => Promise<NextConfig> | NextConfig);
8
+ export declare const makeDockerfile: (type: "backend" | "frontend", config: DeepPartial<DockerConfig>, props: RunnerProps) => DockerConfig;
package/src/types.d.ts CHANGED
@@ -11,15 +11,28 @@ export type Arch = "amd64" | "arm64";
11
11
  export type ExplicitDependencies = string[] | {
12
12
  [key in Arch]: string[];
13
13
  };
14
+ export interface DockerConfig {
15
+ content: string;
16
+ image: string | {
17
+ [key in Arch]?: string;
18
+ };
19
+ preRuns: (string | {
20
+ [key in Arch]?: string;
21
+ })[];
22
+ postRuns: (string | {
23
+ [key in Arch]?: string;
24
+ })[];
25
+ command: string[];
26
+ }
14
27
  export interface AppConfigResult {
15
28
  rootLib?: string;
16
29
  libs: string[];
17
30
  backend: {
18
- dockerfile: string;
31
+ docker: DockerConfig;
19
32
  explicitDependencies: ExplicitDependencies;
20
33
  };
21
34
  frontend: {
22
- dockerfile: string;
35
+ docker: DockerConfig;
23
36
  nextConfig: NextConfig | (() => Promise<NextConfig> | NextConfig);
24
37
  routes?: {
25
38
  basePath?: string;