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

feat: add new slice definitions for 'git' and dependancies #282

Merged
merged 34 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
58dd5c4
feat: add new slice definitions for 'git' and dependancy 'libcurl3t64…
clay-lake Jul 14, 2024
ecd23aa
fix(git.yaml): essential entries in core are not sorted
clay-lake Jul 15, 2024
127747b
fix(git.yaml): duplicate essential entries in dependant slice
clay-lake Jul 15, 2024
e226db8
fix(git.yaml): removed documentation not required in slice
clay-lake Jul 15, 2024
705e014
fix(git.yaml): removed perl library slice. Unused
clay-lake Jul 15, 2024
0a79b04
Merge branch 'ubuntu-24.04' into create-git-slice
cjdcordeiro Aug 21, 2024
872b340
Merge branch 'ubuntu-24.04' into create-git-slice
clay-lake Oct 2, 2024
d75840b
fea: blank task for git tests, wip
clay-lake Oct 2, 2024
46209f5
refactor: git sdf
clay-lake Oct 2, 2024
ed83599
refactor: minimize SDF according to TDD
clay-lake Oct 21, 2024
e937318
refactor: linter warnings
clay-lake Oct 22, 2024
aefaa73
refactor: linter warnings. Missing changes
clay-lake Oct 22, 2024
6b6a925
Merge branch 'ubuntu-24.04' into create-git-slice
clay-lake Nov 7, 2024
1ca91ec
feat: sliced python3-pyftpdlib
clay-lake Nov 8, 2024
75e15ae
feat: added support for git daemon, ftp clone
clay-lake Nov 8, 2024
efa3af3
Merge branch 'ubuntu-24.04' into create-git-slice
clay-lake Nov 8, 2024
1d4aafb
fix: linting issue
clay-lake Nov 8, 2024
547aa0d
trigger build
clay-lake Nov 8, 2024
9833a85
refactor: remove busybox from tests
clay-lake Nov 15, 2024
f8420f5
feat: restore case if server exits early
clay-lake Nov 15, 2024
8538c23
fix: make all tests run in rootfs dir
clay-lake Nov 15, 2024
2e35356
fix: linting error
clay-lake Nov 15, 2024
73dc281
fix: bad path in git task
clay-lake Nov 15, 2024
0ed31a9
fix: git SDF bad content sorting
clay-lake Nov 15, 2024
9e746b2
refactor: remove unused symlinks
clay-lake Nov 15, 2024
a470e55
feat: integration test for python3-pyftpdlib
lengau Nov 15, 2024
6290be3
refactor(slices/git.yaml): remove excess content
clay-lake Nov 18, 2024
9484438
fix(tests/spread/integration/python3-pyftpdlib/task.yaml): fix path t…
clay-lake Nov 18, 2024
6dbecb3
refactor(git.yaml): removed unused library
clay-lake Nov 21, 2024
09e2324
fix(git.yaml, git/task.yaml): apply slice name suggestion
clay-lake Nov 21, 2024
972f3f4
Merge branch 'ubuntu-24.04' into create-git-slice
clay-lake Nov 25, 2024
107b89e
refactor: migrate git to use python3 slices
clay-lake Nov 25, 2024
f7cecff
refactor: changes from pair programming with Rafid
clay-lake Nov 25, 2024
792cb6f
Update slices/git.yaml with comment on git symlink
clay-lake Nov 25, 2024
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
23 changes: 13 additions & 10 deletions slices/git.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@ essential:
slices:
bins:
clay-lake marked this conversation as resolved.
Show resolved Hide resolved
clay-lake marked this conversation as resolved.
Show resolved Hide resolved
# basic functionality including:
# - init
# - config
# - add
# - commit
# - status
# - log
# - checkout
# - blame
# - branch
# - checkout
# - commit
# - config
# - diff
# - fetch
# - init
# - log
# - merge
# - rev-list
# - status
essential:
- libc6_libs
- libpcre2-8-0_libs
- zlib1g_libs
contents:
/usr/bin/git: {symlink: /usr/lib/git-core/git}
/usr/bin/git: { symlink: /usr/lib/git-core/git }
clay-lake marked this conversation as resolved.
Show resolved Hide resolved
/usr/lib/git-core/git:

daemon:
# support for git daemon
essential:
- git_bins
contents:
/usr/lib/git-core/git-daemon:
/usr/lib/git-core/git-upload-pack:
clay-lake marked this conversation as resolved.
Show resolved Hide resolved

http-clone:
clay-lake marked this conversation as resolved.
Show resolved Hide resolved
# requirements for cloning over http `git clone https://`:
# requirements for cloning over http`git clone https://`:
essential:
- git_bins
- libcurl3t64-gnutls_libs
Expand All @@ -43,7 +46,7 @@ slices:
/usr/lib/git-core/git-remote-https: # link pointing to git-remote-http

