Skip to content

Commit 33da58b

Browse files
authored
Merge pull request #183 from sir-gon/feature/production_ready
Feature/production ready
2 parents 53b13ef + 000e6e9 commit 33da58b

File tree

6 files changed

+56
-28
lines changed

6 files changed

+56
-28
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"java.configuration.updateBuildConfiguration": "automatic",
33
"java.compile.nullAnalysis.mode": "automatic",
4-
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle.xml",
4+
"java.checkstyle.configuration": "${workspaceFolder}/checkstyle.xml",
55
"java.checkstyle.version": "10.10.0",
66
"sonarlint.connectedMode.project": {
77
"connectionId": "sir-gon",

Dockerfile

Lines changed: 25 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

@@ -31,9 +33,11 @@ COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/
3133
# Code source
3234
COPY ./algorithm-exercises-java ${WORKDIR}/algorithm-exercises-java
3335
COPY ./settings.gradle ${WORKDIR}/
34-
COPY ./config ${WORKDIR}/config
3536
COPY ./Makefile ${WORKDIR}/
3637

38+
# code linting conf
39+
COPY ./checkstyle.xml ${WORKDIR}/
40+
3741
# markdownlint conf
3842
COPY ./.markdownlint.yaml ${WORKDIR}/
3943

@@ -46,37 +50,36 @@ CMD ["make", "lint"]
4650
###############################################################################
4751
FROM base AS development
4852

49-
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}/
5059

5160
###############################################################################
5261
FROM development AS builder
5362

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

6466
## build
65-
RUN chmod +x gradlew
66-
RUN gradle --console=verbose build
67+
RUN make build
68+
69+
# CMD []
6770

6871
###############################################################################
6972
### In testing stage, can't use USER, due permissions issue
7073
## in github actions environment:
7174
##
7275
## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
7376
##
74-
FROM builder AS testing
77+
FROM development AS testing
7578

7679
ENV LOG_LEVEL=INFO
7780
ENV BRUTEFORCE=false
78-
79-
WORKDIR /app
81+
ENV WORKDIR=/app
82+
WORKDIR ${WORKDIR}
8083

8184
RUN ls -alh
8285

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

9295
ENV LOG_LEVEL=INFO
9396
ENV BRUTEFORCE=false
97+
ENV WORKDIR=/app
98+
WORKDIR ${WORKDIR}
9499

95100
RUN adduser -D worker
96101
RUN mkdir -p /app
97102
RUN chown worker:worker /app
98103

99-
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
100107

101-
COPY --from=builder ./algorithm-exercises-java/build/libs/algorithm-exercises-java.jar ${WORKDIR}/algorithm-exercises-java.jar
102108
RUN ls -alh
103109

104110
USER worker
105-
106-
# 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

algorithm-exercises-java/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tasks.named('test') {
4343

4444
checkstyle {
4545
toolVersion = '10.17.0'
46-
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
46+
configFile = file("${rootDir}/checkstyle.xml")
4747
maxErrors = 0
4848
maxWarnings = 0
4949
showViolations = true
File renamed without changes.

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)