Skip to content

Commit

Permalink
Docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxthepilot committed Jan 21, 2023
1 parent 4647b68 commit 8bf7f2e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .env.wtfis.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Example ~/.env.wtfis file
# Don't forget to chmod 400!
VT_API_KEY = foo
PT_API_KEY = bar
PT_API_USER = [email protected]
IP2WHOIS_API_KEY = alice
SHODAN_API_KEY = hunter2
# WTFIS_DEFAULTS = "-s -1 -n"
VT_API_KEY=foo
PT_API_KEY=bar
PT_API_USER=[email protected]
IP2WHOIS_API_KEY=alice
SHODAN_API_KEY=hunter2
# WTFIS_DEFAULTS=-s -1 -n
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
####################################
# Builder image
####################################

FROM python:3.10-slim as builder

WORKDIR /workspace
COPY . .

# Install git
RUN apt-get update && \
apt-get install -y --no-install-recommends git

# Checkout latest tagged commit
RUN git checkout \
tags/$(git describe --tags $(git rev-list --tags --max-count=1)) \
-b latest_tag

# Ensure latest pip
RUN python -m pip install --upgrade pip

# Install hatch
RUN pip install hatch

# Clean build wheel and src tarball
RUN hatch build --clean


####################################
# Final image
####################################

FROM python:3.10-slim

# Create user and cd to work dir
RUN useradd --create-home --shell /bin/bash wtfis
WORKDIR /home/wtfis

# Copy wheel file from builder image
COPY --from=builder /workspace/dist/*.whl .

# Upgrade pip, install wheel and delete wheel file
RUN python -m pip install --upgrade pip && \
pip install *.whl && \
rm -f *.whl

# Run as user
USER wtfis

# Command
CMD ["bash"]
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PROJECT_NAME := wtfis
WTFIS_ENV_FILE := ${HOME}/.env.wtfis

# Build Docker image of the latest tagged commit
.PHONY: docker-image
docker-image:
docker build -t $(PROJECT_NAME) --rm .

# Run and exec into the Docker image
.PHONY: docker-run
docker-run:
docker run --env-file=$(WTFIS_ENV_FILE) -it wtfis
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,52 @@ Panels can be displayed with no color with `-n` or `--no-color`.
Default arguments can be defined by setting the `WTFIS_DEFAULTS` environment variable. For example, to use shodan and display results in one column by default:

```
WTFIS_DEFAULTS="-s -1"
WTFIS_DEFAULTS=-s -1
```

If an argument is in `WTFIS_DEFAULTS`, then specifying the same argument during command invocation **negates** that argument. So in the example above, if you then run:

```
wtfis example.com -s
$ wtfis example.com -s
```

then Shodan will NOT be used.

Note that maximum resolutions (`-m N, --max-resolutions N`) cannot be defined in defaults at the moment.


## Docker

wtfis can be run from a Docker image. First, build the image (using the included [Dockerfile](./Dockerfile)) by running:

```
$ make docker-image
```

The image will have the latest _tagged_ version (not necessarily from the latest commit) wtfis. This ensures that you are getting a stable release.

Two ways you can run the image:

Ensure `.env.wtfis` is in your home directory and set with the necessary envvars. Then simply run:

```
$ make docker-run
```

This is an alias to

```
$ docker run --env-file=${HOME}/.env.wtfis -it wtfis
```

Note that each definition must NOT have any spaces before and after the equal sign (`FOO=bar`, not `FOO = bar`).

Altenatively, you can set the environment variables yourself, then run, e.g.:

```
$ docker run -e VT_API_KEY -e SHODAN_API_KEY -it wtfis
```

## TODOs

* Consider adding Greynoise enrichment (RIOT, etc.)
Expand Down

0 comments on commit 8bf7f2e

Please sign in to comment.