Skip to content

Commit

Permalink
refactor(docker): Exit app when we can't create the data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenn92 committed Jan 25, 2024
1 parent 0391745 commit 2438460
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ RUN rm -rf .yarn && \
rm -rf /opt/yarn-* && \
chown -R node:node /opt/ && \
chmod -R 755 /opt/ && \
# data dir
mkdir -m 777 /opt/data && \
mkdir -m 777 /opt/data/logs
mkdir -m 777 /opt/data/logs && \
chown -R node:node /opt/data

# Final build
FROM node:20-alpine3.19
Expand Down Expand Up @@ -87,7 +89,8 @@ RUN corepack install && \
corepack enable && \
apk add supervisor && \
chown node:node /opt && \
chmod 755 /opt && \
# This is required for docker user directive to work
chmod 777 /opt && \
mkdir -m 777 /.cache

USER node
Expand Down
20 changes: 13 additions & 7 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ async function bootstrap() {
}

function createDataDirectoryStructure(): void {
const dir = path.join(__dirname, `../../data/logs`);
try {
const dir = path.join(__dirname, `../../data/logs`);

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, {
recursive: true,
mode: 0o777,
});
console.log(`Data directory structure created.`);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, {
recursive: true,
mode: 0o777,
});
}
} catch (err) {
console.error(
'Could not create data directory. Make sure your permissions are set correctly.',
);
process.exit(0);
}
}

Expand Down

0 comments on commit 2438460

Please sign in to comment.