From 23bdf4b3d81eae1bbb4cdde0e78cabee10410de2 Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Wed, 11 Jun 2025 01:13:28 +0100 Subject: [PATCH] build: replacing Earthly with Makefile & Docker build/run --- .github/renovate.json | 31 +++---- .github/workflows/continuous-integration.yml | 15 ++- .github/workflows/conventional-commits.yml | 10 +- .github/workflows/git-history.yml | 10 +- .../workflows/github-actions-workflows.yml | 16 +--- .github/workflows/mirroring.yml | 2 +- Earthfile | 91 ------------------- Makefile | 59 ++++++------ ci/check-clean-git-history.Dockerfile | 10 ++ ci/check-clean-git-history.sh | 11 --- ...ck-conventional-commits-linting.Dockerfile | 10 ++ ci/check-conventional-commits-linting.sh | 61 ------------- ci/check-github-actions-workflows-linting.sh | 6 -- ci/check-yaml-formatting.sh | 6 -- ci/compile.Dockerfile | 9 ++ ci/compile.sh | 6 -- ci/fix-yaml-formatting.sh | 6 -- ci/unit-test.Dockerfile | 10 ++ 18 files changed, 100 insertions(+), 269 deletions(-) delete mode 100644 Earthfile create mode 100644 ci/check-clean-git-history.Dockerfile delete mode 100755 ci/check-clean-git-history.sh create mode 100644 ci/check-conventional-commits-linting.Dockerfile delete mode 100755 ci/check-conventional-commits-linting.sh delete mode 100755 ci/check-github-actions-workflows-linting.sh delete mode 100755 ci/check-yaml-formatting.sh create mode 100644 ci/compile.Dockerfile delete mode 100755 ci/compile.sh delete mode 100755 ci/fix-yaml-formatting.sh create mode 100644 ci/unit-test.Dockerfile diff --git a/.github/renovate.json b/.github/renovate.json index 169997e..83f2242 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -6,7 +6,6 @@ "automerge": true, "dockerfile": { "managerFilePatterns": [ - "/(^|/)Earthfile$/", "/(^|/|\\.)Dockerfile$/", "/(^|/)Dockerfile[^/]*$/" ] @@ -15,7 +14,8 @@ { "customType": "regex", "managerFilePatterns": [ - "/^Earthfile$/" + "/(^|/|\\.)Dockerfile$/", + "/(^|/)Dockerfile[^/]*$/" ], "matchStrings": [ "# renovate: datasource=(?.*?) depName=(?.*?)( versioning=(?.*?))?\\s.+_VERSION=\"(?.*?)\"\\s" @@ -24,27 +24,18 @@ { "customType": "regex", "managerFilePatterns": [ - "/^Earthfile$/" + "/(^|/|\\.)Dockerfile$/", + "/(^|/)Dockerfile[^/]*$/" ], + "matchStringsStrategy": "recursive", "matchStrings": [ - "# renovate: datasource=repology depName=alpine_(?\\d+[._]\\d+)" + "FROM\\s*.*?alpine[.:]?(?\\d+)\\.(?\\d+)(?:\\n|.)*", + "apk\\s+add\\s+(?:\\n|.)*?[^\\\\]\\n", + "(?[^\\s=~]+)~?=(?[^\\s=]+)" ], - "currentValueTemplate": "{{{ replace '_' '.' currentValue }}}", - "datasourceTemplate": "docker", - "depNameTemplate": "alpine", - "versioningTemplate": "regex:^(?\\d+)[._](?\\d+)$", - "autoReplaceStringTemplate": "# renovate: datasource=repology depName=alpine_{{{newMajor}}}_{{{newMinor}}}" - }, - { - "customType": "regex", - "managerFilePatterns": [ - "/^[.]github/workflows//" - ], - "matchStrings": [ - ".*version: (?.*?)\\s" - ], - "datasourceTemplate": "github-tags", - "depNameTemplate": "earthly/earthly" + "datasourceTemplate": "repology", + "depNameTemplate": "alpine_{{alpineMajor}}_{{alpineMinor}}/{{name}}", + "versioningTemplate": "loose" } ] } diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7bcc436..73bb1f9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -18,4 +18,17 @@ jobs: - name: Checkout code. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Compile. - run: earthly --ci +compile + run: make compile + unit-test: + name: Unit Test + runs-on: ubuntu-latest + steps: + - name: Download Earthly. + uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # v1.0.13 + with: + version: v0.8.15 + - name: Checkout code. + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Unit Test. + run: make unit-test + diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml index 061cf2b..301b891 100644 --- a/.github/workflows/conventional-commits.yml +++ b/.github/workflows/conventional-commits.yml @@ -2,23 +2,15 @@ name: Conventional Commits on: pull_request -env: - # Forcing Earthly to use colours, to make reading output easier. - FORCE_COLOR: 1 - jobs: linting: name: Linting runs-on: ubuntu-latest steps: - - name: Download Earthly. - uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # v1.0.13 - with: - version: v0.8.15 - name: Checkout code. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 - name: Check Conventional Commits linting. - run: earthly --ci +check-conventional-commits-linting --from_reference "origin/${{ github.base_ref }}" + run: make check-conventional-commits-linting FROM="origin/${{ github.base_ref }}" diff --git a/.github/workflows/git-history.yml b/.github/workflows/git-history.yml index 35bcdf5..6e8d884 100644 --- a/.github/workflows/git-history.yml +++ b/.github/workflows/git-history.yml @@ -2,23 +2,15 @@ name: Git History on: pull_request -env: - # Forcing Earthly to use colours, to make reading output easier. - FORCE_COLOR: 1 - jobs: clean: name: Clean runs-on: ubuntu-latest steps: - - name: Download Earthly. - uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # v1.0.13 - with: - version: v0.8.15 - name: Checkout code. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 - name: Check clean Git history. - run: earthly --ci +check-clean-git-history --from "origin/${{ github.base_ref }}" + run: make check-clean-git-history FROM="origin/${{ github.base_ref }}" diff --git a/.github/workflows/github-actions-workflows.yml b/.github/workflows/github-actions-workflows.yml index d0c5b74..75ab549 100644 --- a/.github/workflows/github-actions-workflows.yml +++ b/.github/workflows/github-actions-workflows.yml @@ -2,32 +2,20 @@ name: GitHub Actions Workflows on: pull_request -env: - # Forcing Earthly to use colours, to make reading output easier. - FORCE_COLOR: 1 - jobs: linting: name: Linting runs-on: ubuntu-latest steps: - - name: Download Earthly. - uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # v1.0.13 - with: - version: v0.8.15 - name: Checkout code. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Check GitHub Actions workflows linting. - run: earthly +check-github-actions-workflows-linting + run: make check-github-actions-workflows-linting formatting: name: Formatting runs-on: ubuntu-latest steps: - - name: Download Earthly. - uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # v1.0.13 - with: - version: v0.8.15 - name: Checkout code. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Check formatting. - run: earthly +check-yaml-formatting + run: make check-yaml-formatting diff --git a/.github/workflows/mirroring.yml b/.github/workflows/mirroring.yml index c1d48ff..ac3b7a8 100644 --- a/.github/workflows/mirroring.yml +++ b/.github/workflows/mirroring.yml @@ -12,6 +12,6 @@ jobs: - name: Checkout code. run: git clone --mirror "https://github.com/${GITHUB_REPOSITORY}.git" "${GITHUB_WORKSPACE}" - name: Get GitLab repository. - run: echo "REPOSITORY_NAME=$(echo "${GITHUB_REPOSITORY}" | sed "s|^${GITHUB_REPOSITORY_OWNER}/||g")" >> "${GITHUB_ENV}" + run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY/${GITHUB_REPOSITORY_OWNER}/}" >> "${GITHUB_ENV}" - name: Mirroring. run: git push --mirror "https://oauth2:${{ secrets.GITLAB_PERSONAL_ACCESS_TOKEN }}@gitlab.com/DeveloperC/${REPOSITORY_NAME}" diff --git a/Earthfile b/Earthfile deleted file mode 100644 index 9512e4f..0000000 --- a/Earthfile +++ /dev/null @@ -1,91 +0,0 @@ -VERSION 0.7 - - -COPY_CI_DATA: - COMMAND - COPY --dir "ci/" ".github/" "./" - - -COPY_METADATA: - COMMAND - DO +COPY_CI_DATA - COPY --dir ".git/" "./" - - -alpine-base: - FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c - # renovate: datasource=repology depName=alpine_3_21/bash versioning=loose - ENV BASH_VERSION="5.2.37-r0" - RUN apk add --no-cache bash=$BASH_VERSION - WORKDIR "/nasm-x86-shellcode-generator" - - -check-clean-git-history: - FROM +alpine-base - # renovate: datasource=github-releases depName=DeveloperC286/clean_git_history - ENV CLEAN_GIT_HISTORY_VERSION="v1.0.3" - RUN wget -O - "https://github.com/DeveloperC286/clean_git_history/releases/download/${CLEAN_GIT_HISTORY_VERSION}/x86_64-unknown-linux-musl.tar.gz" | tar xz --directory "/usr/bin/" - DO +COPY_METADATA - ARG from="origin/HEAD" - RUN ./ci/check-clean-git-history.sh "${from}" - - -check-conventional-commits-linting: - FROM +alpine-base - # renovate: datasource=github-releases depName=DeveloperC286/conventional_commits_linter - ENV CONVENTIONAL_COMMITS_LINTER_VERSION="v0.14.3" - RUN wget -O - "https://github.com/DeveloperC286/conventional_commits_linter/releases/download/${CONVENTIONAL_COMMITS_LINTER_VERSION}/x86_64-unknown-linux-musl.gz" | gzip -d > /usr/bin/conventional_commits_linter && chmod 755 /usr/bin/conventional_commits_linter - DO +COPY_METADATA - ARG from_reference="origin/HEAD" - RUN ./ci/check-conventional-commits-linting.sh --from-reference "${from_reference}" - - -golang-base: - FROM golang:1.24.4@sha256:01f861b85f25cd045191578c87ed057b92bd185f2226bbf375c7510ebcb8abf4 - WORKDIR "/nasm-x86-shellcode-generator" - - -yaml-formatting-base: - FROM +golang-base - # renovate: datasource=github-releases depName=google/yamlfmt - ENV YAMLFMT_VERSION="v0.17.0" - RUN go install github.com/google/yamlfmt/cmd/yamlfmt@$YAMLFMT_VERSION - COPY ".yamlfmt" "./" - DO +COPY_CI_DATA - - -check-yaml-formatting: - FROM +yaml-formatting-base - RUN ./ci/check-yaml-formatting.sh - - -fix-yaml-formatting: - FROM +yaml-formatting-base - RUN ./ci/fix-yaml-formatting.sh - SAVE ARTIFACT ".github/" AS LOCAL "./" - - -check-github-actions-workflows-linting: - FROM +golang-base - # renovate: datasource=github-releases depName=rhysd/actionlint - ENV ACTIONLINT_VERSION="v1.7.7" - RUN go install github.com/rhysd/actionlint/cmd/actionlint@$ACTIONLINT_VERSION - DO +COPY_CI_DATA - RUN ./ci/check-github-actions-workflows-linting.sh - - -COPY_SOURCECODE: - COMMAND - DO +COPY_CI_DATA - COPY --dir "src/" "tests/" "./" - - -compile: - FROM +alpine-base - # renovate: datasource=repology depName=alpine_3_21/gcc versioning=loose - ENV GCC_VERSION="14.2.0-r4" - # renovate: datasource=repology depName=alpine_3_21/musl-dev versioning=loose - ENV MUSL_VERSION="1.2.5-r9" - RUN apk add --no-cache gcc=$GCC_VERSION musl-dev=$MUSL_VERSION - DO +COPY_SOURCECODE - RUN ./ci/compile.sh diff --git a/Makefile b/Makefile index 3718bc4..92d3355 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,46 @@ -# linux-x86-shellcode-generator -# See LICENSE file for copyright and license details. -.POSIX: +# So new files are owned by the user. +UID := $(shell id -u) +GID := $(shell id -g) -CC=gcc +.PHONY: check-clean-git-history check-conventional-commits-linting check-yaml-formatting fix-yaml-formatting check-github-actions-workflows-linting compile unit-test payload -SOURCE=src/shellcode-generator.c -OBJECT=shellcode-generator -CFLAGS= +check-clean-git-history: + docker build -t check-clean-git-history -f ci/check-clean-git-history.Dockerfile . + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) check-clean-git-history $(FROM) -TEST_SOURCE=tests/shellcode-generator-tests.c -TEST_OBJECT=shellcode-generator-tests -TEST_CFLAGS=-lcunit +check-conventional-commits-linting: + docker build -t check-conventional-commits-linting -f ci/check-conventional-commits-linting.Dockerfile . + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) check-conventional-commits-linting $(FROM) -PAYLOAD_SOURCE=output.c -PAYLOAD_OBJECT=output -PAYLOAD_CFLAGS=-m32 -fno-stack-protector -z execstack +check-yaml-formatting: + docker pull ghcr.io/google/yamlfmt:0.17.0 + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) ghcr.io/google/yamlfmt:0.17.0 -verbose -lint -dstar .github/workflows/* -.PHONY: all -all: $(OBJECT) +fix-yaml-formatting: + docker pull ghcr.io/google/yamlfmt:0.17.0 + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) ghcr.io/google/yamlfmt:0.17.0 -verbose -dstar .github/workflows/* -$(OBJECT): $(SOURCE) - $(CC) -o $(OBJECT) $(SOURCE) $(CFLAGS) +check-github-actions-workflows-linting: + docker pull rhysd/actionlint:1.7.7 + docker run --rm -v $(PWD):/workspace -w /workspace -u $(UID):$(GID) rhysd/actionlint:1.7.7 -verbose -color -.PHONY: clean -clean: - rm -f $(OBJECT) - rm -f $(TEST_OBJECT) - rm -f $(PAYLOAD_OBJECT) +compile: + docker build -t compile -f ci/compile.Dockerfile . + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) compile -.PHONY: test -test: $(TEST_OBJECT) - ./$(TEST_OBJECT) +unit-test: + docker build -t unit-test -f ci/unit-test.Dockerfile . + docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) unit-test -$(TEST_OBJECT): $(TEST_SOURCE) - $(CC) -o $(TEST_OBJECT) $(TEST_SOURCE) $(TEST_CFLAGS) +PAYLOAD_SOURCE=output.c +PAYLOAD_OBJECT=output +PAYLOAD_CFLAGS=-m32 -fno-stack-protector -z execstack -.PHONY: payload payload: $(PAYLOAD_OBJECT) ./$(PAYLOAD_OBJECT) $(PAYLOAD_OBJECT): $(PAYLOAD_SOURCE) $(CC) -o $(PAYLOAD_OBJECT) $(PAYLOAD_SOURCE) $(PAYLOAD_CFLAGS) + + + diff --git a/ci/check-clean-git-history.Dockerfile b/ci/check-clean-git-history.Dockerfile new file mode 100644 index 0000000..02010b2 --- /dev/null +++ b/ci/check-clean-git-history.Dockerfile @@ -0,0 +1,10 @@ +FROM rust:1.87.0-alpine3.21@sha256:fa7c28576553c431224a85c897c38f3a6443bd831be37061ab3560d9e797dc82 + +# renovate: datasource=github-releases depName=DeveloperC286/clean_git_history +ENV CLEAN_GIT_HISTORY_VERSION="v1.0.3" +RUN wget -O - "https://github.com/DeveloperC286/clean_git_history/releases/download/${CLEAN_GIT_HISTORY_VERSION}/x86_64-unknown-linux-musl.tar.gz" | tar xz --directory "/usr/bin/" + +WORKDIR /workspace + +ENTRYPOINT ["clean_git_history"] +CMD ["origin/HEAD"] diff --git a/ci/check-clean-git-history.sh b/ci/check-clean-git-history.sh deleted file mode 100755 index 93c4f5c..0000000 --- a/ci/check-clean-git-history.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env sh - -set -o errexit -set -o xtrace - -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -clean_git_history "$1" diff --git a/ci/check-conventional-commits-linting.Dockerfile b/ci/check-conventional-commits-linting.Dockerfile new file mode 100644 index 0000000..b13769e --- /dev/null +++ b/ci/check-conventional-commits-linting.Dockerfile @@ -0,0 +1,10 @@ +FROM rust:1.87.0-alpine3.21@sha256:fa7c28576553c431224a85c897c38f3a6443bd831be37061ab3560d9e797dc82 + +# renovate: datasource=github-releases depName=DeveloperC286/conventional_commits_linter +ENV CONVENTIONAL_COMMITS_LINTER_VERSION="v0.14.3" +RUN wget -O - "https://github.com/DeveloperC286/conventional_commits_linter/releases/download/${CONVENTIONAL_COMMITS_LINTER_VERSION}/x86_64-unknown-linux-musl.gz" | gzip -d >/usr/bin/conventional_commits_linter && chmod 755 /usr/bin/conventional_commits_linter + +WORKDIR /workspace + +ENTRYPOINT ["conventional_commits_linter", "--allow-angular-type-only", "--from-reference"] +CMD ["origin/HEAD"] diff --git a/ci/check-conventional-commits-linting.sh b/ci/check-conventional-commits-linting.sh deleted file mode 100755 index ea292ed..0000000 --- a/ci/check-conventional-commits-linting.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -# ARG_OPTIONAL_SINGLE([from-reference],[],[],[origin/HEAD]) -# ARGBASH_GO() -# needed because of Argbash --> m4_ignore([ -### START OF CODE GENERATED BY Argbash v2.9.0 one line above ### -# Argbash is a bash code generator used to get arguments parsing right. -# Argbash is FREE SOFTWARE, see https://argbash.io for more info -# Generated online by https://argbash.io/generate - -die() { - local _ret="${2:-1}" - test "${_PRINT_HELP:-no}" = yes && print_help >&2 - echo "$1" >&2 - exit "${_ret}" -} - -begins_with_short_option() { - local first_option all_short_options='' - first_option="${1:0:1}" - test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 -} - -# THE DEFAULTS INITIALIZATION - OPTIONALS -_arg_from_reference="origin/HEAD" - -print_help() { - printf 'Usage: %s [--from-reference ]\n' "$0" -} - -parse_commandline() { - while test $# -gt 0; do - _key="$1" - case "$_key" in - --from-reference) - test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 - _arg_from_reference="$2" - shift - ;; - --from-reference=*) - _arg_from_reference="${_key##--from-reference=}" - ;; - *) - _PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1 - ;; - esac - shift - done -} - -parse_commandline "$@" - -# OTHER STUFF GENERATED BY Argbash - -### END OF CODE GENERATED BY Argbash (sortof) ### ]) -# [ <-- needed because of Argbash -set -o errexit -set -o xtrace - -conventional_commits_linter --from-reference "${_arg_from_reference}" --allow-angular-type-only -# ] <-- needed because of Argbash diff --git a/ci/check-github-actions-workflows-linting.sh b/ci/check-github-actions-workflows-linting.sh deleted file mode 100755 index 81e88cc..0000000 --- a/ci/check-github-actions-workflows-linting.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env sh - -set -o errexit -set -o xtrace - -actionlint --verbose .github/workflows/* diff --git a/ci/check-yaml-formatting.sh b/ci/check-yaml-formatting.sh deleted file mode 100755 index d39cb5a..0000000 --- a/ci/check-yaml-formatting.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o xtrace - -yamlfmt -lint -dstar .github/**/* diff --git a/ci/compile.Dockerfile b/ci/compile.Dockerfile new file mode 100644 index 0000000..45c9d1f --- /dev/null +++ b/ci/compile.Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.22.0 + +RUN apk add --no-cache \ + gcc=14.2.0-r6 \ + build-base=0.5-r3 + +WORKDIR /workspace + +ENTRYPOINT ["gcc", "-o", "shellcode-generator", "src/shellcode-generator.c"] \ No newline at end of file diff --git a/ci/compile.sh b/ci/compile.sh deleted file mode 100755 index e2674c1..0000000 --- a/ci/compile.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env sh - -set -o errexit -set -o xtrace - -gcc -o "shellcode-generator" "src/shellcode-generator.c" diff --git a/ci/fix-yaml-formatting.sh b/ci/fix-yaml-formatting.sh deleted file mode 100755 index 7f5c712..0000000 --- a/ci/fix-yaml-formatting.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env sh - -set -o errexit -set -o xtrace - -yamlfmt -dstar ./github/**/* diff --git a/ci/unit-test.Dockerfile b/ci/unit-test.Dockerfile new file mode 100644 index 0000000..68db5ea --- /dev/null +++ b/ci/unit-test.Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.22.0 + +RUN apk add --no-cache \ + gcc=14.2.0-r6 \ + build-base=0.5-r3 \ + cunit-dev=2.1.3-r7 + +WORKDIR /workspace + +ENTRYPOINT ["gcc", "-o", "shellcode-generator-tests", "tests/shellcode-generator-tests.c", "-lcunit"] \ No newline at end of file