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

Implements sandbox package #1

Open
wants to merge 1 commit into
base: main
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
16 changes: 16 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
":semanticCommitTypeAll(chore)"
],
"lockFileMaintenance": {
"enabled": true,
"extends": [
"schedule:weekly"
]
},
"nix": {
"enabled": true
}
}
33 changes: 33 additions & 0 deletions .github/workflows/vorpal-sandbox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: vorpal-sandbox

on:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
runner:
- macos-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v4

- if: matrix.runner != 'macos-latest'
run: ./script/debian.sh "sandbox"

- run: make dist

- run: |
echo "ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "OS=$(uname -s | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "SANDBOX_HASH=$(cat "${PWD}/script/sandbox.sha256sum")" >> $GITHUB_ENV

- uses: actions/upload-artifact@v4
with:
name: vorpal-sandbox-${{ env.ARCH }}-${{ env.OS }}
path: dist/vorpal-sandbox-${{ env.SANDBOX_HASH }}.package.tar.zst
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
.vagrant
dist
42 changes: 42 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Vagrant.configure("2") do |config|
config.ssh.password = "vagrant"

config.vm.box = "altf4llc/debian-bookworm"

# Speed is important here as a lot of compiling is done in the vm
# Be sure to set a high enough value for your system
config.vm.provider :vmware_desktop do |vmware|
vmware.vmx["memsize"] = "8192"
vmware.vmx["numvcpus"] = "8"
end

config.vm.provision "shell", keep_color: true, privileged: false, inline: <<-SHELL
echo 'function sync_sandbox {
pushd "${HOME}"

mkdir -p ./vorpal-sandbox

rsync -aPW \
--exclude=".env" \
--exclude=".git" \
--exclude=".vagrant" \
--exclude="dist" \
--exclude="packer_debian_vmware_arm64.box" \
/vagrant/. ./vorpal-sandbox/.

popd
}' >> ~/.bashrc

echo 'function build_sandbox {
sync_sandbox

pushd "${HOME}/vorpal-sandbox"

./script/debian.sh

make dist

popd
}' >> ~/.bashrc
SHELL
end
26 changes: 26 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PACKAGE_HASH := $(shell cat "${PWD}/script/sandbox.sha256sum")
PACKAGE_NAME := vorpal-sandbox-$(PACKAGE_HASH).package
PACKAGE_PATH := /var/lib/vorpal/store/$(PACKAGE_NAME)

build: clean
"${PWD}/script/sandbox.sh"

clean:
rm -rf $(PACKAGE_PATH)
rm -rf $(PACKAGE_PATH).tar.zst
rm -rf "${PWD}/dist"

dist: build
mkdir -p "${PWD}/dist"
tar -cvf - -C "$(PACKAGE_PATH)" "${PWD}" | zstd -o "$(PACKAGE_PATH).tar.zst"
cp $(PACKAGE_PATH).tar.zst "${PWD}/dist/."

list:
@grep '^[^#[:space:]].*:' Makefile

test-vagrant:
vagrant destroy --force || true
vagrant up --provider "vmware_desktop"

update-sha256sum:
"${PWD}/script/hash_path.sh" "${PWD}" > "${PWD}/script/sandbox.sha256sum"
45 changes: 45 additions & 0 deletions script/common/bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail

ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
CPU_COUNT=""
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
VERSION="5.2"

if [ -z "$1" ]; then
echo "Usage: $0 <sandbox-package-path>"
exit 1
fi

if [[ -f "${1}/bin/bash" ]]; then
"${1}/bin/bash" --version | head -n 1
exit 0
fi

if [[ "${ARCH}" == "arm64" ]]; then
ARCH="aarch64"
fi

if [[ "${OS}" == "linux" ]]; then
CPU_COUNT="-j$(nproc)"
fi

curl -L \
"https://ftp.gnu.org/gnu/bash/bash-${VERSION}.tar.gz" \
-o "/tmp/bash-${VERSION}.tar.gz"

tar -xvzf "/tmp/bash-${VERSION}.tar.gz" -C "/tmp"

pushd "/tmp/bash-${VERSION}"

./configure --prefix="${1}"

make ${CPU_COUNT}

make install

popd

rm -rf "/tmp/bash-${VERSION}"

rm -rf "/tmp/bash-${VERSION}.tar.gz"
45 changes: 45 additions & 0 deletions script/common/coreutils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail

ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
CPU_COUNT=""
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
VERSION="9.5"

if [ -z "$1" ]; then
echo "Usage: $0 <sandbox-package-path>"
exit 1
fi

if [[ -f "${1}/bin/cat" ]]; then
"${1}/bin/cat" --version | head -n 1
exit 0
fi

if [[ "${ARCH}" == "arm64" ]]; then
ARCH="aarch64"
fi

if [[ "${OS}" == "linux" ]]; then
CPU_COUNT="-j$(nproc)"
fi

