Skip to content

Commit

Permalink
Extract the code style and test from the Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed May 8, 2023
1 parent c3e7c31 commit 0926983
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 93 deletions.
51 changes: 10 additions & 41 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,63 +80,32 @@ jobs:

- name: Checks
run: c2cciutils-checks
- run: cat .github/workflows/main.yaml
if: failure()

- run: make build
- run: make acceptance-tests-up
- run: make acceptance-tests-run

# Extract artifacts
- run: docker run --rm --detach --name=builder mapfish_print_builder || true
if: always()
- run: docker cp builder:/src/core/build/ core/build/ || true
if: always()
- run: ls -l core/build/libs core/build/distributions
if: always()

- run: docker cp mapfish-print_tests_1:/src/examples/build/ examples/build/ || true
if: always()

- run: c2cciutils-docker-logs || true
if: failure()
- run: make checks
- run: make tests

- run: mkdir -p core/build/resources/actual examples/build/reports core/build/reports examples/build/resources/test/examples
if: always()
- uses: actions/upload-artifact@v3
with:
name: Test results
path: core/build/resources/
path: core/build/resources/test/org/mapfish/print/
if-no-files-found: ignore
if: failure()
- uses: actions/upload-artifact@v3
with:
name: Reports examples
path: examples/build/reports
if-no-files-found: ignore
if: failure()
- uses: actions/upload-artifact@v3
with:
name: Reports core
path: core/build/reports
if-no-files-found: ignore

- run: make acceptance-tests-up
- run: make acceptance-tests-run
- run: c2cciutils-docker-logs || true
if: failure()

- uses: actions/upload-artifact@v3
with:
name: Examples
path: examples/build/resources/test/examples
if-no-files-found: ignore
if: failure()

- name: Collect test results
run: |
mkdir -p /tmp/test_results/junit
find . -name '*TEST-*.xml' -exec cp -v {} /tmp/test_results/junit/ \;
if: failure()
- uses: actions/upload-artifact@v3
with:
name: Test results
path: /tmp/test_results
if: failure()

- name: Publish
run: c2cciutils-publish
if: env.HAS_SECRETS == 'HAS_SECRETS'
Expand Down
44 changes: 19 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,38 @@ FROM gradle:6.9.4-jdk11 AS builder
RUN --mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/root/.cache \
apt-get update && \
apt-get install --yes --no-install-recommends fonts-liberation gettext curl && \
gradle --version
apt-get install --yes --no-install-recommends fonts-liberation gettext curl

WORKDIR /src

ENV GRADLE_OPTS=-Dorg.gradle.daemon=false

RUN --mount=type=cache,target=/home/gradle/.gradle \
gradle --version

COPY gradle/ ./gradle/
COPY gradle.properties build.gradle settings.gradle CI.asc ./
COPY gradle.properties build.gradle settings.gradle CI.asc checkstyle_* ./
COPY examples/build.gradle ./examples/
COPY docs/build.gradle ./docs/
COPY publish/build.gradle ./publish/
COPY core ./core

RUN --mount=type=cache,target=/home/gradle/.gradle \
gradle :core:processResources :core:classes
COPY checkstyle_* ./
# '&& touch success || true' is a trick to be able to get out some artifacts
RUN --mount=type=cache,target=/home/gradle/.gradle \
(gradle :core:checkstyleMain :core:spotbugsMain :core:violations --stacktrace) \
&& ( (gradle :core:build :core:explodedWar :core:libSourcesJar :core:libJavadocJar > /tmp/logs 2>&1 && touch success) || true)
COPY publish ./publish
COPY examples ./examples
COPY docs ./docs

ARG GIT_HEAD
ENV GIT_HEAD=${GIT_HEAD}

COPY publish ./publish

# Exclude the tasks that will run our of the docker build (in a docker run)
RUN --mount=type=cache,target=/home/gradle/.gradle \
([ -e success ] && ( (gradle :publish:build >> /tmp/logs 2>&1) && touch success-publish)) || true
gradle --exclude-task=:core:test --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \
:core:build :core:explodedWar :publish:build :examples:build buildDocs

COPY examples ./examples
COPY docs ./docs
RUN mkdir -p core/build/resources/test/org/mapfish/print/ \
&& chmod -R go=u /home/gradle /tmp/mapfish-print/ . \
&& chmod o+t -R core/build/resources

# Backup cache
RUN --mount=type=cache,target=/home/gradle/.gradle \
([ -e success ] && ( (gradle :examples:build buildDocs >> /tmp/logs 2>&1) && touch success-examples-docs)) || true

