diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9cdc907..91612ff 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 + 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 }} diff --git a/README.md b/README.md index 0846929..094e276 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dig/Dockerfile b/dig/Dockerfile new file mode 100644 index 0000000..04f193f --- /dev/null +++ b/dig/Dockerfile @@ -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"] \ No newline at end of file diff --git a/dig/dig.sh b/dig/dig.sh new file mode 100644 index 0000000..84ae7ea --- /dev/null +++ b/dig/dig.sh @@ -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 \ No newline at end of file diff --git a/stack.yml b/stack.yml index b8bc5fb..dd63e95 100644 --- a/stack.yml +++ b/stack.yml @@ -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