-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): download and cache specific checkstyle version on startup
- Loading branch information
1 parent
814b6da
commit 4dd42b5
Showing
6 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea | ||
.pre-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
# hadolint ignore=DL3006 | ||
FROM alpine as build | ||
ARG LATEST_URL=https://api.github.com/repos/checkstyle/checkstyle/releases/latest | ||
SHELL ["/bin/ash","-o", "pipefail","-c"] | ||
FROM openjdk:11.0.4-jre-slim-buster as build | ||
ARG RELEASE_URL=https://api.github.com/repos/checkstyle/checkstyle/releases/latest | ||
SHELL ["/bin/bash","-o", "pipefail","-c"] | ||
|
||
# hadolint ignore=DL3018 | ||
RUN apk add --no-cache curl jq | ||
RUN curl $LATEST_URL | jq ."assets[] | .browser_download_url" | xargs curl -L -o checkstyle.jar | ||
# hadolint ignore=DL3008 | ||
RUN apt-get update && apt-get install -yq curl jq --no-install-recommends && rm -rf /var/lib/apt/lists/* | ||
#RUN apk add --no-cache curl jq | ||
#RUN curl $RELEASE_URL | jq ."assets[] | .browser_download_url" | xargs curl -L -o /opt/checkstyle.jar | ||
|
||
COPY execute_checkstyle.sh /bin/checkstyle | ||
|
||
FROM gcr.io/distroless/java:11 | ||
#FROM openjdk:11.0.4-jre-slim-buster | ||
WORKDIR /opt | ||
COPY --from=build checkstyle.jar checkstyle.jar | ||
ENTRYPOINT ["java", "-jar", "/opt/checkstyle.jar"] | ||
#COPY --from=build checkstyle.jar checkstyle.jar | ||
ENTRYPOINT ["checkstyle"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
# pre-commit-checkstyle | ||
A docker based pre-commit hook for Java checkstyle | ||
|
||
#Using this hook | ||
A docker based pre-commit hook for Java checkstyle | ||
|
||
This hook will create a folder named `.pre-commit` in you working directory, where the used checkstyle jar file will be located. | ||
Changing the first argument of the hook allows to select a different version. | ||
Make sure to add the cache folder to you gitignore file: | ||
|
||
```gitignore | ||
.pre-commit | ||
``` | ||
|
||
# Using this hook | ||
|
||
```yaml | ||
- repo: https://github.com/HotSprings-GmbH/pre-commit-checkstyle | ||
rev: '' # A Tag or commit hash | ||
- hooks: | ||
- id: checkstyle | ||
args: | ||
- "-c=checkstyle.xml" # configure checkstyle | ||
stages: | ||
- commit | ||
- repo: https://github.com/HotSprings-GmbH/pre-commit-checkstyle | ||
rev: "" # A Tag or commit hash | ||
hooks: | ||
- id: checkstyle | ||
args: | ||
- "8.41" # the checkstyle version | ||
- "-c=checkstyle.xml" # configure checkstyle | ||
stages: | ||
- commit | ||
``` | ||
# Dependencies | ||
## Checkstyle | ||
This hook uses the latest provided version of [checkstyle](https://checkstyle.org/). | ||
- [Source Code](https://github.com/checkstyle/checkstyle). | ||
- [License: LGPL-2.1+](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt) | ||
- [Checkstyle Source Code](https://github.com/checkstyle/checkstyle). | ||
- [Checkstyle License: LGPL-2.1+](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
VERSION=$1 | ||
RELEASE_URL="https://api.github.com/repos/checkstyle/checkstyle/releases?per_page=100" | ||
CHECKSTYLE_FOLDER=/src/.pre-commit/ | ||
CHECKSTYLE_JAR=$CHECKSTYLE_FOLDER/checkstyle-$VERSION.jar | ||
|
||
mkdir -p $CHECKSTYLE_FOLDER | ||
|
||
|
||
if [ -z "$VERSION" ]; then | ||
VERSION=$(curl https://api.github.com/repos/checkstyle/checkstyle/releases/latest | jq ".tag_name" | sed -r "s/.*e-(.*)\"/\1/") | ||
echo "No version provided, using latest version=\"$VERSION\"" | ||
fi | ||
|
||
|
||
if test -f "$CHECKSTYLE_JAR"; then | ||
echo "$CHECKSTYLE_JAR exists." | ||
else | ||
echo "Downloading checkstyle" | ||
VERSION_FOUND=$(curl -s $RELEASE_URL | jq ".[] | .assets[] | .browser_download_url" | grep "\-$VERSION/") | ||
if [ -z "$VERSION_FOUND" ]; then | ||
echo "$VERSION is could not found within the last 100 releases" | ||
exit 1 | ||
else | ||
echo $VERSION_FOUND | xargs curl -L -o $CHECKSTYLE_JAR | ||
fi | ||
|
||
fi | ||
|
||
java -jar $CHECKSTYLE_JAR ${@:2} |