Skip to content

Commit 000e6e9

Browse files
author
Gonzalo Diaz
committed
[CONFIG] [Docker] building process re-organized.
1 parent d09b3a4 commit 000e6e9

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

Dockerfile

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ FROM gradle:8.8.0-jdk21-alpine AS base
44
ENV WORKDIR=/app
55
WORKDIR ${WORKDIR}
66

7+
RUN apk add --update --no-cache make
8+
79
###############################################################################
810
FROM base AS lint
911

@@ -34,7 +36,7 @@ COPY ./settings.gradle ${WORKDIR}/
3436
COPY ./Makefile ${WORKDIR}/
3537

3638
# code linting conf
37-
COPY ./checkstyle.xml ${WORKDIR}/checkstyle.xml
39+
COPY ./checkstyle.xml ${WORKDIR}/
3840

3941
# markdownlint conf
4042
COPY ./.markdownlint.yaml ${WORKDIR}/
@@ -48,37 +50,36 @@ CMD ["make", "lint"]
4850
###############################################################################
4951
FROM base AS development
5052

51-
RUN apk add --update --no-cache make
53+
COPY ./algorithm-exercises-java ${WORKDIR}/algorithm-exercises-java
54+
COPY ./settings.gradle ${WORKDIR}/
55+
COPY ./Makefile ${WORKDIR}/
56+
COPY ./checkstyle.xml ${WORKDIR}/
57+
COPY ./gradle ${WORKDIR}/
58+
COPY ./gradlew ${WORKDIR}/
5259

5360
###############################################################################
5461
FROM development AS builder
5562

56-
WORKDIR /app
57-
58-
## Copy sources to builder stage
59-
COPY ./algorithm-exercises-java ${WORKDIR}/algorithm-exercises-java
60-
COPY ./config ${WORKDIR}/config
61-
COPY ./gradle ${WORKDIR}/gradle
62-
COPY ./gradlew ${WORKDIR}/gradlew
63-
COPY ./settings.gradle ${WORKDIR}/settings.gradle
64-
COPY ./Makefile ${WORKDIR}/Makefile
63+
ENV WORKDIR=/app
64+
WORKDIR ${WORKDIR}
6565

6666
## build
67-
RUN chmod +x gradlew
68-
RUN gradle --console=verbose build
67+
RUN make build
68+
69+
# CMD []
6970

7071
###############################################################################
7172
### In testing stage, can't use USER, due permissions issue
7273
## in github actions environment:
7374
##
7475
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
7576
##
76-
FROM builder AS testing
77+
FROM development AS testing
7778

7879
ENV LOG_LEVEL=INFO
7980
ENV BRUTEFORCE=false
80-
81-
WORKDIR /app
81+
ENV WORKDIR=/app
82+
WORKDIR ${WORKDIR}
8283

8384
RUN ls -alh
8485

@@ -93,16 +94,18 @@ FROM eclipse-temurin:22.0.1_8-jre-alpine AS production
9394

9495
ENV LOG_LEVEL=INFO
9596
ENV BRUTEFORCE=false
97+
ENV WORKDIR=/app
98+
WORKDIR ${WORKDIR}
9699

97100
RUN adduser -D worker
98101
RUN mkdir -p /app
99102
RUN chown worker:worker /app
100103

101-
WORKDIR /app
104+
RUN apk add --update --no-cache make
105+
COPY ./Makefile ${WORKDIR}/
106+
COPY --from=builder /app/algorithm-exercises-java/build/libs/algorithm-exercises-java.jar ${WORKDIR}/algorithm-exercises-java.jar
102107

103-
COPY --from=builder ./algorithm-exercises-java/build/libs/algorithm-exercises-java.jar ${WORKDIR}/algorithm-exercises-java.jar
104108
RUN ls -alh
105109

106110
USER worker
107-
108-
# CMD []
111+
CMD ["make", "run"]

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,21 @@ outdated:
7474
clean:
7575
$(GRADLE) clean
7676

77-
build: env lint test
78-
$(GRADLE) --console=verbose clean build
77+
build: env
78+
$(GRADLE) --console=verbose clean build \
79+
--exclude-task test \
80+
--exclude-task checkstyleMain \
81+
--exclude-task checkstyleTest
7982

8083
compose/build: env
8184
docker-compose --profile lint build
8285
docker-compose --profile testing build
86+
docker-compose --profile production build
8387

8488
compose/rebuild: env
8589
docker-compose --profile lint build --no-cache
8690
docker-compose --profile testing build --no-cache
91+
docker-compose --profile production build --no-cache
8792

8893
compose/lint/markdown: compose/build
8994
docker-compose --profile lint run --rm algorithm-exercises-java-lint make lint/markdown
@@ -99,7 +104,13 @@ compose/test/static: compose/build
99104

100105
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
101106

107+
compose/test: compose/build
108+
docker-compose --profile testing run --rm algorithm-exercises-java-test make test
109+
102110
compose/run: compose/build
103-
docker-compose --profile testing run --rm algorithm-exercises-java make test
111+
docker-compose --profile production run --rm algorithm-exercises-java make run
104112

105113
all: env dependencies lint test
114+
115+
run:
116+
ls -alh

compose.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22

33
services:
4-
algorithm-exercises-java:
5-
image: algorithm-exercises-java:latest
4+
algorithm-exercises-java-test:
5+
image: algorithm-exercises-java:test
66
build:
77
context: .
88
target: testing
99
environment:
1010
LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
1111
BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
1212
volumes:
13-
- ./build:/app/build
13+
# - ./build:/app/build
14+
- ./:/app
1415
profiles: [testing]
1516

1617
algorithm-exercises-java-lint:
@@ -37,6 +38,17 @@ services:
3738
- ./:/app
3839
profiles: [development]
3940

41+
algorithm-exercises-java:
42+
image: algorithm-exercises-java:latest
43+
build:
44+
context: .
45+
target: production
46+
environment:
47+
LOG_LEVEL: ${LOG_LEVEL:-info} ## (1) ## info | debug
48+
BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false
49+
# volumes:
50+
# - ./:/app
51+
profiles: [production]
4052
## REFERENCES:
4153
## (1) Passing Environment variable with fallback value:
4254
## https://stackoverflow.com/a/70772707/6366150

0 commit comments

Comments
 (0)