-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**What** - Add a `dig` function that can be used to verify DNS resultion inside a cluster. The function is implemented as a small bash script that invokes `dig` and then returns the result as JSON or text, depending on an ENV configuration. This function can also be used to demonstrate how to lightly wrap the CLI tool and provide some logging to stderr To test ```sh $ faas-cli build --filter dig $ docker run --name digtest --rm -p 8080:8080 ghcr.io/openfaas/dig:latest $ curl localhost:8080 -d "google.com" {"ip_address": "172.217.23.110"} $ docker kill digtest ``` Signed-off-by: Lucas Roesler <[email protected]>
- Loading branch information
1 parent
75d6169
commit ad2ad3f
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.8.4 as watchdog | ||
|
||
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.13 | ||
|
||
RUN mkdir -p /home/app | ||
|
||
RUN apk add --no-cache bind-tools | ||
|
||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
|
||
# Add non root user | ||
RUN addgroup -S app && adduser app -S -G app | ||
RUN chown app /home/app | ||
|
||
WORKDIR /home/app | ||
|
||
USER app | ||
|
||
COPY --chown=app:app dig.sh . | ||
RUN chmod +x dig.sh | ||
|
||
# customize the json key name for the success responses | ||
ENV response_key="ip_address" | ||
|
||
# configure of-watchdog | ||
# https://github.com/openfaas/of-watchdog#configuration | ||
ENV fprocess="/home/app/dig.sh" | ||
ENV mode="streaming" | ||
ENV content_type="application/json" | ||
ENV suppress_lock="false" | ||
ENV prefix_logs="false" | ||
# Set to true to see request in function logs | ||
ENV write_debug="false" | ||
|
||
EXPOSE 8080 | ||
|
||
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
CMD ["fwatchdog"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env sh | ||
|
||
|
||
# write log message to stderr | ||
log() { | ||
echo "$@" 1>&2; | ||
} | ||
|
||
IFS='' read -d '' -r request | ||
response=$(dig "$request" +short 2>&1) | ||
status=$? | ||
|
||
log "request=\"$request\" response=\"$response\" content_type=\"$content_type\"" | ||
|
||
if [ "$content_type" = "application/json" ]; then | ||
key="error" | ||
if [ $status -eq 0 ]; then | ||
key="${response_key:-response}" | ||
fi | ||
|
||
echo "{\"$key\": \"$response\"}" | ||
else | ||
echo "$response" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters