Skip to content

Commit 8aded5b

Browse files
author
Gonzalo Diaz
committed
[CONFIG] [Docker] [make] new "production" phase at the end.
1 parent b142ffc commit 8aded5b

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

.github/workflows/docker-image.yml

Lines changed: 5 additions & 1 deletion
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

Lines changed: 18 additions & 11 deletions
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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ clean:
5252
mkdir -p ./coverage
5353
touch ./coverage/.gitkeep
5454

55+
build: dependencies
56+
${NPM} run build
57+
5558
dependencies:
5659
@echo "################################################################################"
5760
@echo "## Dependencies: ###############################################################"
@@ -94,10 +97,12 @@ upgrade: update
9497
compose/build: env
9598
docker-compose --profile lint build
9699
docker-compose --profile testing build
100+
docker-compose --profile production build
97101

98102
compose/rebuild: env
99103
docker-compose --profile lint build --no-cache
100104
docker-compose --profile testing build --no-cache
105+
docker-compose --profile production build --no-cache
101106

102107
compose/lint/markdown: compose/build
103108
docker-compose --profile lint build
@@ -114,7 +119,13 @@ compose/test/static: compose/build
114119

115120
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
116121

122+
compose/test: compose/build
123+
docker-compose --profile testing run --rm algorithm-exercises-js-test make test
124+
117125
compose/run: compose/build
118-
docker-compose --profile testing run --rm algorithm-exercises-js make test
126+
docker-compose --profile production run --rm algorithm-exercises-js make run
119127

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

compose.yaml

Lines changed: 6 additions & 6 deletions
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:

0 commit comments

Comments
 (0)