Skip to content

Commit bbb9da2

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] [Docker] [make] yamllint added as tool in docker lint stage, and as "make" action.
1 parent 7ae3084 commit bbb9da2

File tree

4 files changed

+108
-32
lines changed

4 files changed

+108
-32
lines changed

Dockerfile

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,93 @@ ENV WORKDIR=/app
77
WORKDIR ${WORKDIR}
88

99
###############################################################################
10-
FROM node:20.14.0-alpine3.20 AS lint
10+
FROM base AS lint
1111

1212
ENV WORKDIR=/app
1313
WORKDIR ${WORKDIR}
1414

15+
RUN apk add --update --no-cache make nodejs npm
16+
RUN apk add --update --no-cache yamllint
17+
18+
RUN npm install -g --ignore-scripts markdownlint-cli
19+
20+
# [!TIP] Use a bind-mount to "/app" to override following "copys"
21+
# for lint and test against "current" sources in this stage
22+
23+
# YAML sources
24+
COPY ./.github ${WORKDIR}/
25+
COPY ./compose.yaml ${WORKDIR}/
26+
27+
# Markdown sources
28+
COPY ./docs ${WORKDIR}/
29+
COPY ./README.md ${WORKDIR}/
30+
COPY ./LICENSE.md ${WORKDIR}/
31+
COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/
32+
33+
# Code source
1534
COPY ./src ${WORKDIR}/src
16-
RUN apk add --update --no-cache make
17-
RUN npm install -g markdownlint-cli
35+
COPY ./package.json ${WORKDIR}/package.json
36+
COPY ./package-lock.json ${WORKDIR}/package-lock.json
37+
COPY ./Makefile ${WORKDIR}/
1838

39+
# code linting conf
40+
COPY ./.prettierrc ${WORKDIR}/
41+
COPY ./.prettierignore ${WORKDIR}/
42+
COPY ./.eslintrc ${WORKDIR}/
43+
COPY ./.babelrc ${WORKDIR}/
44+
45+
# markdownlint conf
46+
COPY ./.markdownlint.yaml ${WORKDIR}/
47+
48+
# yamllint conf
49+
COPY ./.yamllint ${WORKDIR}/
50+
COPY ./.yamlignore ${WORKDIR}/
51+
52+
CMD ["make", "lint"]
1953
###############################################################################
2054
FROM base AS development
2155

22-
###############################################################################
23-
FROM development AS builder
56+
ENV WORKDIR=/app
57+
WORKDIR ${WORKDIR}
2458

2559
COPY ./src ${WORKDIR}/src
2660
COPY ./package.json ${WORKDIR}/package.json
2761
COPY ./package-lock.json ${WORKDIR}/package-lock.json
2862
COPY ./Makefile ${WORKDIR}/
2963

3064
RUN npm ci --verbose
65+
RUN ls -alh
66+
67+
# CMD []
68+
WORKDIR ${WORKDIR}
69+
###############################################################################
70+
FROM development AS builder
71+
72+
ENV WORKDIR=/app
73+
WORKDIR ${WORKDIR}
74+
75+
RUN make clean && npm ci --verbose --omit-dev
76+
77+
# CMD []
3178

3279
###############################################################################
3380
### In testing stage, can't use USER, due permissions issue
3481
## in github actions environment:
3582
##
3683
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
3784
##
38-
FROM builder AS testing
85+
FROM development AS testing
3986

4087
ENV LOG_LEVEL=info
4188
ENV BRUTEFORCE=false
42-
43-
WORKDIR /app
89+
ENV WORKDIR=/app
90+
WORKDIR ${WORKDIR}
4491

4592
COPY ./.babelrc /app/.babelrc
46-
COPY ./.eslintrc /app/.eslintrc
47-
COPY ./.prettierrc /app/.prettierrc
4893
COPY ./jest.config.js /app/jest.config.js
49-
COPY --from=builder /app/node_modules /app/node_modules
5094
RUN ls -alh
5195

52-
CMD ["npm", "run", "test"]
96+
CMD ["make", "test"]
5397

5498
###############################################################################
5599
### In production stage
@@ -60,8 +104,10 @@ FROM builder AS production
60104

61105
ENV LOG_LEVEL=info
62106
ENV BRUTEFORCE=false
107+
ENV WORKDIR=/app
108+
WORKDIR ${WORKDIR}
63109

64-
WORKDIR /app
110+
# TODO find a way to exclude /src/ and exclude *.test.js files
65111

66112
COPY ./.babelrc /app/.babelrc
67113
COPY ./.eslintrc /app/.eslintrc

