Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): keep alteration scripts folder writable by gid 0 #6328

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###### [STAGE] Build ######
FROM node:20-alpine as builder

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / main-dockerize

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
WORKDIR /etc/logto
ENV CI=true

Expand Down Expand Up @@ -37,9 +37,10 @@
RUN rm -rf .scripts pnpm-*.yaml packages/cloud

###### [STAGE] Seal ######
FROM node:20-alpine as app

Check warning on line 40 in Dockerfile

View workflow job for this annotation

GitHub Actions / main-dockerize

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
WORKDIR /etc/logto
COPY --from=builder /etc/logto .
RUN mkdir -p /etc/logto/packages/cli/alteration-scripts && chmod g+w /etc/logto/packages/cli/alteration-scripts
EXPOSE 3001
ENTRYPOINT ["npm", "run"]
CMD ["start"]
23 changes: 21 additions & 2 deletions packages/cli/src/commands/database/alteration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,27 @@ export const getAlterationFiles = async (): Promise<AlterationFile[]> => {
}

// We need to copy alteration files to execute in the CLI context to make `slonik` available
await fs.rm(localAlterationDirectory, { force: true, recursive: true });
await fs.cp(alterationDirectory, localAlterationDirectory, { recursive: true });
// Notice that we don't remove the folder,
// this ensures that the writabiliy remains (and also allows this to be a separately-mounted directory.
if (!existsSync(localAlterationDirectory)) {
await fs.mkdir(localAlterationDirectory, { recursive: true });
}

const oldFiles = await fs.readdir(localAlterationDirectory);
await Promise.all(
oldFiles.map(async (file) =>
fs.rm(path.join(localAlterationDirectory, file), { force: true, recursive: true })
)
);
const newFiles = await fs.readdir(alterationDirectory);
await Promise.all(
newFiles.map(async (file) =>
fs.cp(path.join(alterationDirectory, file), path.join(localAlterationDirectory, file), {
recursive: true,
preserveTimestamps: true,
})
)
);

const directory = await fs.readdir(localAlterationDirectory);
const files = directory.filter((file) => alterationFilenameRegex.test(file));
Expand Down
Loading