diff --git a/Dockerfile b/Dockerfile index 2389176..7d385b4 100644 --- a/Dockerfile +++ b/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"] \ No newline at end of file +#CMD ["sh", "-c", "node application/api/createMockDb.js && node application/api/apiServer.js", "serve", "-s", "application/front", "-p", "80"] \ No newline at end of file diff --git a/start/api.sh b/start/api.sh new file mode 100644 index 0000000..c63aff6 --- /dev/null +++ b/start/api.sh @@ -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!" \ No newline at end of file diff --git a/start/front.sh b/start/front.sh new file mode 100644 index 0000000..b2f13da --- /dev/null +++ b/start/front.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "Welcome!" +echo "Starting react-redux web app..." + +serve -s front -p 80 + +echo "Terminated!" \ No newline at end of file diff --git a/start/start.sh b/start/start.sh new file mode 100644 index 0000000..d457fd8 --- /dev/null +++ b/start/start.sh @@ -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 \ No newline at end of file