Skip to content

Commit

Permalink
github: switch to use lxc
Browse files Browse the repository at this point in the history
vagrant on macos is fragile recently, try to use lxc.

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Dec 8, 2023
1 parent b793ab1 commit c730917
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 81 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,36 @@ jobs:
test:
name: Test
needs: build
runs-on: macos-latest
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
distribution:
- debian-bullseye
- debian-bookworm
- ubuntu-focal
- ubuntu-jammy
label:
- Debian GNU/Linux bullseye amd64
- Debian GNU/Linux bookworm amd64
- Ubuntu Focal amd64
- Ubuntu Jammy amd64
include:
- label: Debian GNU/Linux bullseye amd64
rake-job: debian-bullseye
test-lxc-image: images:debian/11
- label: Debian GNU/Linux bookworm amd64
rake-job: debian-bookworm
test-lxc-image: images:debian/12
- label: Ubuntu Focal amd64
rake-job: ubuntu-focal
test-lxc-image: ubuntu:20.04
- label: Ubuntu Jammy amd64
rake-job: ubuntu-jammy
test-lxc-image: ubuntu:22.04
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
with:
name: packages-${{ matrix.distribution }}
name: packages-${{ matrix.rake-job }}
- uses: actions/download-artifact@master
with:
name: packages-apt-source-${{ matrix.distribution }}
- name: Run Test
run: fluent-package/apt/systemd-test/test.sh ${{ matrix.distribution }}
name: packages-apt-source-${{ matrix.rake-job }}
- uses: canonical/setup-lxd@v0.1.1
- name: Run Test
run: fluent-package/apt/systemd-test/test.sh ${{ matrix.test-lxc-image }}
28 changes: 19 additions & 9 deletions .github/workflows/yum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,30 @@ jobs:
test:
name: Test
needs: build
runs-on: macos-latest
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
distribution:
- centos-7
- rockylinux-8
- almalinux-9
- amazonlinux-2
# - amazonlinux-2023
label:
# CGroup V1 is not supported
# - CentOS 7 x86_64
- RockyLinux 8 x86_64
- AlmaLinux 9 x86_64
include:
# - label: CentOS 7 x86_64
# rake-job: centos-7
# test-lxc-image: images:centos/7
- label: RockyLinux 8 x86_64
rake-job: rockylinux-8
test-lxc-image: images:rockylinux/8
- label: AlmaLinux 9 x86_64
rake-job: almalinux-9
test-lxc-image: images:almalinux/9
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
with:
name: packages-${{ matrix.distribution }}
name: packages-${{ matrix.rake-job }}
- uses: canonical/setup-lxd@v0.1.1
- name: Run Test
run: fluent-package/yum/systemd-test/test.sh ${{ matrix.distribution }}
run: fluent-package/yum/systemd-test/test.sh ${{ matrix.test-lxc-image }}
2 changes: 1 addition & 1 deletion fluent-package/apt/systemd-test/install-newly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -exu
case $1 in
local)
sudo apt install -V -y \
/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
;;
v5)
curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5.sh | sh
Expand Down
49 changes: 22 additions & 27 deletions fluent-package/apt/systemd-test/test.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/bin/bash

if [ -z $1 ]; then
echo "Error: Need to specify VM name in the Vagrantfile."
echo "Ex.) $ ./test.sh ubuntu-focal"
echo "Error: Need to specify lxc image name."
echo "Ex.) $ ./test.sh ubuntu:20.04"
exit 1
fi

vm=$1
dir="/vagrant/fluent-package/apt/systemd-test"
image=$1
dir="/host/fluent-package/apt/systemd-test"

vagrant status $vm | grep -E "^${vm}\s+not created (.*)$"
if [ $? -ne 0 ]; then
echo "Error: The VM already exists. Need to destroy it in advance with the following command."
echo "$ vagrant destroy $vm"
exit 1
fi

set -eu
set -eux

test_filenames=(
update-to-next-version.sh
)

