From cac35b475cdb78093ff2e31e02a4719315ce17d4 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 15:23:05 +0700 Subject: [PATCH 1/9] Add more tools --- Dockerfile | 5 ++++- README.md | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 17d1910..db4a5ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,4 +39,7 @@ RUN apk add --no-cache --update \ bind-tools \ busybox-extras \ lz4 zstd \ - vim + vim \ + openssl \ + ipset \ + ripgrep diff --git a/README.md b/README.md index 8758ce2..9d45aa4 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,19 @@ kubectl exec -it nettools -n default bash ```sh docker run -it ghcr.io/duyhenryer/nettools:2.0.1 sh +``` + +#### Sample Use-cases + +`tcpdump` is a powerful and common packet analyzer that runs under the command line. +It allows the user to display TCP/IP and other packets being transmitted or received over an attached network interface. + +```sh +tcpdump -i eth0 port 9999 -c 1 -Xvv +``` +More info on tcpdump can be found [here](http://www.tcpdump.org/tcpdump_man.html). + +`netstat` is a useful tool for checking your network configuration and activity. +```sh +netstat -tulpn ``` \ No newline at end of file From 29e2101c2f94660f1ca44ef515b9fe2f2a4571d6 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 15:58:46 +0700 Subject: [PATCH 2/9] Add workflows check pr --- .github/workflows/pr-build.yml | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/pr-build.yml diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml new file mode 100644 index 0000000..2c03bea --- /dev/null +++ b/.github/workflows/pr-build.yml @@ -0,0 +1,93 @@ +name: PR-Build + +run-name: PR Build Image + +on: + pull_request: + branches: ['main'] + +jobs: + pr-build: + # https://github.com/actions/runner-images + runs-on: ubuntu-latest + + steps: + # checkout + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # all history for tags and branches, needed to resolve tag->branch name + + # https://docs.docker.com/build/ci/github-actions/multi-platform/ + # QEMU for software emulation of multiple platforms + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + # Docker buildx/buildkit for multi-platform builds + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + # debug + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + + # debug github context and env + - name: Dump env + run: env | sort + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + + - name: calculate branch name IF tag + if: github.ref_type == 'tag' # 'branch' if regular push + run: | + echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" + echo "GITHUB_SHA = $GITHUB_SHA" + short_sha=`git rev-parse --short $GITHUB_SHA` + echo "short SHA = $short_sha" + echo candidates for branch name + git for-each-ref | grep ^$GITHUB_SHA | grep origin | grep -v HEAD + branch_name=`git for-each-ref | grep ^$GITHUB_SHA | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` + echo tag $GITHUB_REF_NAME is on branch $branch_name + + # tags and labels + - name: Extract metadata (tags, labels) for image ${{ env.FULL_IMAGE_NAME }} + id: meta + uses: docker/metadata-action@v4 + with: + # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images + images: | + ${{ env.GH_REGISTRY }}/${{ env.FULL_IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=ref,event=pr + type=ref,event=branch + # in addition to full semantic version (x.y.z) would also create (x.y) + #type=semver,pattern={{major}}.{{minor}} + + - name: Get fresh build arguments + shell: bash + run: echo -e "BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')\nGITREF=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + id: get_buildargs + + - name: Run PR Build + uses: docker/build-push-action@v5 + with: + context: . + push: false + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + MY_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + MY_BUILTBY=github-action + BUILD_TIME=${{ steps.get_buildargs.outputs.BUILD_TIME }} + GITREF=${{ steps.get_buildargs.outputs.GITREF }} + GITREF_long="${{ github.sha }}" \ No newline at end of file From 68d16808e388e21db1d84ce326719810f850bc45 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:01:51 +0700 Subject: [PATCH 3/9] Add workflows check pr --- .github/workflows/pr-build.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 2c03bea..79250fc 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -12,6 +12,12 @@ jobs: runs-on: ubuntu-latest steps: + + # debug + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event from ${{ github.actor }}." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + # checkout - name: Check out repository code uses: actions/checkout@v4 @@ -25,9 +31,6 @@ jobs: # Docker buildx/buildkit for multi-platform builds - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} # debug - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." @@ -77,7 +80,7 @@ jobs: run: echo -e "BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')\nGITREF=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT id: get_buildargs - - name: Run PR Build + - name: Build PR Image uses: docker/build-push-action@v5 with: context: . From e642e5606823edc1b64d2934a19d87b1e136134e Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:05:07 +0700 Subject: [PATCH 4/9] fix check tag --- .github/workflows/pr-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 79250fc..7e951b3 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - + # debug - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event from ${{ github.actor }}." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" @@ -48,8 +48,8 @@ jobs: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - name: calculate branch name IF tag - if: github.ref_type == 'tag' # 'branch' if regular push + - name: calculate branch name IF branch + if: github.ref_type == 'branch' # 'branch' if regular push run: | echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" echo "GITHUB_SHA = $GITHUB_SHA" From cb6bab201571623d5c71a05f893932dc95991551 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:08:39 +0700 Subject: [PATCH 5/9] fix check tag --- .github/workflows/pr-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 7e951b3..4dfc0bd 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -52,12 +52,12 @@ jobs: if: github.ref_type == 'branch' # 'branch' if regular push run: | echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" - echo "GITHUB_SHA = $GITHUB_SHA" - short_sha=`git rev-parse --short $GITHUB_SHA` + echo "GITHUB_SHA = ${{ github.event.pull_request.head.sha }}" + short_sha=`git rev-parse --short ${{ github.event.pull_request.head.sha }}` echo "short SHA = $short_sha" echo candidates for branch name - git for-each-ref | grep ^$GITHUB_SHA | grep origin | grep -v HEAD - branch_name=`git for-each-ref | grep ^$GITHUB_SHA | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` + git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD + branch_name=`git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` echo tag $GITHUB_REF_NAME is on branch $branch_name # tags and labels From a787b54ee34198bb16b63103958cb937deaee29c Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:14:05 +0700 Subject: [PATCH 6/9] fix check tag --- .github/workflows/pr-build.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 4dfc0bd..3a4f44e 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -48,6 +48,18 @@ jobs: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" + # - name: calculate branch name IF branch + # if: github.ref_type == 'branch' # 'branch' if regular push + # run: | + # echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" + # echo "GITHUB_SHA = ${{ github.event.pull_request.head.sha }}" + # short_sha=`git rev-parse --short ${{ github.event.pull_request.head.sha }}` + # echo "short SHA = $short_sha" + # echo candidates for branch name + # git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD + # branch_name=`git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` + # echo tag $GITHUB_REF_NAME is on branch $branch_name + - name: calculate branch name IF branch if: github.ref_type == 'branch' # 'branch' if regular push run: | From 241790bfec478ec4c878ee54c62d697d3829e9b4 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:16:39 +0700 Subject: [PATCH 7/9] fix check tag --- .github/workflows/pr-build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 3a4f44e..015d78e 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -67,10 +67,7 @@ jobs: echo "GITHUB_SHA = ${{ github.event.pull_request.head.sha }}" short_sha=`git rev-parse --short ${{ github.event.pull_request.head.sha }}` echo "short SHA = $short_sha" - echo candidates for branch name - git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD - branch_name=`git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` - echo tag $GITHUB_REF_NAME is on branch $branch_name + branch_name=$short_sha # tags and labels - name: Extract metadata (tags, labels) for image ${{ env.FULL_IMAGE_NAME }} From a60ffd7f1d59b14a83209be4fe621b0c771ffc2a Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:23:30 +0700 Subject: [PATCH 8/9] fix check tag --- .github/workflows/pr-build.yml | 98 +++++----------------------------- 1 file changed, 13 insertions(+), 85 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 015d78e..03fe029 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -12,94 +12,22 @@ jobs: runs-on: ubuntu-latest steps: - - # debug - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event from ${{ github.actor }}." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - # checkout - - name: Check out repository code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # all history for tags and branches, needed to resolve tag->branch name - - # https://docs.docker.com/build/ci/github-actions/multi-platform/ - # QEMU for software emulation of multiple platforms + - name: Checkout + uses: actions/checkout@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # Docker buildx/buildkit for multi-platform builds + with: + platforms: arm64,amd64 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # debug - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." + id: buildx + uses: docker/setup-buildx-action@v2 - # debug github context and env - - name: Dump env - run: env | sort - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} - # - name: calculate branch name IF branch - # if: github.ref_type == 'branch' # 'branch' if regular push - # run: | - # echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" - # echo "GITHUB_SHA = ${{ github.event.pull_request.head.sha }}" - # short_sha=`git rev-parse --short ${{ github.event.pull_request.head.sha }}` - # echo "short SHA = $short_sha" - # echo candidates for branch name - # git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD - # branch_name=`git for-each-ref | grep ^$short_sha | grep origin | grep -v HEAD | head -n1 | sed "s/.*\///"` - # echo tag $GITHUB_REF_NAME is on branch $branch_name - - - name: calculate branch name IF branch - if: github.ref_type == 'branch' # 'branch' if regular push + - name: Run Buildx run: | - echo "GITHUB_REF_NAME = $GITHUB_REF_NAME" - echo "GITHUB_SHA = ${{ github.event.pull_request.head.sha }}" - short_sha=`git rev-parse --short ${{ github.event.pull_request.head.sha }}` - echo "short SHA = $short_sha" - branch_name=$short_sha - - # tags and labels - - name: Extract metadata (tags, labels) for image ${{ env.FULL_IMAGE_NAME }} - id: meta - uses: docker/metadata-action@v4 - with: - # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images - images: | - ${{ env.GH_REGISTRY }}/${{ env.FULL_IMAGE_NAME }} - tags: | - type=semver,pattern={{version}} - type=ref,event=pr - type=ref,event=branch - # in addition to full semantic version (x.y.z) would also create (x.y) - #type=semver,pattern={{major}}.{{minor}} - - - name: Get fresh build arguments - shell: bash - run: echo -e "BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')\nGITREF=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - id: get_buildargs - - - name: Build PR Image - uses: docker/build-push-action@v5 - with: - context: . - push: false - platforms: linux/amd64,linux/arm64,linux/arm/v7 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - MY_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - MY_BUILTBY=github-action - BUILD_TIME=${{ steps.get_buildargs.outputs.BUILD_TIME }} - GITREF=${{ steps.get_buildargs.outputs.GITREF }} - GITREF_long="${{ github.sha }}" \ No newline at end of file + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --output "type=image,push=false" \ + --file ./Dockerfile . \ No newline at end of file From cdde9067859c8b64ab6b076fc6a41bca68453cb7 Mon Sep 17 00:00:00 2001 From: duyhenryer Date: Wed, 27 Mar 2024 16:28:27 +0700 Subject: [PATCH 9/9] update v4 --- .github/workflows/pr-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 03fe029..91561ab 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -13,14 +13,14 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: arm64,amd64 - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Available platforms run: echo ${{ steps.buildx.outputs.platforms }}