curl -L \
"https://ftp.gnu.org/gnu/coreutils/coreutils-${VERSION}.tar.gz" \
-o "/tmp/coreutils-${VERSION}.tar.gz"

tar -xzf "/tmp/coreutils-${VERSION}.tar.gz" -C "/tmp"

pushd "/tmp/coreutils-${VERSION}"

./configure --prefix="${1}"

make ${CPU_COUNT}

make install

popd

rm -rf "/tmp/coreutils-${VERSION}"

rm -rf "/tmp/coreutils-${VERSION}.tar.gz"
43 changes: 43 additions & 0 deletions script/common/zstd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail

ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
CPU_COUNT=""
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
VERSION="1.5.5"

if [ -z "$1" ]; then
echo "Usage: $0 <sandbox-package-path>"
exit 1
fi

if [[ -f "${1}/bin/zstd" ]]; then
"${1}/bin/zstd" --version
exit 0
fi

if [[ "${ARCH}" == "arm64" ]]; then
ARCH="aarch64"
fi

if [[ "${OS}" == "linux" ]]; then
CPU_COUNT="-j$(nproc)"
fi

curl -L \
"https://github.com/facebook/zstd/releases/download/v${VERSION}/zstd-${VERSION}.tar.gz" \
-o "/tmp/zstd-${VERSION}.tar.gz"

tar -xzf "/tmp/zstd-${VERSION}.tar.gz" -C "/tmp"

pushd "/tmp/zstd-${VERSION}"

make ${CPU_COUNT}

make install PREFIX="${1}"

popd

rm -rf "/tmp/zstd-${VERSION}"

rm -rf "/tmp/zstd-${VERSION}.tar.gz"
1 change: 1 addition & 0 deletions script/darwin/bash.sh
1 change: 1 addition & 0 deletions script/darwin/coreutils.sh
1 change: 1 addition & 0 deletions script/darwin/zstd.sh
20 changes: 20 additions & 0 deletions script/debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

sudo apt-get update

sudo apt-get install \
--no-install-recommends \
--yes \
autoconf \
automake \
bison \
build-essential \
coreutils \
flex \
gawk \
gperf \
m4 \
perl \
texinfo \
zstd
56 changes: 56 additions & 0 deletions script/hash_path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -euo pipefail

export LC_ALL=C

if [ -z "$1" ]; then
echo "Usage: $0 <path>"
exit 1
fi

SYSTEM_PATH="$(realpath "${1}")"

if [[ ! -e "$SYSTEM_PATH" ]]; then
echo "The file or directory does not exist."
exit 1
fi

files=$(find "$SYSTEM_PATH" -type f | sort -n)
hashes=""
ignore_paths=(
"${SYSTEM_PATH}/.git"
"${SYSTEM_PATH}/script/sandbox.sha256sum"
)

is_ignored() {
local file_path="$1"

for ignore in "${ignore_paths[@]}"; do
if [[ "$file_path" == *"$ignore"* ]]; then
return 0
fi
done

if [ -f "$SYSTEM_PATH/.gitignore" ]; then
while IFS= read -r pattern; do
[[ -z "$pattern" || "$pattern" == \#* ]] && continue

regex=$(echo "$pattern" | sed 's/\./\\./g; s/\*/.*/g; s/\?/./g')

if [[ "$file_path" =~ $regex ]]; then
return 0
fi
done < "$SYSTEM_PATH/.gitignore"
fi

return 1
}

while IFS= read -r file; do
if ! is_ignored "$file"; then
hash=$(shasum -a 256 "$file" | awk '{print $1}')
hashes="${hashes}${hash}"
fi
done <<< "$files"

echo -n "$hashes" | shasum -a 256 | awk '{print $1}'
1 change: 1 addition & 0 deletions script/linux/bash.sh
44 changes: 44 additions & 0 deletions script/linux/binutils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euxo pipefail

ARCH="$(uname -m | tr '[:upper:]' '[:lower:]')"
CPU_COUNT=""
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
VERSION="2.43.1"

if [ -z "$1" ]; then
echo "Usage: $0 <sandbox-package-path>"
exit 1
fi

if [[ "${ARCH}" == "arm64" ]]; then
ARCH="aarch64"
fi

if [[ "${OS}" == "linux" ]]; then
CPU_COUNT="-j$(nproc)"
fi

curl -L \
"https://ftp.gnu.org/gnu/binutils/binutils-${VERSION}.tar.gz" \
-o "/tmp/binutils-${VERSION}.tar.gz"

tar -xvzf "/tmp/binutils-${VERSION}.tar.gz" -C "/tmp"

pushd "/tmp/binutils-${VERSION}"

mkdir -p ./build

popd

pushd "/tmp/binutils-${VERSION}/build"

../configure --prefix="${1}"
make ${CPU_COUNT}
make install

popd

rm -rf "/tmp/binutils-${VERSION}"

rm -rf "/tmp/binutils-${VERSION}.tar.gz"
1 change: 1 addition & 0 deletions script/linux/coreutils.sh
Loading