Skip to content

Commit 8c413b2

Browse files
Merge pull request #764 from contentstack/dev
Dev
2 parents acd3e95 + 053048e commit 8c413b2

File tree

15 files changed

+164
-74
lines changed

15 files changed

+164
-74
lines changed

.dockerignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
node_modules
2-
npm-debug.log
2+
npm-debug.log
3+
build/
4+
*.log
5+
.env
6+
.git
7+
.gitignore
8+
Dockerfile
9+
.dockerignore

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,6 @@ fileignoreconfig:
9191

9292
- filename: api/src/services/globalField.service.ts
9393
checksum: fbc0612dda1894fd55455c4adaa4b7016b01a73e5d4093a3a9dad471b434c2ec
94+
- filename: api/src/services/sitecore.service.ts
95+
checksum: ceaed6417b1b6fd2581f547cbc7e871900ecbae5557496b26f025781f323ba82
9496
version: "1.0"

api/Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
FROM --platform=linux/amd64 node:24.1.0-alpine3.22
1+
FROM node:24.4.1-alpine
22

33
WORKDIR /usr/src/app
44

55
COPY package*.json ./
66

7-
RUN npm install
7+
RUN npm install \
8+
&& addgroup -S nodeapp \
9+
&& adduser -S nodeapp -G nodeapp
810

911
COPY . .
1012

13+
# If your app writes to a build or other directory, create and set permissions here
14+
RUN mkdir -p /usr/src/app/build && chown -R nodeapp:nodeapp /usr/src/app
15+
16+
USER nodeapp
17+
1118
EXPOSE 5001
1219