if [ ! $vm = "debian-bookworm" ]; then
if [ ! $image = "images:debian/12" ]; then
# As no bookworm package for v4, so execute upgrade test for other code name.
test_filenames+=(
update-from-v4.sh
Expand All @@ -32,24 +25,26 @@ fi

for apt_repo_type in local v5 lts; do
echo -e "\nRun test: $apt_repo_type\n"
vagrant up $vm
vagrant ssh $vm -- $dir/setup.sh
vagrant ssh $vm -- $dir/install-newly.sh $apt_repo_type
vagrant destroy -f $vm
lxc launch $image target
sleep 5
lxc config device add target host disk source=$PWD path=/host
lxc list
lxc exec target -- $dir/setup.sh
lxc exec target -- $dir/install-newly.sh $apt_repo_type
lxc stop target
lxc delete target
done

for test_filename in ${test_filenames[@]}; do
echo -e "\nRun test: $test_filename\n"
vagrant up $vm
vagrant ssh $vm -- $dir/setup.sh
vagrant ssh $vm -- $dir/$test_filename
vagrant destroy -f $vm
# I want to use snapshot instead of destorying it for every test,
# but somehow, it will be often an error on GitHub Actions...
# $ vagrant ssh $vm -- $dir/setup.sh
# $ vagrant snapshot save -f $vm after-setup
# (execute a test)
# $ vagrant snapshot restore $vm after-setup
lxc launch $image target
sleep 5
lxc config device add target host disk source=$PWD path=/host
lxc list
lxc exec target -- $dir/setup.sh
lxc exec target -- $dir/$test_filename
lxc stop target
lxc delete target
done

echo -e "\nAll Success!\n"
4 changes: 2 additions & 2 deletions fluent-package/apt/systemd-test/update-from-v4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sudo apt install -y ./fluentd-apt-source_2020.8.25-1_all.deb
# Install v4
sudo apt clean all
# Uncomment when v5 repository was deployed
#apt_source_package=/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-apt-source*_all.deb
#apt_source_package=/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-apt-source*_all.deb
#sudo apt install -V -y ${apt_source_package} ca-certificates
sudo apt update
sudo apt install -V -y td-agent=${td_agent_version}-1
Expand All @@ -21,7 +21,7 @@ systemctl status --no-pager td-agent

# Install the current
sudo apt install -V -y \
/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb

# Test: service status
systemctl status --no-pager fluentd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sudo apt install -y ./fluentd-apt-source_2020.8.25-1_all.deb
# Install v4
sudo apt clean all
# Uncomment when v5 repository was deployed
#apt_source_package=/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-apt-source*_all.deb
#apt_source_package=/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-apt-source*_all.deb
#sudo apt install -V -y ${apt_source_package} ca-certificates
sudo apt update
sudo apt install -V -y td-agent=${td_agent_version}-1
Expand All @@ -21,7 +21,7 @@ systemctl status --no-pager td-agent

# Install the current
sudo apt install -V -y \
/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
systemctl status --no-pager fluentd

sudo systemctl stop fluentd
Expand All @@ -32,7 +32,7 @@ systemctl status --no-pager fluentd
systemctl status --no-pager td-agent

# Make a dummy pacakge for the next version
dpkg-deb -R /vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp
dpkg-deb -R /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp
last_ver=$(cat tmp/DEBIAN/control | grep "Version: " | sed -E "s/Version: ([0-9.]+)-([0-9]+)/\2/g")
sed -i -E "s/Version: ([0-9.]+)-([0-9]+)/Version: \1-$(($last_ver+1))/g" tmp/DEBIAN/control
dpkg-deb --build tmp next_version.deb
Expand Down
4 changes: 2 additions & 2 deletions fluent-package/apt/systemd-test/update-to-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set -exu

# Install the current
sudo apt install -V -y \
/vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb

# Make a dummy pacakge for the next version
dpkg-deb -R /vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp
dpkg-deb -R /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp
last_ver=$(cat tmp/DEBIAN/control | grep "Version: " | sed -E "s/Version: ([0-9.]+)-([0-9]+)/\2/g")
sed -i -E "s/Version: ([0-9.]+)-([0-9]+)/Version: \1-$(($last_ver+1))/g" tmp/DEBIAN/control
dpkg-deb --build tmp next_version.deb
Expand Down
2 changes: 1 addition & 1 deletion fluent-package/yum/systemd-test/install-newly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -exu
case $1 in
local)
sudo $DNF install -y \
/vagrant/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
;;
v5)
case $DISTRIBUTION in
Expand Down
42 changes: 19 additions & 23 deletions fluent-package/yum/systemd-test/test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#!/bin/bash

if [ -z $1 ]; then
echo "Error: Need to specify VM name in the Vagrantfile."
echo "Ex.) $ ./test.sh almalinux-9"
echo "Error: Need to specify distribution name."
echo "Ex.) $ ./test.sh centos-7"
exit 1
fi

vm=$1
dir="/vagrant/fluent-package/yum/systemd-test"
image=$1
dir="/host/fluent-package/yum/systemd-test"

vagrant status $vm | grep -E "^${vm}\s+not created (.*)$"
if [ $? -ne 0 ]; then
echo "Error: The VM already exists. Need to destroy it in advance with the following command."
echo "$ vagrant destroy $vm"
exit 1
fi

set -eu
set -eux

test_filenames=(
update-from-v4.sh
Expand All @@ -26,21 +19,24 @@ test_filenames=(

for yum_repo_type in local v5 lts; do
echo -e "\nRun test: $yum_repo_type\n"
vagrant up $vm
vagrant ssh $vm -- $dir/install-newly.sh $yum_repo_type
vagrant destroy -f $vm
lxc launch $image target
sleep 5
lxc config device add target host disk source=$PWD path=/host
lxc list
lxc exec target -- $dir/install-newly.sh $yum_repo_type
lxc stop target
lxc delete target
done

for test_filename in ${test_filenames[@]}; do
echo -e "\nRun test: $test_filename\n"
vagrant up $vm
vagrant ssh $vm -- $dir/$test_filename
vagrant destroy -f $vm
# I want to use snapshot instead of destroying it for every test,
# but somehow, it will be often an error on GitHub Actions...
# $ vagrant snapshot save -f $vm after-setup
# (execute a test)
# $ vagrant snapshot restore $vm after-setup
lxc launch $image target
sleep 5
lxc config device add target host disk source=$PWD path=/host
lxc list
lxc exec target -- $dir/$test_filename
lxc stop target
lxc delete target
done

echo -e "\nAll Success!\n"
2 changes: 1 addition & 1 deletion fluent-package/yum/systemd-test/update-from-v4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ systemctl status --no-pager td-agent

# Install the current
sudo $DNF install -y \
/vagrant/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm

# Test: service status
systemctl status --no-pager fluentd # Migration process starts the service automatically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sudo systemctl enable --now td-agent
systemctl status --no-pager td-agent

# Install the current
package="/vagrant/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm"
package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm"
sudo $DNF install -y $package
systemctl status --no-pager fluentd # Migration process starts the service automatically
sudo systemctl enable --now fluentd
Expand Down
2 changes: 1 addition & 1 deletion fluent-package/yum/systemd-test/update-to-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -exu
. $(dirname $0)/commonvar.sh

# Install the current
package="/vagrant/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm"
package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm"
sudo $DNF install -y $package
sudo systemctl enable --now fluentd
systemctl status --no-pager fluentd
Expand Down

0 comments on commit c730917

Please sign in to comment.