Makefile

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NPM_UPDATABLE_MODULES = $(shell npm outdated | cut -d' ' -f 1 | sed '1d' | xargs
2626

2727
# DOCKER
2828
BUILDKIT_PROGRESS=plain
29+
DOCKER_BUILDKIT=1
2930

3031
.MAIN: test
3132
.PHONY: all clean dependencies help list test outdated
@@ -44,7 +45,7 @@ env:
4445
@echo "################################################################################"
4546

4647
clean:
47-
npm run jest:clean
48+
${NPM} run jest:clean
4849
rm -vfr ./node_modules
4950
rm -vfr ./coverage
5051
mkdir -p ./coverage
@@ -57,43 +58,60 @@ dependencies:
5758
test -x ./node_modules || npm install --verbose
5859
@echo "################################################################################"
5960

60-
mdlint:
61+
lint/markdown:
6162
markdownlint '**/*.md' --ignore node_modules && echo '✔ Your code looks good.'
6263

63-
lint: test/static mdlint
64+
lint/yaml:
65+
yamllint --stric . && echo '✔ Your code looks good.'
66+
67+
lint: lint/markdown lint/yaml test/styling test/static
6468

6569
test/static: dependencies
66-
npm run lint
70+
${NPM} run lint
71+
72+
test/styling: dependencies
73+
${NPM} run style:check
74+
75+
format: dependencies
76+
${NPM} run style:format
6777

68-
test: env dependencies test/static
69-
npm run jest:ci
78+
test: env dependencies
79+
${NPM} run jest:ci
7080

71-
coverage: test
81+
coverage: dependencies test
7282

73-
coverage/html: coverage
83+
coverage/html: dependencies test
7484

7585
outdated:
76-
-npm outdated
86+
-${NPM} outdated
7787

7888
update: dependencies outdated
79-
npm install $(NPM_UPDATABLE_MODULES)
89+
${NPM} install $(NPM_UPDATABLE_MODULES)
8090

8191
upgrade: update
8292

8393
compose/build: env
94+
docker-compose --profile lint build
8495
docker-compose --profile testing build
8596

8697
compose/rebuild: env
98+
docker-compose --profile lint build --no-cache
8799
docker-compose --profile testing build --no-cache
88100

89-
compose/mdlint: env
101+
compose/lint/markdown: compose/build
90102
docker-compose --profile lint build
91-
docker-compose --profile lint run --rm algorithm-exercises-js-mdlint make mdlint
103+
docker-compose --profile lint run --rm algorithm-exercises-js-lint make lint/markdown
104+
105+
compose/lint/yaml: compose/build
106+
docker-compose --profile lint run --rm algorithm-exercises-js-lint make lint/yaml
107+
108+
compose/test/styling: compose/build
109+
docker-compose --profile lint run --rm algorithm-exercises-js-lint make test/styling
92110

93111
compose/test/static: compose/build
94-
docker-compose --profile testing run --rm algorithm-exercises-js make test/static
112+
docker-compose --profile lint run --rm algorithm-exercises-js-lint make test/static
95113

96-
compose/lint: compose/test/static compose/mdlint
114+
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
97115

98116
compose/run: compose/build
99117
docker-compose --profile testing run --rm algorithm-exercises-js make test

compose.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
---
2+
13
services:
24
algorithm-exercises-js:
35
image: algorithm-exercises-js:latest
@@ -11,14 +13,14 @@ services:
1113
- ./coverage:/app/coverage
1214
profiles: ["testing"]
1315

14-
algorithm-exercises-js-mdlint:
15-
image: algorithm-exercises-ts:mdlint
16+
algorithm-exercises-js-lint:
17+
image: algorithm-exercises-ts:lint
1618
build:
1719
context: .
1820
target: lint
1921
# environment:
20-
# LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
21-
# BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
22+
# LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
23+
# BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
2224
volumes:
2325
- ./:/app
2426
profiles: ["lint"]
@@ -35,6 +37,15 @@ services:
3537
- ./:/app
3638
profiles: ["development"]
3739

40+
algorithm-exercises-js-prod:
41+
image: algorithm-exercises-js:prod
42+
build:
43+
context: .
44+
target: production
45+
volumes:
46+
- ./:/app
47+
profiles: ["production"]
48+
3849
## REFERENCES:
3950
## (1) Passing Environment variable with fallback value:
4051
## https://stackoverflow.com/a/70772707/6366150

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"jest:clean": "jest --clearCache && watchman watch-del-all",
1212
"jest:bruteforce": "BRUTEFORCE=true node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug",
1313
"jest:watch": "node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug --watchAll",
14-
"prettier": "npx prettier --write 'src/**/*.js'",
14+
"style:format": "npx prettier --write 'src/**/*.js'",
15+
"style:check": "npx prettier --check 'src/**/*.js'",
1516
"test": "jest",
1617
"test:all": "npm run lint && npm run jest && echo 'Done.'",
1718
"test:watch": "concurrently -k -s first --names \"LINT,TEST\" -p \"[{name}]\" \"npm run lint:watch\" \"npm run jest:watch\"",

0 commit comments

Comments
 (0)