Skip to content

Instantly share code, notes, and snippets.

@realFranco
Last active April 29, 2023 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realFranco/608915c31f8174f6121501cd78ae3b5f to your computer and use it in GitHub Desktop.
Save realFranco/608915c31f8174f6121501cd78ae3b5f to your computer and use it in GitHub Desktop.
Linter `.sh` and `Dockerifle` files. #docker #bash #shell #hadolint #shellcheck

shellcheck

Linter for bash.

https://github.com/koalaman/shellcheck

docker pull koalaman/shellcheck:v0.9.0

docker run --rm -it koalaman/shellcheck:v0.9.0 --version

docker run --rm -it -v "$(pwd):/app" koalaman/shellcheck:v0.9.0 /app/src/script.sh

hadolint

Linter for Dockerfile files.

https://github.com/hadolint/hadolint

docker pull hadolint/hadolint

docker run --rm -i -v "$(pwd):/app" hadolint/hadolint hadolint --help

docker run --rm -i -v "$(pwd):/app" hadolint/hadolint hadolint /app/src/Dockerfile

docker run --rm -i -v "$(pwd):/app" hadolint/hadolint hadolint /app/src/Dockerfile-Ali

Dockerfile linter results

docker run --rm -i -v "$(pwd):/app" hadolint/hadolint hadolint /app/src/Dockerfile-Ali

/app/src/Dockerfile-Ali:10 DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
/app/src/Dockerfile-Ali:10 DL3019 info: Use the `--no-cache` switch to avoid the need to use `--update` and remove `/var/cache/apk/*` when done installing packages
/app/src/Dockerfile-Ali:14 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
/app/src/Dockerfile-Ali:34 DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
/app/src/Dockerfile-Ali:34 DL3019 info: Use the `--no-cache` switch to avoid the need to use `--update` and remove `/var/cache/apk/*` when done installing packages
/app/src/Dockerfile-Ali:38 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.

Shell linter results

docker run --rm -it -v "$(pwd):/app" koalaman/shellcheck:v0.9.0 /app/src/script.sh

In /app/src/script.sh line 1:
echo "Script"
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.


In /app/src/script.sh line 4:
export a = 1  
         ^-- SC2290 (error): Remove spaces around = to assign.

For more information:
  https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...
  https://www.shellcheck.net/wiki/SC2290 -- Remove spaces around = to assign.
# Stage 1: Build the Angular app
FROM node:11.15.0-alpine as build
WORKDIR /app
COPY . .
# Se instala automake para que se pueda ejecutar un comando
# que tiene que ver con 'gifsicle' que es una dependencia tiene un script de postinstall
# que se va a ejecutar después de ejecutar el npm install
#En este caso se agrega zlib-dev porque es una dependencia para el build
RUN apk add autoconf automake alpine-sdk nasm zlib-dev
# Se utiliza --unsafe-perm para que se pueda ejecutar el script de 'postinstall' de npm
# que sirve para instalar las dependencias de bower
RUN npm install --unsafe-perm
# Se utiliza el argumento 'configuration' para poder definir el environment
ARG CONFIGURATION=production
RUN npm run build -- --configuration=$CONFIGURATION
# Stage 2: Serve the Angular app with Nginx
FROM nginx:1.23.4-alpine as nginx
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# Stage 3: Serve the Angular app with ng serve
FROM node:11.15.0-alpine as serve
WORKDIR /app
COPY . .
# Se instala automake para que se pueda ejecutar un comando
# que tiene que ver con 'gifsicle' que es una dependencia tiene un script de postinstall
# que se va a ejecutar después de ejecutar el npm install
RUN apk add autoconf automake alpine-sdk nasm
# Se utiliza --unsafe-perm para que se pueda ejecutar el script de 'postinstall' de npm
# que sirve para instalar las dependencias de bower
RUN npm install --unsafe-perm
EXPOSE 8080
CMD ["npm", "run", "serve"]
echo "Script"
# Based on `shellcheck` tool this is statement can improved.
export a = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment