dockerfile update + start scripts
parent
3eaad5e580
commit
feaf0cc0ba
43
Dockerfile
43
Dockerfile
|
@ -4,43 +4,42 @@ WORKDIR /app
|
|||
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
#RUN printf '\nAm rulat npm install!\n\n'
|
||||
#RUN echo '\nRezultat:\n'
|
||||
#RUN ls
|
||||
|
||||
|
||||
COPY . ./
|
||||
RUN npm run build
|
||||
|
||||
#RUN printf '\nAm copiat restul fisierelor si am rulat build!\n\n'
|
||||
#RUN echo '\nRezultat:\n'
|
||||
#RUN ls
|
||||
|
||||
# production environment
|
||||
FROM node:12
|
||||
COPY --from=builder /app/build ./build
|
||||
COPY --from=builder /app/tools/mockData.js ./build/api/
|
||||
COPY --from=builder /app/tools/createMockDb.js ./build/api/
|
||||
COPY --from=builder /app/tools/apiServer.js ./build/api/
|
||||
|
||||
#RUN printf '\nAm copiat fisierele din build in imaginea finala!\n\n'
|
||||
#RUN echo '\nRezultat:\n'
|
||||
#RUN ls
|
||||
RUN printf '\n\n- Copy application frontend files\n'
|
||||
COPY --from=builder /app/build ./application/front
|
||||
COPY --from=builder /app/start/front.sh ./application/front/
|
||||
RUN chmod +x application/front/front.sh
|
||||
|
||||
RUN printf '\n\n- Copy application api files\n'
|
||||
COPY --from=builder /app/tools/mockData.js ./application/api/
|
||||
COPY --from=builder /app/tools/createMockDb.js ./application/api/
|
||||
COPY --from=builder /app/tools/apiServer.js ./application/api/
|
||||
COPY --from=builder /app/start/api.sh ./application/api/
|
||||
RUN chmod +x application/api/api.sh
|
||||
|
||||
RUN printf '\n\n- Copy application starting script\n'
|
||||
COPY --from=builder /app/start/start.sh ./application/
|
||||
RUN chmod +x application/start.sh
|
||||
|
||||
#install static server || Alternativ se poate utiliza si http-server
|
||||
RUN npm install -g serve
|
||||
|
||||
WORKDIR /build
|
||||
WORKDIR /application/api
|
||||
RUN printf '\n\n- Install json-server in api directory\n'
|
||||
RUN npm install json-server --save-prod
|
||||
|
||||
RUN printf '\n- Am instalat json-server!\n\n'
|
||||
#RUN ls
|
||||
|
||||
WORKDIR /
|
||||
WORKDIR /application
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
#CMD ["sh", "-c", "node build/api/createMockDb.js && node build/api/apiServer.js && serve -s build -p 80"]
|
||||
CMD ["./start.sh"]
|
||||
#CMD ["sh", "-c", "node application/api/createMockDb.js && node application/api/apiServer.js && serve -s application/front -p 80"]
|
||||
#CMD ["serve", "-s", "build", "-p", "80"]
|
||||
|
||||
#CMD ["sh", "-c", "node build/api/createMockDb.js && node build/api/apiServer.js", "serve", "-s", "build", "-p", "80"]
|
||||
#CMD ["sh", "-c", "node application/api/createMockDb.js && node application/api/apiServer.js", "serve", "-s", "application/front", "-p", "80"]
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
echo "Welcome!"
|
||||
|
||||
echo "Create mock database..."
|
||||
node api/createMockDb.js
|
||||
|
||||
echo "Starting API JSON Server..."
|
||||
node api/apiServer.js
|
||||
|
||||
echo "DONE!"
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
echo "Welcome!"
|
||||
echo "Starting react-redux web app..."
|
||||
|
||||
serve -s front -p 80
|
||||
|
||||
echo "Terminated!"
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Start the first process
|
||||
./front/front.sh -D
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to start front: $status"
|
||||
exit $status
|
||||
fi
|
||||
|
||||
# Start the second process
|
||||
./api/api.sh -D
|
||||
status=$?
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to start api: $status"
|
||||
exit $status
|
||||
fi
|
||||
|
||||
# Naive check runs checks once a minute to see if either of the processes exited.
|
||||
# This illustrates part of the heavy lifting you need to do if you want to run
|
||||
# more than one service in a container. The container exits with an error
|
||||
# if it detects that either of the processes has exited.
|
||||
# Otherwise it loops forever, waking up every 60 seconds
|
||||
|
||||
while sleep 60; do
|
||||
ps aux |grep front/front.sh |grep -q -v grep
|
||||
PROCESS_1_STATUS=$?
|
||||
ps aux |grep api/api.sh |grep -q -v grep
|
||||
PROCESS_2_STATUS=$?
|
||||
# If the greps above find anything, they exit with 0 status
|
||||
# If they are not both 0, then something is wrong
|
||||
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
|
||||
echo "One of the processes has already exited."
|
||||
exit 1
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue