Stabilize Cloud Run startup order

This commit is contained in:
Flatlogic Bot 2026-05-07 12:54:17 +03:00
parent 3c74c2e686
commit c6117dcf4c
4 changed files with 39 additions and 13 deletions

View File

@ -72,14 +72,23 @@ ENV APP_SHELL_PORT=4000
CMD ["sh", "-c", "\
yarn --cwd /app/frontend dev & echo $! > /app/pids/frontend.pid && \
yarn --cwd /app/backend start & echo $! > /app/pids/backend.pid && \
sleep 10 && nginx -g 'daemon off;' & \
NGINX_PID=$! && \
echo 'Waiting for backend (port 3000) to be available...' && \
set -e; \
echo 'Preparing repository before starting app processes...' ; \
yarn --cwd /app/app-shell init-repo; \
yarn --cwd /app/frontend dev & echo $! > /app/pids/frontend.pid; \
yarn --cwd /app/backend start & echo $! > /app/pids/backend.pid; \
APP_SHELL_SKIP_REPO_INIT=true yarn --cwd /app/app-shell start & echo $! > /app/pids/app-shell.pid; \
echo 'Waiting for frontend (port 3001) to be available...' ; \
while ! nc -z localhost ${FRONT_PORT}; do \
sleep 2; \
done; \
echo 'Waiting for backend (port 3000) to be available...' ; \
while ! nc -z localhost ${BACKEND_PORT}; do \
sleep 2; \
done && \
echo 'Backend is up. Starting app_shell for Git check...' && \
yarn --cwd /app/app-shell start && \
wait $NGINX_PID"]
done; \
echo 'Waiting for app_shell (port 4000) to be available...' ; \
while ! nc -z localhost ${APP_SHELL_PORT}; do \
sleep 2; \
done; \
echo 'All app processes are up. Starting nginx...' ; \
exec nginx -g 'daemon off;'"]

View File

@ -2,6 +2,7 @@
"name": "app-shell",
"description": "app-shell",
"scripts": {
"init-repo": "node ./src/init-repo.js",
"start": "node ./src/index.js"
},
"dependencies": {

View File

@ -32,8 +32,7 @@ function runGitCheck() {
})
.catch(err => {
console.error('Error during repo initialization:', err);
// Optionally exit the process if Git check is critical:
// process.exit(1);
process.exit(1);
});
}
@ -48,7 +47,8 @@ app.use('/vcs', vcsRoutes);
// Start the app_shell server
startServer();
// Now perform Git check
runGitCheck();
if (process.env.APP_SHELL_SKIP_REPO_INIT !== 'true') {
runGitCheck();
}
module.exports = app;

View File

@ -0,0 +1,16 @@
const VCS = require('./services/vcs');
const projectId = '32694';
VCS.initRepo(projectId)
.then((result) => {
if (result && result.message) {
console.log(result.message);
} else {
console.log(result);
}
})
.catch((error) => {
console.error('Error during repo initialization:', error);
process.exit(1);
});