Skip to content

Commit

Permalink
fix: dockerlint command bug (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro authored May 2, 2022
1 parent c617dc0 commit c605ff4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
25 changes: 25 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2.1

promotion_requires: &promotion_requires
[
dockerlint,
hadolint,
orb-tools/pack,
test-check-command-docker,
Expand Down Expand Up @@ -176,6 +177,25 @@ jobs:
ls
exit 1
fi
test-dockerlint:
docker:
- image: cimg/node:17.7.2
parameters:
debug:
type: boolean
default: false
dockerfile:
type: string
default: "test.Dockerfile"
treat-warnings-as-errors:
type: boolean
default: false
steps:
- checkout
- docker/dockerlint:
debug: <<parameters.debug>>
dockerfile: <<parameters.dockerfile>>
treat-warnings-as-errors: <<parameters.treat-warnings-as-errors>>

workflows:
test-deploy:
Expand All @@ -186,6 +206,11 @@ workflows:
trusted-registries: docker.io,my-company.com:5000
dockerfiles: test.Dockerfile:test2.Dockerfile
filters: *filters
- test-dockerlint:
name: dockerlint
debug: true
treat-warnings-as-errors: false
filters: *filters
- test-pull:
filters: *filters
- test-create-workspace:
Expand Down
13 changes: 5 additions & 8 deletions src/commands/dockerlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ parameters:
steps:
- run:
name: Lint Dockerfile at <<parameters.dockerfile>>
command: |
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
npm install -g dockerlint<<^parameters.debug>> > /dev/null 2>&1<</parameters.debug>> || \
$SUDO npm install -g dockerlint<<^parameters.debug>> > /dev/null 2>&1<</parameters.debug>>
dockerlint<<#parameters.treat-warnings-as-errors>> -p<</parameters.treat-warnings-as-errors>> \
<<parameters.dockerfile>>
environment:
PARAM_DEBUG: <<parameters.debug>>
PARAM_TREAT_WARNING_AS_ERRORS: <<parameters.treat-warnings-as-errors>>
PARAM_DOCKERFILE: <<parameters.dockerfile>>
command: <<include(scripts/dockerlint.sh)>>
24 changes: 24 additions & 0 deletions src/scripts/dockerlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

if [[ $EUID == 0 ]]; then SUDO=""; else SUDO="sudo"; fi

if ! command -v dockerlint &> /dev/null; then
if ! command -v npm &> /dev/null; then
echo "npm is required to install dockerlint.";
echo "Consider running this command with an image that has node available: https://circleci.com/developer/images/image/cimg/node";
echo "Alternatively, use dockerlint's docker image: https://github.com/RedCoolBeans/dockerlint#docker-image."
exit 1
fi

if [ "$PARAM_DEBUG" = true ]; then
npm install -g dockerlint || "$SUDO" npm install -g dockerlint
else
npm install -g dockerlint &> /dev/null || "$SUDO" npm install -g dockerlint &> /dev/null
fi
fi

if [ "$PARAM_TREAT_WARNING_AS_ERRORS" = true ]; then
dockerlint -f "$PARAM_DOCKERFILE" -p
else
dockerlint -f "$PARAM_DOCKERFILE"
fi

0 comments on commit c605ff4

Please sign in to comment.