Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Docker container as current user #1985

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ def generate_flavor(flavor, flavor_info):
file.write(action_yml)
logging.info(f"Updated {flavor_action_yml}")
extra_lines = [
"COPY entrypoint.sh /entrypoint.sh",
"COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh",
"RUN chmod +x entrypoint.sh",
"USER 1000",
'ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]',
]
build_dockerfile(
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/test-mega-linter-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ jobs:
node-version: "12"
- name: Install dependencies
run: cd mega-linter-runner && yarn install --frozen-lockfile && npm link
- name: Run tests
run: cd mega-linter-runner && npm run test
- name: Run CLI tests
run: cd mega-linter-runner && npm run test:cli
- name: Run module tests
if: always()
run: cd mega-linter-runner && npm run test:module
- name: Run upgrade tests
if: always()
run: cd mega-linter-runner && npm run test:upgrade
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Upgrade create-pull-request and create-or-update-comment GitHub Actions
- Increase auto-update-linters GitHub Action timeout
- Upgrade base Docker image to python:3.11.3-alpine3.17
- Make Docker image rootless, and run it as user 1000 rather than root by
@Kurt-von-Laven in [#1975](https://github.com/oxsecurity/megalinter/issues/1975).

- Documentation

Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ ENV KICS_QUERIES_PATH=/opt/kics/assets/queries KICS_LIBRARIES_PATH=/opt/kics/ass
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -677,8 +677,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -717,7 +717,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/ci_light/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ RUN wget -q -O - https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/m
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -218,8 +218,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -258,7 +258,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/cupcake/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ ENV KICS_QUERIES_PATH=/opt/kics/assets/queries KICS_LIBRARIES_PATH=/opt/kics/ass
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -459,8 +459,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -499,7 +499,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/documentation/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -305,8 +305,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -345,7 +345,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/dotnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ RUN curl --retry 5 --retry-delay 5 -sLO "${ARM_TTK_URI}" \
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -400,8 +400,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -440,7 +440,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -320,8 +320,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -360,7 +360,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ RUN wget --quiet https://github.com/pmd/pmd/releases/download/pmd_releases%2F${P
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -333,8 +333,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -373,7 +373,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/javascript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -321,8 +321,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -361,7 +361,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ RUN composer global require --ignore-platform-reqs overtrue/phplint ^5.3 \
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -349,8 +349,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -389,7 +389,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -316,8 +316,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -356,7 +356,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/ruby/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -306,8 +306,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -346,7 +346,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
9 changes: 5 additions & 4 deletions flavors/rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: Fil
################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
COPY --chown=1000:1000 megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
Expand All @@ -300,8 +300,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation

###########################
# Get the build arguments #
Expand Down Expand Up @@ -340,7 +340,8 @@ LABEL com.github.actions.name="MegaLinter" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
COPY --chown=1000:1000 entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
USER 1000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
Loading