13-
CMD [ "npm","run", "dev"]
20+
CMD [ "npm", "run", "dev" ]

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"homepage": "https://github.com/contentstack/migration-v2.git#readme",
2727
"dependencies": {
28-
"@contentstack/cli": "^1.34.0",
28+
"@contentstack/cli": "1.41.0",
2929
"@contentstack/cli-utilities": "^1.12.0",
3030
"@contentstack/json-rte-serializer": "^2.0.7",
3131
"@contentstack/marketplace-sdk": "^1.2.4",

api/src/services/migration.service.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,20 @@ const startTestMigration = async (req: Request): Promise<any> => {
327327
destinationStackId: project?.current_test_stack_id,
328328
});
329329
await taxonomyService?.createTaxonomy({
330-
orgId,
330+
orgId,
331331
projectId,
332-
stackId:project?.destination_stack_id,
332+
stackId: project?.destination_stack_id,
333333
current_test_stack_id: project?.current_test_stack_id,
334334
region,
335335
userId: user_id,
336336
});
337337
await globalFieldServie?.createGlobalField({
338338
region,
339-
user_id,
340-
stackId:project?.destination_stack_id,
339+
user_id,
340+
stackId: project?.destination_stack_id,
341341
current_test_stack_id: project?.current_test_stack_id,
342342
});
343-
343+
344344
switch (cms) {
345345
case CMS.SITECORE_V8:
346346
case CMS.SITECORE_V9:
@@ -361,6 +361,9 @@ const startTestMigration = async (req: Request): Promise<any> => {
361361
projectId,
362362
project
363363
);
364+
await siteCoreService?.createEnvironment(
365+
project?.current_test_stack_id
366+
)
364367
await siteCoreService?.createVersionFile(
365368
project?.current_test_stack_id
366369
);
@@ -563,17 +566,17 @@ const startMigration = async (req: Request): Promise<any> => {
563566
destinationStackId: project?.destination_stack_id,
564567
});
565568
await taxonomyService?.createTaxonomy({
566-
orgId,
567-
projectId,
568-
stackId:project?.destination_stack_id,
569-
current_test_stack_id: project?.destination_stack_id,
570-
region,
571-
userId: user_id,
569+
orgId,
570+
projectId,
571+
stackId: project?.destination_stack_id,
572+
current_test_stack_id: project?.destination_stack_id,
573+
region,
574+
userId: user_id,
572575
});
573576
await globalFieldServie?.createGlobalField({
574577
region,
575-
user_id,
576-
stackId:project?.destination_stack_id,
578+
user_id,
579+
stackId: project?.destination_stack_id,
577580
current_test_stack_id: project?.destination_stack_id,
578581
});
579582
switch (cms) {
@@ -732,7 +735,7 @@ const getAuditData = async (req: Request): Promise<any> => {
732735
if (!safeEntriesSelectFieldPath.startsWith(auditLogPath)) {
733736
throw new BadRequestError('Access to this file is not allowed.');
734737
}
735-
738+
736739
const fileContent = await fsPromises?.readFile(safeEntriesSelectFieldPath, 'utf8');
737740
try {
738741
if (typeof fileContent === 'string') {

api/src/services/sitecore.service.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getSafePath } from '../utils/sanitize-path.utils.js';
1616
const append = 'a';
1717
const baseDirName = MIGRATION_DATA_CONFIG.DATA;
1818
const {
19+
ENVIRONMENTS_DIR_NAME,
1920
ENTRIES_DIR_NAME,
2021
LOCALE_DIR_NAME,
2122
LOCALE_MASTER_LOCALE,
@@ -24,6 +25,7 @@ const {
2425
ASSETS_DIR_NAME,
2526
ASSETS_FILE_NAME,
2627
ASSETS_SCHEMA_FILE,
28+
ENVIRONMENTS_FILE_NAME
2729
} = MIGRATION_DATA_CONFIG;
2830

2931
const idCorrector = ({ id }: any) => {
@@ -159,7 +161,7 @@ const createAssets = async ({
159161
const blobPath: any = path.join(packagePath, 'blob', 'master');
160162
const assetsPath = read(blobPath);
161163
if (assetsPath?.length) {
162-
const isIdPresent = assetsPath?.find((ast) =>{
164+
const isIdPresent = assetsPath?.find((ast) => {
163165
return ast?.includes(metaData?.id)
164166
}
165167
);
@@ -307,8 +309,7 @@ const createEntry = async ({
307309
for await (const ctType of contentTypes) {
308310
const message = getLogMessage(
309311
srcFunc,
310-
`Transforming entries of Content Type ${
311-
keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid
312+
`Transforming entries of Content Type ${keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid
312313
} has begun.`,
313314
{}
314315
);
@@ -407,7 +408,7 @@ const createEntry = async ({
407408
);
408409
const mapperCt: string =
409410
keyMapper?.[ctType?.contentstackUid] !== '' &&
410-
keyMapper?.[ctType?.contentstackUid] !== undefined
411+
keyMapper?.[ctType?.contentstackUid] !== undefined
411412
? keyMapper?.[ctType?.contentstackUid]
412413
: ctType?.contentstackUid;
413414
const fileMeta = { '1': `${newLocale}.json` };
@@ -422,8 +423,7 @@ const createEntry = async ({
422423
} else {
423424
const message = getLogMessage(
424425
srcFunc,
425-
`No entries found for the content type ${
426-
keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid
426+
`No entries found for the content type ${keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid
427427
}.`,
428428
{}
429429
);
@@ -530,9 +530,22 @@ const createVersionFile = async (destinationStackId: string) => {
530530
);
531531
};
532532

533+
const createEnvironment = async (destinationStackId: string) => {
534+
const baseDir = path.join(baseDirName, destinationStackId);
535+
const environmentSave = path.join(baseDir, ENVIRONMENTS_DIR_NAME);
536+
const environmentFile = path.join(environmentSave, ENVIRONMENTS_FILE_NAME);
537+
538+
// Ensure the directory exists
539+
await fs.promises.mkdir(environmentSave, { recursive: true });
540+
541+
// Write an empty environments file (or replace {} with your actual data)
542+
await fs.promises.writeFile(environmentFile, JSON.stringify({}), 'utf8');
543+
}
544+
533545
export const siteCoreService = {
534546
createEntry,
535547
createAssets,
536548
createLocale,
537549
createVersionFile,
550+
createEnvironment
538551
};

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
volumes:
1111
- ${CMS_DATA_PATH}:${CONTAINER_PATH}
1212
- shared_data:/app/extracted_files
13+
security_opt:
14+
- no-new-privileges:true
1315

1416
upload-api:
1517
container_name: migration-upload-api
@@ -21,6 +23,8 @@ services:
2123
volumes:
2224
- ${CMS_DATA_PATH}:${CONTAINER_PATH}
2325
- shared_data:/app/extracted_files
26+
security_opt:
27+
- no-new-privileges:true
2428

2529
ui:
2630
container_name: migration-ui
@@ -29,6 +33,8 @@ services:
2933
ports:
3034
- "3000:3000"
3135
restart: always
36+
security_opt:
37+
- no-new-privileges:true
3238

3339
volumes:
34-
shared_data:
40+
shared_data:

ui/.dockerignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
node_modules
22
npm-debug.log
3-
build
3+
Dockerfile
4+
build/
5+
*.log
6+
.git
7+
.gitignore
8+
.dockerignore
9+
.env

ui/Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
FROM --platform=linux/amd64 node:22-alpine
1+
FROM node:22-alpine
22

33
WORKDIR /usr/src/app
44

55
COPY package*.json ./
66

7-
RUN apk update && apk upgrade && npm install
7+
RUN apk update && apk upgrade \
8+
&& npm install \
9+
&& addgroup -S nodeapp \
10+
&& adduser -S nodeapp -G nodeapp
811

912
COPY . .
1013

14+
# Ensure permissions for nodeapp user
15+
RUN chown -R nodeapp:nodeapp /usr/src/app
16+
17+
USER nodeapp
18+
1119
EXPOSE 3000
1220

13-
CMD [ "npm","run", "start"]
21+
CMD [ "npm", "run", "start" ]

upload-api/Dockerfile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
# Use an official Node.js runtime as a base image
2-
FROM --platform=linux/amd64 node:24.1.0-alpine3.22
1+
FROM node:24.4.1-alpine
32

4-
# Set the working directory in the container
53
WORKDIR /app
64

7-
# Copy package.json and package-lock.json to the working directory
85
COPY package*.json ./
96

10-
# Install application dependencies
11-
RUN npm install
7+
RUN npm install \
8+
&& addgroup -S nodeapp \
9+
&& adduser -S nodeapp -G nodeapp
1210

13-
# Copy the application code to the container
1411
COPY . .
1512

16-
# Expose the port your app will run on
13+
RUN mkdir -p /app/build \
14+
&& mkdir -p /app/extracted_files \
15+
&& chown -R nodeapp:nodeapp /app
16+
17+
COPY docker-entrypoint.sh /usr/local/bin/
18+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
19+
20+
USER nodeapp
21+
1722
EXPOSE 4002
1823

19-
# Define the command to run your application
20-
CMD ["npm", "run", "start"]
24+
ENTRYPOINT ["docker-entrypoint.sh"]
25+
26+
CMD ["npm", "run", "start"]

0 commit comments

Comments
 (0)