forked from noxious/server
Moved bash code into .sh file
This commit is contained in:
parent
67a4c6763b
commit
9ea12ee458
16
Dockerfile
16
Dockerfile
@ -16,9 +16,6 @@ COPY package*.json ./
|
||||
# Install application dependencies
|
||||
RUN npm install
|
||||
|
||||
# Import migrations
|
||||
RUN npx mikro-orm migration:up
|
||||
|
||||
# Copy the rest of your application code to the container
|
||||
COPY . .
|
||||
|
||||
@ -28,16 +25,9 @@ RUN npm run build
|
||||
# Expose the ports your Node.js application, Redis, and MySQL will listen on
|
||||
EXPOSE 80 6379 3306
|
||||
|
||||
# Create a shell script to run Redis, MySQL, run migrations, and start the application in a tmux session
|
||||
RUN echo '#!/bin/sh' > /usr/src/start.sh && \
|
||||
echo 'redis-server --daemonize yes' >> /usr/src/start.sh && \
|
||||
echo 'mysqld --user=mysql --datadir=/var/lib/mysql &' >> /usr/src/start.sh && \
|
||||
echo 'sleep 10' >> /usr/src/start.sh && \
|
||||
echo 'npx prisma migrate deploy' >> /usr/src/start.sh && \
|
||||
echo 'tmux new-session -d -s nodeapp "node dist/server.js"' >> /usr/src/start.sh && \
|
||||
echo 'echo "App is running in tmux session. Attach with: tmux attach-session -t nodeapp"' >> /usr/src/start.sh && \
|
||||
echo 'tail -f /dev/null' >> /usr/src/start.sh && \
|
||||
chmod +x /usr/src/start.sh
|
||||
# Copy and make the startup script executable
|
||||
COPY docker-start.sh /usr/src/start.sh
|
||||
RUN chmod +x /usr/src/start.sh
|
||||
|
||||
# Use the shell script as the entry point
|
||||
CMD ["/usr/src/start.sh"]
|
24
docker-start.sh
Normal file
24
docker-start.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Start Redis in the background
|
||||
redis-server --daemonize yes
|
||||
|
||||
# Start MySQL
|
||||
mysqld --user=mysql --datadir=/var/lib/mysql &
|
||||
|
||||
# Wait for MySQL to be ready
|
||||
while ! mysqladmin ping -h localhost --silent; do
|
||||
echo "Waiting for MySQL to be ready..."
|
||||
sleep 2
|
||||
done
|
||||
echo "MySQL is ready!"
|
||||
|
||||
# Run database migrations
|
||||
npx mikro-orm migration:up
|
||||
|
||||
# Start the Node.js application in a tmux session
|
||||
tmux new-session -d -s nodeapp "node dist/server.js"
|
||||
echo "App is running in tmux session. Attach with: tmux attach-session -t nodeapp"
|
||||
|
||||
# Keep container running
|
||||
tail -f /dev/null
|
Loading…
x
Reference in New Issue
Block a user