Skip to content

Commit

Permalink
[CONFIG] [Docker] building process re-organized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Diaz committed Jun 12, 2024
1 parent 001fd84 commit 26f7ae9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
74 changes: 58 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,42 @@ RUN npm install -g --ignore-scripts markdownlint-cli
# [!TIP] Use a bind-mount to "/app" to override following "copys"
# for lint and test against "current" sources in this stage

# YAML sources
COPY ./.github ${WORKDIR}/
COPY ./compose.yaml ${WORKDIR}/

# Markdown sources
COPY ./docs ${WORKDIR}/
COPY ./README.md ${WORKDIR}/
COPY ./LICENSE.md ${WORKDIR}/
COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/

# Code source
COPY ./src ${WORKDIR}/src
COPY ./package.json ${WORKDIR}/package.json
COPY ./package-lock.json ${WORKDIR}/package-lock.json
COPY ./Makefile ${WORKDIR}/

# code linting conf
COPY ./.prettierrc ${WORKDIR}/
COPY ./.prettierignore ${WORKDIR}/
COPY ./.eslintrc ${WORKDIR}/
COPY ./.eslintignore ${WORKDIR}/

# markdownlint conf
COPY ./.markdownlint.yaml ${WORKDIR}/

# yamllint conf
COPY ./.yamllint ${WORKDIR}/
COPY ./.yamlignore ${WORKDIR}/

CMD ["make", "lint"]

###############################################################################
FROM base AS development

###############################################################################
FROM development AS builder
ENV WORKDIR=/app
WORKDIR ${WORKDIR}

COPY ./src ${WORKDIR}/src
COPY ./package.json ${WORKDIR}/package.json
Expand All @@ -35,45 +64,58 @@ COPY ./Makefile ${WORKDIR}/
COPY ./tsconfig.json ${WORKDIR}/tsconfig.json

RUN npm ci --verbose --ignore-scripts
RUN ls -alh

# CMD []
###############################################################################
FROM development AS builder

ENV WORKDIR=/app
WORKDIR ${WORKDIR}

RUN npm run build

CMD ["ls", "-alh"]

###############################################################################
### In testing stage, can't use USER, due permissions issue
## in github actions environment:
##
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
##
FROM builder AS testing
FROM development AS testing

ENV LOG_LEVEL=info
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}

WORKDIR /app

COPY ./.eslintrc /app/.eslintrc
COPY ./.prettierrc /app/.prettierrc
COPY ./jest.config.ts /app/jest.config.ts
COPY --from=builder /app/node_modules /app/node_modules
RUN ls -alh

CMD ["npm", "run", "test"]
CMD ["make", "test"]

###############################################################################
### In production stage
## in the production phase, "good practices" such as
## WORKSPACE and USER are maintained
##
FROM builder AS production
FROM base AS production

ENV NODE_ENV=production
ENV LOG_LEVEL=info
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}

WORKDIR /app
COPY --from=builder /app/dist ${WORKDIR}/dist

COPY ./.eslintrc /app/.eslintrc
COPY ./.prettierrc /app/.prettierrc
COPY ./jest.config.ts /app/jest.config.ts
COPY --from=builder /app/node_modules /app/node_modules
COPY ./Makefile ${WORKDIR}/
COPY ./package.json ${WORKDIR}/package.json
COPY ./package-lock.json ${WORKDIR}/package-lock.json

RUN npm ci --verbose --omit=dev --omit=optional --ignore-scripts --no-cache
RUN ls -alh

USER node
CMD ["npm", "run", "test"]
CMD ["ls", "-alh"]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ env:

clean:
npm run jest:clean
rm -vfr ./node_modules
rm -vfr ./coverage
rm -vfr ./dist
rm -vfr ./node_modules
mkdir -p ./coverage
touch ./coverage/.gitkeep

build: dependencies
${NPM} run build

dependencies:
@echo "################################################################################"
@echo "## Dependencies: ###############################################################"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"typescript": "^5.4.5"
},
"scripts": {
"build": "tsc",
"start": "npm run test",
"lint": "npx --yes eslint . --color --max-warnings=0 && echo '✔ Your code looks good.'",
"jest:ci": "node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug",
Expand Down

0 comments on commit 26f7ae9

Please sign in to comment.