Skip to content

Commit

Permalink
chore: lighten docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jun 20, 2024
1 parent f9f17d3 commit 5331ac4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ jobs:

- run: docker build . -t magnito --build-arg VERSION=0.0.0
- run: docker run -d --name test --network magnito-test_default magnito
- uses: mxschmitt/action-tmate@v3
- run: count=0 && until [ "$(docker inspect --format='{{json .State.Health.Status}}' test)" == "\"healthy\"" ] || [ $count -eq 30 ]; do sleep 1; count=$((count + 1)); done && [ $count -ne 30 ]
- run: docker stop test
23 changes: 8 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ FROM node:20-alpine

WORKDIR /usr/src/app

RUN apk add sudo
RUN echo '%node ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

ARG CLIENT_PORT=5001

ENV PORT=5000
Expand All @@ -40,26 +37,22 @@ ENV SMTP_PORT=2500
ENV SMTP_USER=fake_mail_user
ENV SMTP_PASS=fake_mail_password

COPY package.json .
COPY --from=builder /usr/src/app/client/out ./client/out
COPY --chown=node package.json .
COPY --chown=node --from=builder /usr/src/app/client/out ./client/out
COPY --chown=node server/package.json server/package-lock.json ./server/

COPY server/package.json server/package-lock.json ./server/
RUN npm ci --omit=dev --prefix server

COPY --from=builder /usr/src/app/server/index.js ./server/index.js
COPY --from=builder /usr/src/app/server/node_modules/.prisma ./server/node_modules/.prisma
COPY --from=builder /usr/src/app/server/prisma ./server/prisma
COPY --chown=node --from=builder /usr/src/app/server/index.js ./server/index.js
COPY --chown=node --from=builder /usr/src/app/server/node_modules/.prisma ./server/node_modules/.prisma
COPY --chown=node --from=builder /usr/src/app/server/prisma ./server/prisma
COPY --chown=node --from=builder /usr/src/app/data ./data
RUN apk --no-cache add curl
COPY --from=builder /usr/src/app/data ./data

RUN chown -R node:node /usr/src/app

HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD curl -f http://localhost:$PORT/health && curl -f http://localhost:$CLIENT_PORT || exit 1
HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget --no-verbose --tries=1 --spider http://localhost:$PORT/health || exit 1

EXPOSE ${PORT} ${CLIENT_PORT}
VOLUME ["/usr/src/app/data"]

USER node
ENTRYPOINT ["sh", "-c", "sudo chown -R node /usr/src/app/data && ls -l /usr/src/app && exec \"$@\"", "--"]

CMD ["npm", "start"]

0 comments on commit 5331ac4

Please sign in to comment.