Skip to content

Commit d0b29ed

Browse files
authored
Merge pull request #440 from sir-gon/feature/production-ready
Feature/production ready
2 parents bafedb0 + 8aded5b commit d0b29ed

File tree

6 files changed

+55
-31
lines changed

6 files changed

+55
-31
lines changed

.github/workflows/docker-image.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ jobs:
1919
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
2020
- name: Build the Docker image
2121
run: make compose/rebuild
22-
- name: Run test in Docker image
22+
- name: Lint in Docker image
23+
run: make compose/lint
24+
- name: Test in Docker image
25+
run: make compose/test
26+
- name: Run in Docker image
2327
run: make compose/run
2428
- name: Tag Docker image
2529
run: >

Dockerfile

+18-11
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,20 @@ RUN ls -alh
6767
# CMD []
6868
WORKDIR ${WORKDIR}
6969
###############################################################################
70-
FROM development AS builder
70+
FROM base AS builder
7171

7272
ENV WORKDIR=/app
7373
WORKDIR ${WORKDIR}
7474

75-
RUN make clean && npm ci --verbose --omit-dev
75+
COPY ./src ${WORKDIR}/src
76+
COPY ./package.json ${WORKDIR}/package.json
77+
COPY ./package-lock.json ${WORKDIR}/package-lock.json
78+
COPY ./Makefile ${WORKDIR}/
7679

77-
# CMD []
80+
RUN rm -vfr node_modules && npm ci --verbose --omit=dev
81+
RUN npm run build
82+
83+
CMD ["ls", "-alh"]
7884

7985
###############################################################################
8086
### In testing stage, can't use USER, due permissions issue
@@ -100,21 +106,22 @@ CMD ["make", "test"]
100106
## in the production phase, "good practices" such as
101107
## WORKSPACE and USER are maintained
102108
##
103-
FROM builder AS production
109+
FROM base AS production
104110

105111
ENV LOG_LEVEL=info
106112
ENV BRUTEFORCE=false
107113
ENV WORKDIR=/app
108114
WORKDIR ${WORKDIR}
109115

110-
# TODO find a way to exclude /src/ and exclude *.test.js files
116+
COPY --from=builder /app/dist ${WORKDIR}/dist
117+
COPY --from=builder /app/node_modules ${WORKDIR}/node_modules
118+
119+
COPY ./Makefile ${WORKDIR}/
120+
COPY ./package.json ${WORKDIR}/package.json
121+
COPY ./package-lock.json ${WORKDIR}/package-lock.json
122+
COPY ./Makefile ${WORKDIR}/
111123

112-
COPY ./.babelrc /app/.babelrc
113-
COPY ./.eslintrc /app/.eslintrc
114-
COPY ./.prettierrc /app/.prettierrc
115-
COPY ./jest.config.js /app/jest.config.js
116-
COPY --from=builder /app/node_modules /app/node_modules
117124
RUN ls -alh
118125

119126
USER node
120-
CMD ["npm", "run", "test"]
127+
CMD ["ls", "-alh"]

Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ env:
4646

4747
clean:
4848
${NPM} run jest:clean
49+
rm -vfr ./build
4950
rm -vfr ./node_modules
5051
rm -vfr ./coverage
5152
mkdir -p ./coverage
5253
touch ./coverage/.gitkeep
5354

55+
build: dependencies
56+
${NPM} run build
57+
5458
dependencies:
5559
@echo "################################################################################"
5660
@echo "## Dependencies: ###############################################################"
@@ -93,10 +97,12 @@ upgrade: update
9397
compose/build: env
9498
docker-compose --profile lint build
9599
docker-compose --profile testing build
100+
docker-compose --profile production build
96101

97102
compose/rebuild: env
98103
docker-compose --profile lint build --no-cache
99104
docker-compose --profile testing build --no-cache
105+
docker-compose --profile production build --no-cache
100106

101107
compose/lint/markdown: compose/build
102108
docker-compose --profile lint build
@@ -113,7 +119,13 @@ compose/test/static: compose/build
113119

114120
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
115121

122+
compose/test: compose/build
123+
docker-compose --profile testing run --rm algorithm-exercises-js-test make test
124+
116125
compose/run: compose/build
117-
docker-compose --profile testing run --rm algorithm-exercises-js make test
126+
docker-compose --profile production run --rm algorithm-exercises-js make run
118127

119128
all: env dependencies test
129+
130+
run:
131+
ls -alh

compose.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22

33
services:
4-
algorithm-exercises-js:
5-
image: algorithm-exercises-js:latest
4+
algorithm-exercises-js-test:
5+
image: algorithm-exercises-js:test
66
build:
77
context: .
88
target: testing
@@ -37,13 +37,13 @@ services:
3737
- ./:/app
3838
profiles: ["development"]
3939

40-
algorithm-exercises-js-prod:
41-
image: algorithm-exercises-js:prod
40+
algorithm-exercises-js:
41+
image: algorithm-exercises-js:latest
4242
build:
4343
context: .
4444
target: production
45-
volumes:
46-
- ./:/app
45+
# volumes:
46+
# - ./:/app
4747
profiles: ["production"]
4848

4949
## REFERENCES:

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
2-
"name": "projecteuler.net",
2+
"name": "algorithm-exercises-js",
33
"version": "1.0.0",
4-
"description": "Solutions to the first 100 problems from [Project Euler](https://projecteuler.net/)",
5-
"main": "src/problem0000-template.js",
4+
"description": "Algorithm exercises solved in Javascript ECMA6, running with Jest testing suite. Developed with TDD.",
5+
"main": "src/problem0000.js",
66
"scripts": {
7+
"build": "npx --yes copyfiles --verbose -R --up 1 -e \"**/*.test.js\" -e \"**/*.config.js\" \"**/*.js\" dist/",
78
"start": "npm run test",
8-
"lint": "npx eslint . --color --max-warnings=0 && echo '✔ Your code looks good.'",
9-
"lint:watch": "npx esw . --color --max-warnings=0 --watch",
9+
"lint": "npx --yes eslint . --color --max-warnings=0 && echo '✔ Your code looks good.'",
10+
"lint:watch": "npx --yes esw . --color --max-warnings=0 --watch",
1011
"jest:ci": "node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug",
11-
"jest:clean": "jest --clearCache && watchman watch-del-all",
12+
"jest:clean": "npx --yes jest --clearCache && npx --yes watchman watch-del-all",
1213
"jest:bruteforce": "BRUTEFORCE=true node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug",
1314
"jest:watch": "node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug --watchAll",
14-
"style:format": "npx prettier --write 'src/**/*.js'",
15-
"style:check": "npx prettier --check 'src/**/*.js'",
16-
"test": "jest",
15+
"style:format": "npx --yes prettier --write 'src/**/*.js'",
16+
"style:check": "npx --yes prettier --check 'src/**/*.js'",
17+
"test": "npm run jest:ci",
1718
"test:all": "npm run lint && npm run jest && echo 'Done.'",
18-
"test:watch": "concurrently -k -s first --names \"LINT,TEST\" -p \"[{name}]\" \"npm run lint:watch\" \"npm run jest:watch\"",
19+
"test:watch": "npx --yes concurrently -k -s first --names \"LINT,TEST\" -p \"[{name}]\" \"npm run lint:watch\" \"npm run jest:watch\"",
1920
"update-all": "npm install $(npm outdated | cut -d' ' -f 1 | sed '1d' | xargs -I '$' echo '$@latest' | xargs echo)"
2021
},
2122
"author": "Gonzalo Diaz <[email protected]>",

0 commit comments

Comments
 (0)