Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dig function #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
run: >
echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} |
tr '[:upper:]' '[:lower:]')
- name: Docker Login
run: >
echo ${{secrets.DOCKER_PASSWORD}} |
docker login ghcr.io --username
${{ steps.get_repo_owner.outputs.repo_owner }}
--password-stdin
- name: Login to Docker Registry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can revert this part now, since master appears to be working again.

uses: docker/login-action@v1
with:
username: ${{ steps.get_repo_owner.outputs.repo_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
- name: Publish functions
run: >
OWNER="${{ steps.get_repo_owner.outputs.repo_owner }}"
OWNER="${{ steps.get_repo_owner.outputs.repo_owner }}"
TAG="latest"
faas-cli publish
--extra-tag ${{ github.sha }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ curl http://127.0.0.1:8080 -d "-c 5 -n 1000 https://your-service.com/"

* `alpine` - a base for running built-in bash or busybox commands like `env` (use it to debug headers) or `wc -l` to count text within a body
* `curl` - debug outgoing networking or internal services
* `dig` - debug DNS resolution from inside your cluster
* `figlet` - print ASCII logso
* `hey` - run a load-test against a HTTP API, website, or function with [hey](https://github.com/rakyll/hey)
* `nmap` - scan a network range
Expand Down
40 changes: 40 additions & 0 deletions dig/Dockerfile
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"]
24 changes: 24 additions & 0 deletions dig/dig.sh
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
5 changes: 5 additions & 0 deletions stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ functions:
handler: ./curl
image: ghcr.io/${OWNER:-openfaas}/curl:${TAG:-latest}

dig:
lang: dockerfile
handler: ./dig
image: ghcr.io/${OWNER:-openfaas}/dig:${TAG:-latest}

shasum:
lang: dockerfile
handler: ./shasum
Expand Down