ftp-clone:
# requirements for cloning over ftp `git clone ftp://`:
# requirements for cloning over ftp`git clone ftp://`:
essential:
- git_http-clone
contents:
Expand Down
221 changes: 113 additions & 108 deletions tests/spread/integration/git/task.yaml
Original file line number Diff line number Diff line change
@@ -1,152 +1,157 @@
summary: Integration tests for git

environment:
EXTRA_SLICES: "" # No extra slices by default.
# test git_bins
RUN/bins: test_bins
SLICE/bins: git_bins
# test git_http-clone
RUN/http_clone: test_http_clone
SLICE/http_clone: git_http-clone
EXTRA_SLICES/http_clone: ca-certificates_data
# test git_ftp-clone
RUN/ftp_clone: test_ftp_clone
SLICE/ftp_clone: git_ftp-clone
# test git_daemon
RUN/daemon_clone: test_daemon_clone
SLICE/daemon_clone: git_daemon

execute: |
clay-lake marked this conversation as resolved.
Show resolved Hide resolved

function setup(){
git_rootfs="/"
function chroot_git(){
# execute git within chroot. We use -C to cd since
# we have no $SHELL to navigate with.
repo="$(realpath -e --relative-to="$git_rootfs" "$PWD")"
chroot "$git_rootfs" /usr/bin/git -C "$repo" "$@"
}

function setup(){
mkdir -p "$1/dev/"
mkdir -p "$1/etc/"

# fake essentials
touch "$1/dev/null"
head -c 500 /dev/urandom > "$1/dev/urandom"
cp /etc/resolv.conf $1/etc/
mkdir "$1/root"

# link busybox
pushd "$1/usr/bin/"
for TARGET in ash mkdir cat sleep nc
do
ln -sf busybox $TARGET
done
popd
# configure
git_rootfs="$1"
pushd "$1"

}

rootfs_bins=$(install-slices git_bins busybox_bins)
setup "$rootfs_bins"

chroot "$rootfs_bins" ash << EOF
set -ex

mkdir repo
cd repo

git init

git config user.email "[email protected]"
git config user.name "Your Name"
git config core.pager cat

echo hello_world > test_file
git add test_file
git commit -m "hello hello_world"

git status
git log

git blame -L 1,1 test_file

git checkout -b test

echo foo_bar >> test_file
git add test_file
git commit -m "hello foo_bar"

git diff master
function cleanup(){
popd
}

git branch
git checkout master
git merge test
function test_bins(){
chroot_git init
chroot_git config user.email "root@localhost"
chroot_git config user.name "Test Runner"

EOF
echo "Test" > "$1/test.txt"
chroot_git add test.txt
chroot_git commit -m 'test commit'

chroot_git --no-pager status
chroot_git --no-pager log

# Testing for http-clone
rootfs_http=$(install-slices git_http-clone busybox_bins ca-certificates_data)
setup "$rootfs_http"
chroot_git blame -L 1,1 test.txt
[[ $(chroot_git ls-files) == "test.txt" ]]

chroot "$rootfs_http" ash << EOF
set -ex
chroot_git checkout -b test

# TODO: should we replace this with locally hosted server?
git clone https://github.com/cmatsuoka/figlet.git "$rootfs_bins/figlet"
chroot_git --no-pager diff master
chroot_git branch
chroot_git checkout master
chroot_git merge test
}

EOF
function test_http_clone(){
chroot_git clone --depth 1 https://git.launchpad.net/ubuntu/+source/hello hello
cd $_

# Testing for daemon clone
rootfs_daemon=$(install-slices git_daemon busybox_bins)
setup "$rootfs_daemon"
chroot_git --no-pager log
chroot_git fetch origin
chroot_git --no-pager branch --remotes --contains $(chroot_git rev-list -n 1 HEAD)
}

chroot "$rootfs_daemon" ash << EOF
set -xe
function test_ftp_clone(){
ftp_root=$(install-slices python3-pyftpdlib_libs)
clay-lake marked this conversation as resolved.
Show resolved Hide resolved

# create a test repo
repo_name=daemon-src
repo_path=/srv/git/\$repo_name
mkdir -p \$repo_path
cd \$repo_path
mkdir -p srv/git/ftp-src
pushd $_
chroot_git init --bare
chroot_git update-server-info
popd

git init .
echo foo_bar >> test_file
git add test_file
git config user.email "[email protected]"
git config user.name "Your Name"
git commit -m "hello foo_bar"
cp -r $1/srv $ftp_root

# start the daemon in the background
cd ..
/usr/lib/git-core/git-daemon \\
--base-path=. \\
--reuseaddr \\
--listen=127.0.0.1 \\
--verbose \\
--export-all &
daemon_pid=\$!
pushd $ftp_root/srv/git
chroot $ftp_root /usr/bin/python3.12 -m pyftpdlib -V -p 2121 -d /srv/git &
pyftpdlib_pid=$!
popd

# wait for server port to become available
while ! echo -n | nc 127.0.0.1 9418
while ! fuser 2121/tcp > /dev/null 2>&1
do
if ! test -d /proc/$pyftpdlib_pid
then
echo "pyftpdlib exited early"
exit 1
fi
sleep 1
done

# clone the repo
git clone git://localhost/\$repo_name daemon-dst
# Test cloning the repo
chroot_git clone ftp://localhost:2121/ftp-src ftp-dst

# cleanup
kill \$daemon_pid

EOF

# Testing for ftp-clone
rootfs_ftp=$(install-slices git_ftp-clone busybox_bins python3-pyftpdlib_libs)
setup "$rootfs_ftp"
kill -TERM $(fuser 2121/tcp 2>/dev/null)
}

chroot "$rootfs_ftp" ash << EOF
set -xe
function test_daemon_clone(){
mkdir -p $1/srv/git/daemon-src

# create a test repo
repo_name=ftp-src
repo_path=/srv/git/\$repo_name
mkdir -p \$repo_path
cd \$repo_path
pushd $1/srv/git/daemon-src
git init
touch test-file
chroot_git add test-file
chroot_git config user.email "root@localhost"
chroot_git config user.name "Test Runner"
chroot_git commit -m "Hello daemon"
popd

git init --bare
git update-server-info
chroot_git daemon \
--base-path=/srv/git \
--reuseaddr \
--listen=127.0.0.1 \
--verbose \
--export-all &
daemon_pid=$!

cd ..
/usr/bin/python3.12 -m pyftpdlib -V &
pyftpdlib_pid=\$!

# wait for server port to become available
while ! echo -n | nc 127.0.0.1 2121
do
sleep 1
done
# Wait for daemon to start
while ! fuser 9418/tcp > /dev/null 2>&1
do
if ! test -d /proc/$daemon_pid
then
echo "daemon exited early"
exit 1
fi
sleep 1
done

# clone the repo
git clone ftp://localhost:2121/\$repo_name ftp-dst
# Test cloning the repo
chroot_git clone git://localhost/daemon-src daemon-dst

# cleanup
kill \$pyftpdlib_pid
# Cleanup. TERM or KILL cause git to return an en error.
kill -INT $(fuser 9418/tcp 2>/dev/null)
}

EOF
rootfs=$(install-slices $SLICE $EXTRA_SLICES)
setup $rootfs
$RUN $rootfs
cleanup
clay-lake marked this conversation as resolved.
Show resolved Hide resolved
64 changes: 64 additions & 0 deletions tests/spread/integration/python3-pyftpdlib/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
summary: Integration tests for python3-pyftpdlib

execute: |
function wait_for_ftp(){
sleep 0.3
while ! nc -z 127.0.0.1 2121
do
test -d /proc/$pyftpdlib_pid || (echo "pyftpdlib exited early"; exit 1)
sleep 1
done
}
function cleanup(){
while [[ -d /proc/$pyftpdlib_pid ]]; do
kill $pyftpdlib_pid || true
sleep 0.1
done
}
# Still run the cleanup even on test failure.
trap cleanup EXIT

rootfs="$(install-slices python3-pyftpdlib_libs)"
mkdir "${rootfs}/dev"
mount --bind /dev "${rootfs}/dev"
mkdir -p "${rootfs}"/srv/subdir
echo "Test file" > "${rootfs}"/srv/subdir/test-file

# Basic install smoke test

chroot "${rootfs}" python3.10 -m pyftpdlib --help

# Anonymous hosting

chroot "${rootfs}" /usr/bin/python3.10 -m pyftpdlib \
--verbose \
--interface=127.0.0.1 \
--port=2121 \
--directory=/srv &
export pyftpdlib_pid=$!
wait_for_ftp

[[ "$(curl ftp://127.0.0.1:2121/subdir/test-file)" == "Test file" ]]

cleanup

# With login and file upload.

chroot "${rootfs}" /usr/bin/python3.10 -m pyftpdlib \
--verbose \
--interface=127.0.0.1 \
--port=2121 \
--directory=/srv \
--write \
--username=testy \
--password=testy &
export pyftpdlib_pid=$!
wait_for_ftp

[[ "$(curl ftp://testy:[email protected]:2121/subdir/test-file)" == "Test file" ]]

echo "Test upload" > test-upload
curl -T test-upload ftp://testy:[email protected]:2121/test-upload
[[ "$(cat "${rootfs}/srv/test-upload")" == "$(cat test-upload)" ]]

cleanup
Loading