wait for db before starting the server (#14)

This commit is contained in:
JannikStreek 2024-03-05 15:17:52 +01:00 committed by GitHub
parent 2703da66c8
commit 4cd243335d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -5,3 +5,4 @@
!package.json !package.json
!tsconfig.build.json !tsconfig.build.json
!tsconfig.json !tsconfig.json
!entrypoint.sh

View File

@ -12,17 +12,20 @@ RUN npm run build
FROM base as production FROM base as production
RUN apt-get update
RUN apt-get install -y postgresql-client
ENV NODE_ENV=production ENV NODE_ENV=production
USER node USER node
WORKDIR /home/node/app WORKDIR /home/node/app
COPY package.json package-lock.json ./ COPY package.json package-lock.json entrypoint.sh ./
RUN npm ci RUN npm ci
COPY --from=production_buildstage /home/node/app/dist /home/node/app/dist COPY --from=production_buildstage /home/node/app/dist /home/node/app/dist
ENTRYPOINT ["npm", "run", "start:prod"] CMD ["./entrypoint.sh"]
FROM base as development FROM base as development

12
entrypoint.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
echo "Looking for the database ..."
while ! pg_isready -q -d $STORAGE_URI
do
echo "Waiting for database."
sleep 2
done
echo "Found database."
echo "Starting the application..."
npm run start:prod