Skip to content

Commit fb924c7

Browse files
authored
Remove apk go requirement when possible (#2318)
* Install revive from ghcr docker binary * Install actionlint from docker image's binary to remove apk go * Install checkmake from docker image binary * Use latest instead of tags for modified docker images * Use a builder image for revive as the released binaries return broken version number * Edit comment in actionlint Dockerfile instructions * Build dustilock in a stage and copy go binary * Specify GOBIN folder for revive install in builder * Remove unneeded GOPATH and GOROOT variables Unneeded since we are not building go packages from source anymore * Include fixes from linters * Add `COPY --link --from` by using dockerfile frontend syntax * Revert: Remove unneeded GOPATH and GOROOT variables * Run build.sh * Run ./build.sh after rebase * Include apk go requirement for golangci-lint * Add changelog entry * Handle duplicated FROM and COPY instructions * cSpell fixes
1 parent bed68e1 commit fb924c7

File tree

155 files changed

+800
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+800
-517
lines changed

.automation/build.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ def generate_flavor(flavor, flavor_info):
212212
os.makedirs(os.path.dirname(dockerfile), exist_ok=True)
213213
copyfile(f"{REPO_HOME}/Dockerfile", dockerfile)
214214
flavor_label = flavor_info["label"]
215-
comment = f"# MEGA-LINTER FLAVOR [{flavor}]: {flavor_label}"
215+
comment = f"# MEGALINTER FLAVOR [{flavor}]: {flavor_label}"
216216
with open(dockerfile, "r+", encoding="utf-8") as f:
217+
first_line = f.readline().rstrip()
218+
if first_line.startswith("# syntax="):
219+
comment = f"{first_line}\n{comment}"
220+
else:
221+
f.seek(0)
217222
content = f.read()
218223
f.seek(0)
219224
f.truncate()
@@ -300,14 +305,27 @@ def build_dockerfile(
300305
for dockerfile_item in item["install"]["dockerfile"]:
301306
# FROM
302307
if dockerfile_item.startswith("FROM"):
308+
if dockerfile_item in all_dockerfile_items:
309+
dockerfile_item = (
310+
"# Next FROM line commented because already managed by another linter\n"
311+
"# " + "\n# ".join(dockerfile_item.splitlines())
312+
)
303313
docker_from += [dockerfile_item]
304314
# ARG
305315
elif dockerfile_item.startswith("ARG"):
306316
docker_arg += [dockerfile_item]
307317
# COPY
308318
elif dockerfile_item.startswith("COPY"):
319+
if dockerfile_item in all_dockerfile_items:
320+
dockerfile_item = (
321+
"# Next COPY line commented because already managed by another linter\n"
322+
"# " + "\n# ".join(dockerfile_item.splitlines())
323+
)
309324
docker_copy += [dockerfile_item]
310-
docker_other += ["# Managed with " + dockerfile_item]
325+
docker_other += [
326+
"# Managed with "
327+
+ "\n# ".join(dockerfile_item.splitlines())
328+
]
311329
# Already used item
312330
elif (
313331
dockerfile_item in all_dockerfile_items

.github/linters/.cspell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"Fmegalinter",
133133
"GHSA",
134134
"GITLEAKS",
135+
"GOBIN",
135136
"GOLANGCI",
136137
"GOODCHECK",
137138
"GOPATH",
@@ -539,6 +540,7 @@
539540
"descriptionless",
540541
"devcontainer",
541542
"devcontainers",
543+
"devel",
542544
"devskim",
543545
"dimen",
544546
"dimendef",
@@ -864,6 +866,7 @@
864866
"mlinters",
865867
"moarvm",
866868
"mprettier",
869+
"mrtazz",
867870
"msgon",
868871
"mstruebing",
869872
"msvs",
@@ -977,6 +980,7 @@
977980
"packagename",
978981
"pagebreak",
979982
"pageref",
983+
"pandoc",
980984
"parallelization",
981985
"paren",
982986
"parens",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
3636
- CI
3737
- Use docker/build-push-action to build docker images and akhilerm/tag-push-action to release by retagging and pushing beta images instead of rebuilding them
3838
- Authenticate to GitHub API during docker build to avoid reaching limits
39+
- Remove apk go package install in images where possible to decrease image sizes, by @echoix in <https://github.com/oxsecurity/megalinter/pull/2318>
3940

4041
- Fixes
4142
- Replace deprecated spectral package, by @bdovaz in by @bdovaz in <https://github.com/oxsecurity/megalinter/pull/2340>

Dockerfile

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
###########################################
23
###########################################
34
## Dockerfile to run MegaLinter ##
@@ -10,15 +11,33 @@
1011
## @generated by .automation/build.py using descriptor files, please do not update manually ##
1112
#############################################################################################
1213
#FROM__START
14+
FROM rhysd/actionlint:latest as actionlint
15+
# shellcheck is a dependency for actionlint
16+
17+
FROM koalaman/shellcheck:stable as shellcheck
18+
# Next FROM line commented because already managed by another linter
19+
# FROM koalaman/shellcheck:stable as shellcheck
1320
FROM mvdan/shfmt:latest-alpine as shfmt
1421
FROM hadolint/hadolint:v2.12.0-alpine as hadolint
1522
FROM mstruebing/editorconfig-checker:2.7.0 as editorconfig-checker
23+
FROM golang:1.19-alpine as revive
24+
## The golang image used as a builder is a temporary workaround
25+
## for the released revive binaries not returning version numbers (devel).
26+
## The install command should then be what is commented in the go.megalinter-descriptor.yml
27+
RUN GOBIN=/usr/bin go install github.com/mgechev/revive@latest
28+
1629
FROM ghcr.io/assignuser/chktex-alpine:latest as chktex
30+
FROM mrtazz/checkmake:latest as checkmake
1731
FROM yoheimuta/protolint:latest as protolint
32+
FROM golang:alpine as dustilock
33+
RUN GOBIN=/usr/bin go install github.com/checkmarx/[email protected]
34+
1835
FROM zricethezav/gitleaks:v8.15.3 as gitleaks
1936
FROM ghcr.io/terraform-linters/tflint:v0.45.0 as tflint
2037
FROM tenable/terrascan:1.18.0 as terrascan
2138
FROM alpine/terragrunt:latest as terragrunt
39+
# Next FROM line commented because already managed by another linter
40+
# FROM alpine/terragrunt:latest as terragrunt
2241
FROM checkmarx/kics:alpine as kics
2342
#FROM__END
2443

@@ -69,7 +88,6 @@ RUN apk add --update --no-cache \
6988
openssh \
7089
docker \
7190
openrc \
72-
go \
7391
icu-libs \
7492
libcurl \
7593
libintl \
@@ -93,9 +111,11 @@ RUN apk add --update --no-cache \
93111
php81-simplexml \
94112
composer \
95113
dpkg \
114+
py3-pyflakes \
96115
nodejs \
97116
npm \
98117
yarn \
118+
go \
99119
openssl \
100120
readline-dev \
101121
g++ \
@@ -280,17 +300,26 @@ ENV PATH="/root/.cargo/bin:${PATH}"
280300
#############################################################################################
281301

282302
#COPY__START
283-
COPY --from=shfmt /bin/shfmt /usr/bin/
284-
COPY --from=hadolint /bin/hadolint /usr/bin/hadolint
285-
COPY --from=editorconfig-checker /usr/bin/ec /usr/bin/editorconfig-checker
286-
COPY --from=chktex /usr/bin/chktex /usr/bin/
287-
COPY --from=protolint /usr/local/bin/protolint /usr/bin/
288-
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
289-
COPY --from=tflint /usr/local/bin/tflint /usr/bin/
290-
COPY --from=terrascan /go/bin/terrascan /usr/bin/
291-
COPY --from=terragrunt /usr/local/bin/terragrunt /usr/bin/
292-
COPY --from=terragrunt /bin/terraform /usr/bin/
293-
COPY --from=kics /app/bin/kics /usr/bin/
303+
COPY --link --from=actionlint /usr/local/bin/actionlint /usr/bin/actionlint
304+
# shellcheck is a dependency for actionlint
305+
306+
COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
307+
# Next COPY line commented because already managed by another linter
308+
# COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
309+
COPY --link --from=shfmt /bin/shfmt /usr/bin/
310+
COPY --link --from=hadolint /bin/hadolint /usr/bin/hadolint
311+
COPY --link --from=editorconfig-checker /usr/bin/ec /usr/bin/editorconfig-checker
312+
COPY --link --from=revive /usr/bin/revive /usr/bin/revive
313+
COPY --link --from=chktex /usr/bin/chktex /usr/bin/
314+
COPY --link --from=checkmake /checkmake /usr/bin/checkmake
315+
COPY --link --from=protolint /usr/local/bin/protolint /usr/bin/
316+
COPY --link --from=dustilock /usr/bin/dustilock /usr/bin/dustilock
317+
COPY --link --from=gitleaks /usr/bin/gitleaks /usr/bin/
318+
COPY --link --from=tflint /usr/local/bin/tflint /usr/bin/
319+
COPY --link --from=terrascan /go/bin/terrascan /usr/bin/
320+
COPY --link --from=terragrunt /usr/local/bin/terragrunt /usr/bin/
321+
COPY --link --from=terragrunt /bin/terraform /usr/bin/
322+
COPY --link --from=kics /app/bin/kics /usr/bin/
294323
COPY --from=kics /app/bin/assets /opt/kics/assets/
295324
#COPY__END
296325

@@ -380,8 +409,9 @@ RUN echo y|sfdx plugins:install sfdx-hardis \
380409
# ENV PATH="${PATH}:/root/.dotnet/tools:/usr/share/dotnet"
381410

382411
# actionlint installation
383-
ENV GO111MODULE=on
384-
RUN go install github.com/rhysd/actionlint/cmd/actionlint@latest && go clean --cache
412+
# Managed with COPY --link --from=actionlint /usr/local/bin/actionlint /usr/bin/actionlint
413+
# # shellcheck is a dependency for actionlint
414+
# Managed with COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
385415

386416
# arm-ttk installation
387417
ENV ARM_TTK_PSD1="${ARM_TTK_DIRECTORY}/arm-ttk-master/arm-ttk/arm-ttk.psd1"
@@ -396,14 +426,11 @@ RUN curl --retry 5 --retry-delay 5 -sLO "${ARM_TTK_URI}" \
396426
&& chmod +x /usr/bin/bash-exec \
397427

398428
# shellcheck installation
399-
&& ML_THIRD_PARTY_DIR="/third-party/shellcheck" \
400-
&& mkdir -p ${ML_THIRD_PARTY_DIR} \
401-
&& wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv --directory ${ML_THIRD_PARTY_DIR} \
402-
&& mv "${ML_THIRD_PARTY_DIR}/shellcheck-stable/shellcheck" /usr/bin/ \
403-
&& find ${ML_THIRD_PARTY_DIR} -type f -not -name 'LICENSE*' -delete -o -type d -empty -delete \
429+
# Managed with # Next COPY line commented because already managed by another linter
430+
# # COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
404431

405432
# shfmt installation
406-
# Managed with COPY --from=shfmt /bin/shfmt /usr/bin/
433+
# Managed with COPY --link --from=shfmt /bin/shfmt /usr/bin/
407434

408435
# bicep_linter installation
409436
&& curl --retry 5 --retry-delay 5 -sLo ${BICEP_EXE} "${BICEP_URI}" \
@@ -428,20 +455,21 @@ RUN curl --retry 5 --retry-delay 5 -sLO "${ARM_TTK_URI}" \
428455
&& rm -r dart-sdk/ \
429456

430457
# hadolint installation
431-
# Managed with COPY --from=hadolint /bin/hadolint /usr/bin/hadolint
458+
# Managed with COPY --link --from=hadolint /bin/hadolint /usr/bin/hadolint
432459

433460
# editorconfig-checker installation
434-
# Managed with COPY --from=editorconfig-checker /usr/bin/ec /usr/bin/editorconfig-checker
461+
# Managed with COPY --link --from=editorconfig-checker /usr/bin/ec /usr/bin/editorconfig-checker
435462

436463
# dotenv-linter installation
437464
&& wget -q -O - https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s \
438465

439466
# golangci-lint installation
440467
&& wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh \
441-
&& golangci-lint --version \
468+
&& golangci-lint --version
469+
442470

443471
# revive installation
444-
&& go install github.com/mgechev/revive@latest && go clean --cache
472+
# Managed with COPY --link --from=revive /usr/bin/revive /usr/bin/revive
445473

446474
# checkstyle installation
447475
RUN --mount=type=secret,id=GITHUB_TOKEN CHECKSTYLE_LATEST=$(curl -s \
@@ -487,7 +515,7 @@ RUN wget --quiet https://github.com/pmd/pmd/releases/download/pmd_releases%2F${P
487515
&& find ${ML_THIRD_PARTY_DIR} -type f -not -name 'LICENSE*' -delete -o -type d -empty -delete \
488516

489517
# chktex installation
490-
# Managed with COPY --from=chktex /usr/bin/chktex /usr/bin/
518+
# Managed with COPY --link --from=chktex /usr/bin/chktex /usr/bin/
491519
&& cd ~ && touch .chktexrc && cd / \
492520

493521
# luacheck installation
@@ -506,9 +534,7 @@ RUN wget --quiet https://github.com/pmd/pmd/releases/download/pmd_releases%2F${P
506534
&& cd / \
507535

508536
# checkmake installation
509-
&& ( [ -d /usr/local/bin ] || mkdir -p /usr/local/bin ) \
510-
&& wget -q "https://github.com/mrtazz/checkmake/releases/download/0.2.1/checkmake-0.2.1.linux.amd64" -O /usr/local/bin/checkmake \
511-
&& chmod 755 /usr/local/bin/checkmake \
537+
# Managed with COPY --link --from=checkmake /checkmake /usr/bin/checkmake
512538

513539
# perlcritic installation
514540
&& curl --retry 5 --retry-delay 5 -sL https://cpanmin.us/ | perl - -nq --no-wget Perl::Critic
@@ -537,7 +563,7 @@ RUN composer global require --ignore-platform-reqs overtrue/phplint ^5.3 \
537563
# RUN pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force'
538564

539565
# protolint installation
540-
# Managed with COPY --from=protolint /usr/local/bin/protolint /usr/bin/
566+
# Managed with COPY --link --from=protolint /usr/local/bin/protolint /usr/bin/
541567

542568
# lintr installation
543569
&& mkdir -p /home/r-library \
@@ -565,18 +591,10 @@ ENV PATH="~/.raku/bin:/opt/rakudo-pkg/bin:/opt/rakudo-pkg/share/perl6/site/bin:$
565591
RUN dotnet tool install --global Microsoft.CST.DevSkim.CLI \
566592

567593
# dustilock installation
568-
&& ML_THIRD_PARTY_DIR=/download/dustilock && \
569-
mkdir -p ${ML_THIRD_PARTY_DIR} && \
570-
git clone https://github.com/Checkmarx/dustilock.git ${ML_THIRD_PARTY_DIR} && \
571-
cd ${ML_THIRD_PARTY_DIR} && \
572-
go build && go clean --cache && \
573-
chmod +x dustilock && \
574-
mv "${ML_THIRD_PARTY_DIR}/dustilock" /usr/bin/ && \
575-
find ${ML_THIRD_PARTY_DIR} -type f -not -name 'LICENSE*' -delete -o -type d -empty -delete && \
576-
cd / \
594+
# Managed with COPY --link --from=dustilock /usr/bin/dustilock /usr/bin/dustilock
577595

578596
# gitleaks installation
579-
# Managed with COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
597+
# Managed with COPY --link --from=gitleaks /usr/bin/gitleaks /usr/bin/
580598

581599
# syft installation
582600
&& curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin \
@@ -622,19 +640,19 @@ RUN dotnet tool install --global Microsoft.CST.DevSkim.CLI \
622640
&& dotnet tool install --global TSQLLint \
623641

624642
# tflint installation
625-
# Managed with COPY --from=tflint /usr/local/bin/tflint /usr/bin/
643+
# Managed with COPY --link --from=tflint /usr/local/bin/tflint /usr/bin/
626644

627645
# terrascan installation
628-
# Managed with COPY --from=terrascan /go/bin/terrascan /usr/bin/
646+
# Managed with COPY --link --from=terrascan /go/bin/terrascan /usr/bin/
629647

630648
# terragrunt installation
631-
# Managed with COPY --from=terragrunt /usr/local/bin/terragrunt /usr/bin/
649+
# Managed with COPY --link --from=terragrunt /usr/local/bin/terragrunt /usr/bin/
632650

633651
# terraform-fmt installation
634-
# Managed with COPY --from=terragrunt /bin/terraform /usr/bin/
652+
# Managed with COPY --link --from=terragrunt /bin/terraform /usr/bin/
635653

636654
# kics installation
637-
# Managed with COPY --from=kics /app/bin/kics /usr/bin/
655+
# Managed with COPY --link --from=kics /app/bin/kics /usr/bin/
638656
&& mkdir -p /opt/kics/assets
639657
ENV KICS_QUERIES_PATH=/opt/kics/assets/queries KICS_LIBRARIES_PATH=/opt/kics/assets/libraries
640658
# Managed with COPY --from=kics /app/bin/assets /opt/kics/assets/

flavors/ci_light/Dockerfile

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# MEGA-LINTER FLAVOR [ci_light]: Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML
1+
# syntax=docker/dockerfile:1
2+
# MEGALINTER FLAVOR [ci_light]: Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML
23
###########################################
34
###########################################
45
## Dockerfile to run MegaLinter ##
@@ -11,8 +12,10 @@
1112
## @generated by .automation/build.py using descriptor files, please do not update manually ##
1213
#############################################################################################
1314
#FROM__START
15+
FROM koalaman/shellcheck:stable as shellcheck
1416
FROM mvdan/shfmt:latest-alpine as shfmt
1517
FROM hadolint/hadolint:v2.12.0-alpine as hadolint
18+
FROM mrtazz/checkmake:latest as checkmake
1619
FROM zricethezav/gitleaks:v8.15.3 as gitleaks
1720
#FROM__END
1821

@@ -165,38 +168,34 @@ ENV PATH="/root/.cargo/bin:${PATH}"
165168
#############################################################################################
166169

167170
#COPY__START
168-
COPY --from=shfmt /bin/shfmt /usr/bin/
169-
COPY --from=hadolint /bin/hadolint /usr/bin/hadolint
170-
COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
171+
COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
172+
COPY --link --from=shfmt /bin/shfmt /usr/bin/
173+
COPY --link --from=hadolint /bin/hadolint /usr/bin/hadolint
174+
COPY --link --from=checkmake /checkmake /usr/bin/checkmake
175+
COPY --link --from=gitleaks /usr/bin/gitleaks /usr/bin/
171176
#COPY__END
172177

173178
#############################################################################################
174179
## @generated by .automation/build.py using descriptor files, please do not update manually ##
175180
#############################################################################################
176181
#OTHER__START
177182
# shellcheck installation
178-
RUN ML_THIRD_PARTY_DIR="/third-party/shellcheck" \
179-
&& mkdir -p ${ML_THIRD_PARTY_DIR} \
180-
&& wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv --directory ${ML_THIRD_PARTY_DIR} \
181-
&& mv "${ML_THIRD_PARTY_DIR}/shellcheck-stable/shellcheck" /usr/bin/ \
182-
&& find ${ML_THIRD_PARTY_DIR} -type f -not -name 'LICENSE*' -delete -o -type d -empty -delete \
183+
# Managed with COPY --link --from=shellcheck /bin/shellcheck /usr/bin/shellcheck
183184

184185
# shfmt installation
185-
# Managed with COPY --from=shfmt /bin/shfmt /usr/bin/
186+
# Managed with COPY --link --from=shfmt /bin/shfmt /usr/bin/
186187

187188
# hadolint installation
188-
# Managed with COPY --from=hadolint /bin/hadolint /usr/bin/hadolint
189+
# Managed with COPY --link --from=hadolint /bin/hadolint /usr/bin/hadolint
189190

190191
# dotenv-linter installation
191-
&& wget -q -O - https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s \
192+
RUN wget -q -O - https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s \
192193

193194
# checkmake installation
194-
&& ( [ -d /usr/local/bin ] || mkdir -p /usr/local/bin ) \
195-
&& wget -q "https://github.com/mrtazz/checkmake/releases/download/0.2.1/checkmake-0.2.1.linux.amd64" -O /usr/local/bin/checkmake \
196-
&& chmod 755 /usr/local/bin/checkmake \
195+
# Managed with COPY --link --from=checkmake /checkmake /usr/bin/checkmake
197196

198197
# gitleaks installation
199-
# Managed with COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/
198+
# Managed with COPY --link --from=gitleaks /usr/bin/gitleaks /usr/bin/
200199

201200
# trivy installation
202201
&& wget --tries=5 -q -O - https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin

0 commit comments

Comments
 (0)