RUN chmod -R go=u /home/gradle .

FROM builder AS test-builder

RUN cat /tmp/logs && ls success success-publish success-examples-docs

VOLUME [ "/src/core" ]
cp -r /home/gradle/.gradle /home/gradle/.gradle-backup
RUN mv /home/gradle/.gradle-backup /home/gradle/.gradle
34 changes: 28 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@ GIT_HEAD_ARG = --build-arg=GIT_HEAD=$(shell git rev-parse HEAD)
export DOCKER_BUILDKIT = 1

.PHONY: build
build:
build: build-builder
# Required and not necessarily exists
touch CI.asc

docker build $(GIT_HEAD_ARG) --target=builder --tag=mapfish_print_builder .
docker build $(GIT_HEAD_ARG) .

docker build $(GIT_HEAD_ARG) --target=runner --tag=camptocamp/mapfish_print core
docker build $(GIT_HEAD_ARG) --target=tester --tag=mapfish_print_tester core
docker build $(GIT_HEAD_ARG) --target=watcher --tag=mapfish_print_watcher core

.PHONY: build-builder
build-builder:
docker build $(GIT_HEAD_ARG) --target=builder --tag=mapfish_print_builder .

.PHONY: checks
checks: build-builder
docker run --rm \
--volume=$(PWD)/core/src/:/src/core/src/ \
--volume=$(PWD)/reports/:/src/core/build/reports/ \
mapfish_print_builder \
gradle :core:spotbugsMain :core:checkstyleMain

.PHONY: tests
tests: build-builder
docker stop print-builder || true
docker run --rm --detach --name=print-builder mapfish_print_builder tail --follow /dev/null

docker exec print-builder gradle :core:test

# Get the result
mkdir -p core/build/resources/test/org/mapfish/print/
docker cp print-builder:/src/core/build/resources/test/org/mapfish/print/ core/build/resources/test/org/mapfish/print/

docker stop print-builder

.PHONY: acceptance-tests-up
acceptance-tests-up:
acceptance-tests-up: build
docker-compose down --remove-orphan

mkdir /tmp/geoserver-data || true
Expand All @@ -24,7 +46,7 @@ acceptance-tests-up:
cp -r examples/geoserver-data/* /tmp/geoserver-data/
cp -r core/src/test/resources/map-data/* /tmp/geoserver-data/www/

USER_ID=$(shell id -u):$(shell id -g) docker-compose up -d
USER_ID=$(shell id -u):$(shell id -g) docker-compose up --detach

.PHONY: acceptance-tests-run
acceptance-tests-run:
Expand Down
20 changes: 2 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,18 @@ configure(subprojects.findAll { ['core', 'examples'].contains(it.name) }) {
toolVersion = "10.10.0" // com.puppycrawl.tools:checkstyle
configFile = file("$rootProject.rootDir/checkstyle_checks.xml")
configProperties = ['basedir': project.rootDir.path]
ignoreFailures = true
reportsDir = file("$project.buildDir/reports/checkstyleReports")
}
checkstyleTest.enabled = false

spotbugs {
toolVersion = "4.7.3" // com.github.spotbugs:spotbugs-annotations
ignoreFailures = true
reportsDir = file("$project.buildDir/reports/spotbugsReports")
effort = "max"
reportLevel = "high"
}
spotbugsTest.enabled = false

task violations(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
minSeverity = 'INFO'
detailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE
maxViolations = 0
printViolations = true
violations = [
["FINDBUGS", ".", ".*/reports/spotbugsReports/.*\\.xml", "Spotbugs"],
["CHECKSTYLE", ".", ".*/reports/checkstyleReports/.*\\.xml", "Checkstyle"]
]
}
check.finalizedBy violations

sourceCompatibility = 1.11
targetCompatibility = 1.11
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

compileJava.options.compilerArgs = ['-Xlint:deprecation', '-Xlint:unchecked']

Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ services:
image: mapfish_print_tester
user: ${USER_ID}
volumes:
- ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps
- ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps:ro
ports:
- 8080:8080
environment:
PRINT_YAML_MAX_ALIASES: 200
PRINT_YAML_MAX_ALIASES: '200'
LOG_LEVEL: DEBUG
JASPER_LOG_LEVEL: DEBUG

Expand All @@ -26,5 +26,5 @@ services:
volumes:
- ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples
environment:
PRINT_YAML_MAX_ALIASES: 200
PRINT_YAML_MAX_ALIASES: '200'
GRADLE_USER_HOME: /home/gradle/.gradle

0 comments on commit 0926983

Please sign in to comment.