From d7a4292382f6d5585a7a9acdc1b5cc5fd3e588d3 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 18:20:10 +1300 Subject: [PATCH 01/12] pkg(python): 2.7.1 doesn't build properly --- packages/python.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/python.mk b/packages/python.mk index 02fe442..d0aa0ab 100644 --- a/packages/python.mk +++ b/packages/python.mk @@ -2,7 +2,7 @@ NAME=python AUTHOR=Thomas Hobson DEPENDENCIES= COMPILED=false -VERSIONS=2.7.1 3.5.1 3.9.1 +VERSIONS=3.5.1 3.9.1 include common.mk @@ -15,6 +15,7 @@ ${ENV_FILE}: ${BIN_DIR}: ${BUILD_DIR}Python-${VERSION}/ $(eval TMP_DIR=${PWD}/${BUILD_DIR}tmpout/) + cd $< && ./configure --prefix ${PREFIX} $(MAKE) -C $< DESTDIR=${TMP_DIR} $(MAKE) -C $< altinstall From 1ab3f463d0156cac4d31efb874fa5165e1e56f79 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 18:20:41 +1300 Subject: [PATCH 02/12] pkg(Makefile): add language specific build rules --- packages/Makefile | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/Makefile b/packages/Makefile index 91124e2..44fe47c 100644 --- a/packages/Makefile +++ b/packages/Makefile @@ -5,6 +5,8 @@ PKG_FILES=$(filter-out common.mk,$(wildcard *.mk)) PKG_SLUGS=$(foreach pkg, ${PKG_FILES}, $(addprefix $(shell make -f ${pkg} name VERSION=UNKNOWN)-, $(shell make -f ${pkg} versions VERSION=UNKNOWN))) # Functions +CALL_MAKE=$(shell make -f $1 $2 VERSION=UNKNOWN) + define pkg_info $(eval PKG_SLUG=$(patsubst $1-%,%,$2)) $(eval PKG_VERSION=$(lastword $(subst -, ,${PKG_SLUG}))) @@ -12,18 +14,27 @@ define pkg_info $(eval PKG_FILE=$(shell grep '^VERSIONS\s*=.*${PKG_VERSION}' $(shell grep "NAME\s*=\s*${PKG_NAME}" ${PKG_FILES} -l) -l)) endef +define per-lang +build-$(call CALL_MAKE, $1, name):: $$(addprefix build-$(call CALL_MAKE, $1, name)-, $$(call CALL_MAKE, $1, versions)) +clean-$(call CALL_MAKE, $1, name):: $$(addprefix clean-$(call CALL_MAKE, $1, name)-, $$(call CALL_MAKE, $1, versions)) +endef + + # Targets -build: $(foreach pkg, ${PKG_FILES}, $(addprefix build-$(shell make -f ${pkg} name VERSION=UNKNOWN)-, $(lastword $(shell make -f ${pkg} versions VERSION=UNKNOWN)))) +$(foreach e,${PKG_FILES}, $(eval $(call per-lang,${e}))) + +build build-all: $(foreach pkg, ${PKG_FILES}, build-$(call CALL_MAKE, ${pkg}, name)) $(addprefix build-, ${PKG_SLUGS}): $(call pkg_info,build,$@) $(MAKE) -f ${PKG_FILE} VERSION=${PKG_VERSION} build - - -clean: $(foreach pkg, ${PKG_FILES}, $(addprefix clean-$(shell make -f ${pkg} name VERSION=UNKNOWN)-, $(shell make -f ${pkg} versions VERSION=UNKNOWN))) +clean clean-all: $(foreach pkg, ${PKG_FILES}, clean-$(call CALL_MAKE, ${pkg}, name)) rm -rf build/ + $(addprefix clean-, ${PKG_SLUGS}): $(call pkg_info,clean,$@) $(MAKE) -f ${PKG_FILE} VERSION=${PKG_VERSION} clean + + From 1dd9e1a738844ca122419da8e96c8fc68ce872a0 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 18:23:28 +1300 Subject: [PATCH 03/12] repo: allow individual package building --- repo/Dockerfile | 5 ++++- repo/entrypoint.sh | 10 ++++++++++ repo/make.sh | 13 ------------- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100755 repo/entrypoint.sh delete mode 100755 repo/make.sh diff --git a/repo/Dockerfile b/repo/Dockerfile index 8980d53..35201e0 100644 --- a/repo/Dockerfile +++ b/repo/Dockerfile @@ -5,4 +5,7 @@ RUN apt-get update && apt-get install -y autoconf build-essential libssl-dev pkg pip3 install 'yq==2.12.0' && \ rm -rf /var/lib/apt/lists/* -CMD [ "bash", "/repo/make.sh" ] \ No newline at end of file +ADD *.sh / + +ENTRYPOINT ["bash","/entrypoint.sh"] +CMD ["all"] diff --git a/repo/entrypoint.sh b/repo/entrypoint.sh new file mode 100755 index 0000000..bd958ab --- /dev/null +++ b/repo/entrypoint.sh @@ -0,0 +1,10 @@ +cd /packages +for pkg in "$*" +do + make -j16 build-$pkg +done + +cd /repo +./mkindex.sh + +curl -s http://piston_api:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml" diff --git a/repo/make.sh b/repo/make.sh deleted file mode 100755 index bad392e..0000000 --- a/repo/make.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -e - -cd /repo - -# Make packages -pushd ../packages/ -make -j16 -popd - - -# Make repo index - -./mkindex.sh \ No newline at end of file From 70262d8c4b792dcaea021780865761ceee508b57 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 18:29:20 +1300 Subject: [PATCH 04/12] deploy: new repo container takes care of this --- docker-compose.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 509e677..c74a814 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,11 +16,7 @@ services: piston_fs_repo: #Temporary solution until CI works build: repo - command: > - bash -c '/repo/make.sh && - curl http://piston_api:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml"; - echo -e "\nAn error here is fine, it just means its already added it. Perhaps you restarted this container" - ' + command: ['python'] # Only build python volumes: - ./repo:/repo - ./packages:/packages \ No newline at end of file From 1a7382bb6f24cd4fd888ac6aa05ac779aba248f6 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 19:20:28 +1300 Subject: [PATCH 05/12] pkg(common): Generate test file per version --- packages/.gitignore | 3 ++- packages/common.mk | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/.gitignore b/packages/.gitignore index 2e367bf..5c3f8df 100644 --- a/packages/.gitignore +++ b/packages/.gitignore @@ -1,2 +1,3 @@ build/ -*.pkg.tar.gz \ No newline at end of file +*.pkg.tar.gz +*.tf \ No newline at end of file diff --git a/packages/common.mk b/packages/common.mk index ec069b0..d71d584 100644 --- a/packages/common.mk +++ b/packages/common.mk @@ -34,11 +34,12 @@ name: .NOTPARALLEL: build -build: ${BUILD_DIR} ${PKG_FILE} +build: ${BUILD_DIR} ${PKG_FILE} ${PKG_SLUG}.tf clean: rm -rf ${BUILD_DIR} rm -f ${PKG_FILE} + rm -f ${PKG_SLUG}.tf # mkdir ${BUILD_DIR}: @@ -61,7 +62,8 @@ $(patsubst %.json,%.jq,${INFO_FILE}): echo '.build_platform="$(or ${PLATFORM}, baremetal-$(shell grep -oP "^ID=\K\w+" /etc/os-release ))"' >> $@ $(foreach dep, ${DEPENDENCIES}, echo '.dependencies.$(word 1,$(subst =, ,${dep}))="$(word 2,$(subst =, ,${dep}))"' >> $@) - +${PKG_SLUG}.tf: + cp ${NAME}.test $@ # Helpers %/: %.tar.gz From 89d787cd63f1ebbe0ccb8b81b174b8853592fc82 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 19:30:35 +1300 Subject: [PATCH 06/12] ci(package-pr): automated testing --- .github/workflows/package-pr.yaml | 56 ++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/package-pr.yaml b/.github/workflows/package-pr.yaml index de2f025..866a1a1 100644 --- a/.github/workflows/package-pr.yaml +++ b/.github/workflows/package-pr.yaml @@ -11,8 +11,8 @@ on: - 'packages/**' jobs: - packages-affected: - name: List affected packages + check-build: + name: Check that package builds runs-on: ubuntu-latest steps: - name: Get PR Commits @@ -21,7 +21,6 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} - name: Check subsystem - if: ${{ success() || failure() }} uses: tim-actions/commit-message-checker-with-regex@v0.3.1 with: commits: ${{ steps.get-pr-commits.outputs.commits }} @@ -33,17 +32,44 @@ jobs: shell: bash run: | COMMITS='${{ steps.get-pr-commits.outputs.commits }}' - PACKAGES=$(echo $COMMITS | jq .[].commit.message -r | grep -oP '^pkg\(\K[^:\h\n]+(?=\))' | sort -u | sed 's/^/* /') - PACKAGES=${PACKAGES//$'%'/'%25'} - PACKAGES=${PACKAGES//$'\n'/'%0A'} - PACKAGES=${PACKAGES//$'\r'/'%0D'} + PACKAGES=$(echo $COMMITS | jq .[].commit.message -r | grep -oP '^pkg\(\K[^:\h\n]+(?=\))' | sort -u) echo "::set-output name=packages::$PACKAGES" - - name: 'Comment PR' - uses: actions/github-script@0.3.0 - if: github.event_name == 'pull_request' - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { issue: { number: issue_number }, repo: { owner, repo } } = context; - github.issues.createComment({ issue_number, owner, repo, body: "Affected packages:\n${{ steps.get-packages.outputs.packages }}" }); \ No newline at end of file + - name: Checkout + uses: actions/checkout@v2 + + - name: Build docker containers + run: | + docker build -t piston_fs_repo repo + docker build -t piston_api api + + - name: Build Packages + run: | + docker run -v './repo:/repo' -v './packages:/packages' piston_fs_repo ${{ steps.get-packages.outputs.packages }} + + - name: Run tests + run: | + docker run -dp 6969:6969 -v './repo:/repo' --privileged --name api piston_api + echo Waiting for API to start.. + bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:6969/runtimes)" != "200" ]]; do sleep 5; done' + echo Adding local repo + curl -s http://127.0.0.1:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml" + echo Testing packages + for pkg in "$(curl -s http://127.0.0.1:6969/repos/local/packages/ | jq '.data.packages[] | "\(.language)/\(.language_version)"' -r)" + do + PKG_SLUG=${pkg/\//-} + PKG_NAME=$(echo $pkg | cut -d'/' -f 1) + PKG_VERSION=$(echo $pkg | cut -d'/' -f 2) + echo Installing ${PKG_SLUG} + curl -sXPOST http://127.0.0.1:6969/repos/local/packages/${pkg} | jq '.language' -r || exit 1 + echo Testing ${PKG_SLUG} (using ${PKG_SLUG}.tf) + TEST_FILE=$(cat ${PKG_SLUG}.tf) + TEST_JSON=`jq -C '.language = "${PKG_NAME}" | .version = "${PKG_VERSION}" | .files=[] | .files[0]={} | .files[0].name="test" | .files[0].name.content="${TEST_FILE}" | .main = "test" | .args = [] | .stdin = "" | .compile_timeout = 10000 | .run_timeout = 3000' <<< '{}'` + curl -sXPOST http://127.0.0.1:6969/jobs -H 'Content-Type: application/json' -d "$TEST_JSON" + done + + + + + + From b410fa8525f7fd13a3becb8f25c985c3de4235f2 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 19:43:34 +1300 Subject: [PATCH 07/12] ci(package-pr): use absolute paths in docker --- .github/workflows/package-pr.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-pr.yaml b/.github/workflows/package-pr.yaml index 866a1a1..daf23e8 100644 --- a/.github/workflows/package-pr.yaml +++ b/.github/workflows/package-pr.yaml @@ -45,11 +45,11 @@ jobs: - name: Build Packages run: | - docker run -v './repo:/repo' -v './packages:/packages' piston_fs_repo ${{ steps.get-packages.outputs.packages }} + docker run -v $(pwd)'/repo:/repo' -v $(pwd)'/packages:/packages' piston_fs_repo ${{ steps.get-packages.outputs.packages }} - name: Run tests run: | - docker run -dp 6969:6969 -v './repo:/repo' --privileged --name api piston_api + docker run -dp 6969:6969 -v $(pwd)'/repo:/repo' --privileged --name api piston_api echo Waiting for API to start.. bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:6969/runtimes)" != "200" ]]; do sleep 5; done' echo Adding local repo From d295861a7dbdcf8673a280c5cec14ec78903f804 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 22:18:27 +1300 Subject: [PATCH 08/12] repo: dont error if we cannot access piston_api --- repo/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo/entrypoint.sh b/repo/entrypoint.sh index bd958ab..6f917d7 100755 --- a/repo/entrypoint.sh +++ b/repo/entrypoint.sh @@ -7,4 +7,4 @@ done cd /repo ./mkindex.sh -curl -s http://piston_api:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml" +curl -s http://piston_api:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml" || echo "WARNING: Could not add repository" From d86dc4bbb3355211d5ac18f7435c32d2973bef4a Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 22:20:23 +1300 Subject: [PATCH 09/12] ci(package-pr): check OK is included in STDOUT --- .github/workflows/package-pr.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package-pr.yaml b/.github/workflows/package-pr.yaml index daf23e8..d5c317b 100644 --- a/.github/workflows/package-pr.yaml +++ b/.github/workflows/package-pr.yaml @@ -65,7 +65,8 @@ jobs: echo Testing ${PKG_SLUG} (using ${PKG_SLUG}.tf) TEST_FILE=$(cat ${PKG_SLUG}.tf) TEST_JSON=`jq -C '.language = "${PKG_NAME}" | .version = "${PKG_VERSION}" | .files=[] | .files[0]={} | .files[0].name="test" | .files[0].name.content="${TEST_FILE}" | .main = "test" | .args = [] | .stdin = "" | .compile_timeout = 10000 | .run_timeout = 3000' <<< '{}'` - curl -sXPOST http://127.0.0.1:6969/jobs -H 'Content-Type: application/json' -d "$TEST_JSON" + curl -sXPOST http://127.0.0.1:6969/jobs -H 'Content-Type: application/json' -d "$TEST_JSON" > ${PKG_SLUG}.tr + jq '.run.stdout' ${PKG_SLUG}.tr | grep "OK" || exit 1 done From f85c430869667839962c049e664baf98f0a86c71 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 22:25:23 +1300 Subject: [PATCH 10/12] ci(package-pr): dont endlessly hang --- .github/workflows/package-pr.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-pr.yaml b/.github/workflows/package-pr.yaml index d5c317b..dc3d9fd 100644 --- a/.github/workflows/package-pr.yaml +++ b/.github/workflows/package-pr.yaml @@ -49,9 +49,9 @@ jobs: - name: Run tests run: | - docker run -dp 6969:6969 -v $(pwd)'/repo:/repo' --privileged --name api piston_api + docker run -p 6969:6969 -v $(pwd)'/repo:/repo' --privileged --name api piston_api & echo Waiting for API to start.. - bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:6969/runtimes)" != "200" ]]; do sleep 5; done' + while [[ "$(curl -s -w '%{http_code}' http://127.0.0.1:6969/runtimes)" != "200" ]]; do sleep 5; done echo Adding local repo curl -s http://127.0.0.1:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml" echo Testing packages From e82f019d0ec62a48d61eff1d31d64fbd1302d99c Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Sun, 28 Feb 2021 22:30:07 +1300 Subject: [PATCH 11/12] ci(package-pr): mount piston directory into api --- .github/workflows/package-pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package-pr.yaml b/.github/workflows/package-pr.yaml index dc3d9fd..245e81a 100644 --- a/.github/workflows/package-pr.yaml +++ b/.github/workflows/package-pr.yaml @@ -49,7 +49,7 @@ jobs: - name: Run tests run: | - docker run -p 6969:6969 -v $(pwd)'/repo:/repo' --privileged --name api piston_api & + docker run -p 6969:6969 -v $(pwd)'/data:/piston' -v $(pwd)'/repo:/repo' --privileged --name api piston_api & echo Waiting for API to start.. while [[ "$(curl -s -w '%{http_code}' http://127.0.0.1:6969/runtimes)" != "200" ]]; do sleep 5; done echo Adding local repo From a2f3058dff6ffcfbfa5c5b3bf2f257966b6646b6 Mon Sep 17 00:00:00 2001 From: ThreshMain <50732964+ThreshMain@users.noreply.github.com> Date: Mon, 1 Mar 2021 03:42:42 +0100 Subject: [PATCH 12/12] pkg(php): Added php 7.4.15 8.0.2 (#128) --- README.MD | 4 ++-- packages/php.mk | 24 ++++++++++++++++++++++++ packages/php.test | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 packages/php.mk create mode 100644 packages/php.test diff --git a/README.MD b/README.MD index 44f9298..db0b24e 100644 --- a/README.MD +++ b/README.MD @@ -204,7 +204,7 @@ Content-Type: application/json # Supported Languages -`python`, +`python`,`php`
@@ -235,4 +235,4 @@ various privilege escalation, denial-of-service, and resource saturation threats # License -Piston is licensed under the MIT license. \ No newline at end of file +Piston is licensed under the MIT license. diff --git a/packages/php.mk b/packages/php.mk new file mode 100644 index 0000000..65dbc37 --- /dev/null +++ b/packages/php.mk @@ -0,0 +1,24 @@ +NAME=php +AUTHOR=Martin Kos +DEPENDENCIES= +COMPILED=false +VERSIONS=7.4.15 8.0.2 + +include common.mk + + +${RUN_FILE}: + echo 'php $$*' > $@ + +${ENV_FILE}: + echo 'export PATH=$$PWD/bin:$$PATH' > $@ + +${BIN_DIR}: ${BUILD_DIR}php-${VERSION}-sources/ + $(eval TMP_DIR=${PWD}/${BUILD_DIR}tmpout) + cd $< && ./configure --prefix ${PREFIX} + $(MAKE) -C $< + INSTALL_ROOT=${TMP_DIR}/ $(MAKE) -C $< install + mv ${TMP_DIR}${PREFIX} ${BIN_DIR} && rm -r ${TMP_DIR} + +${BUILD_DIR}php-${VERSION}-sources.tar.gz: + curl "https://www.php.net/distributions/php-${VERSION}.tar.gz" -o $@ diff --git a/packages/php.test b/packages/php.test new file mode 100644 index 0000000..997ffba --- /dev/null +++ b/packages/php.test @@ -0,0 +1,3 @@ +