Skip to content

Commit

Permalink
[[FEAT]] Add initial Docker/Containerfile
Browse files Browse the repository at this point in the history
Having a local Containerfile allows anybody to build JSHint containers.
Better yet, it allows JSHint to supply official Docker containers for
users to use, rather then 'random containers from the internet'.

Note, that Containerfile is a modern way to signify agnostic Containers.
Internally, they are 100% pure Dockerfile's but for wider acceptance and
inclusion, Containerfile is the modern take.

The `--file Containerfile` argument might be needed for whichever
builder is used.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
  • Loading branch information
oliv3r committed Feb 26, 2022
1 parent 8a68ac2 commit 984d208
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ jobs:
- run:
name: run tests
command: npm run test-node
build-container:
machine:
image: ubuntu-2004:202111-02
steps:
- checkout
- run:
name: Build container
command: docker build --file 'Containerfile' --rm --tag 'jshint:latest' .

workflows:
orb-free-workflow:
Expand Down
6 changes: 6 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
failure-threshold: "style"
ignored:
- DL3007
- DL3008
- DL3013
- DL3018
53 changes: 53 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2022 Olliver Schinagl <oliver@schinagl.nl>

FROM index.docker.io/library/alpine:latest AS builder

WORKDIR /src

COPY . /src/

RUN apk add --no-cache \
git \
nodejs-current \
npm \
&& \
npm ci \
--no-fund \
--production \
--verbose \
&& \
mkdir -p '/jshint/node_modules/jshint' && \
cp -a 'node_modules/' '/jshint/' && \
cp -a 'bin/' 'data/' 'dist/' 'src/' 'package.json' \
'/jshint/node_modules/jshint' && \
npm ci \
--no-audit \
--no-fund \
--verbose \
&& \
npm run pretest && \
npm run test-262 && \
npm run test-node && \
npm run test-website && \
node '/jshint/node_modules/jshint/bin/jshint' --version


FROM index.docker.io/library/alpine:latest

LABEL maintainer="Olliver Schinagl <oliver@schinagl.nl>"

RUN apk add --no-cache \
nodejs-current \
&& \
addgroup -S 'jshint' && \
adduser -D -G 'jshint' -h '/var/lib/jshint' -s '/bin/false' -S 'jshint' && \
ln -f -n -s '/usr/local/lib/node_modules/jshint/bin/jshint' '/usr/local/bin/jshint'

COPY --from=builder "/jshint/node_modules/" "/usr/local/lib/node_modules"
COPY "./containerfiles/container-entrypoint.sh" "/init"

ENTRYPOINT [ "/init" ]

USER 'jshint'
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,44 @@ Engineers from these companies and projects use JSHint:

And many more!

## Using JSHint

### Containers

JSHint provides an official Container that can be used to run JSHint. To build
a container using docker for example:

```console
$ docker build --file 'Containerfile' --rm --tag 'jshint:latest' .
```

Running the container is then as trivial as:

```console
$ docker run --rm --interactive --tty jshint:latest --help
```

To lint entire directories, a
[docker volume mount](https://docs.docker.com/storage/volumes/) is needed,
as otherwise the container does not have access to the code. In the following
example the `pwd` utility is used, but other ways are of course possible.

```console
<path_to_lint> $ docker run --rm --interactive --tty --volume "$(pwd):$(pwd)" --workdir "$(pwd)" jshint:latest "$(pwd)"
```

To lint something quickly using stdin, `jshint` needs to be told to take its
input from stdin via the `-` marker. The following example also shows how to
pass additional options to the container:

```console
$ docker run --rm --interactive jshint:latest --show-non-errors - < file.js
```

> __Note:__ It is very common to see the `--tty` (the `t` in `-it`) flag for
> interactive containers. However when using stdin, this is not correct.

## License

JSHint is licensed under [the MIT Expat
Expand Down
22 changes: 22 additions & 0 deletions containerfiles/container-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2022 Olliver Schinagl <oliver@schinagl.nl>
#
# A beginning user should be able to docker run image bash (or sh) without
# needing to learn about --entrypoint
# https://github.com/docker-library/official-images#consistency

set -eu

# run command if it is not starting with a "-" and is an executable in PATH
if [ "${#}" -le 0 ] || \
[ "${1#-}" != "${1}" ] || \
[ -d "${1}" ] || \
! command -v "${1}" > '/dev/null' 2>&1; then
bin='jshint'
fi

exec ${bin:+${bin}} "${@}"

exit 0

0 comments on commit 984d208

Please sign in to comment.