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

split a testing_using_container script out of backend-for-testing.md #884

Merged
merged 5 commits into from
Jan 16, 2024
Merged
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
53 changes: 4 additions & 49 deletions rust/agama-cli/doc/backend-for-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,8 @@ of [.github/workflows/ci.yml][ci.yml].

[ci.yml]: https://github.com/openSUSE/agama/blob/25462f57ab695d6910beb59ff0b21a7afaeda47e/.github/workflows/ci.yml

## Resulting Script

```sh
# https://build.opensuse.org/package/show/systemsmanagement:Agama:Staging/agama-testing
CIMAGE=registry.opensuse.org/systemsmanagement/agama/staging/containers/opensuse/agama-testing:latest
# rename this if you test multiple things
CNAME=agama
# the '?' here will report a shell error
# if you accidentally paste a command without setting the variable first
echo ${CNAME?}

test -f service/agama.gemspec || echo "You should run this from a checkout of agama"

# destroy the previous instance
podman stop ${CNAME?}
podman rm ${CNAME?}

mkdir -p ./mnt/log-yast2 # needed?
mkdir -p ./mnt/run-agama # only needed for D-Bus access from outside, unused now

# Update our image
podman pull ${CIMAGE?}

podman run --name ${CNAME?} \
--privileged --detach --ipc=host \
-v .:/checkout -v ./mnt/run-agama:/run/agama -v ./mnt/log-yast2:/var/log/YaST2 \
${CIMAGE?}

# shortcut for the following
CEXEC="podman exec ${CNAME?} bash -c"

${CEXEC?} "cd /checkout && ./setup-services.sh"

# Optional: explicit service start using a separate log file
${CEXEC?} "cd /checkout/service && (bundle exec bin/agamactl > service.log 2>&1 &)"

# Now the CLI is in the same repo, just symlink it
${CEXEC?} "ln -sfv /checkout/./rust/target/debug/agama /usr/bin/agama"

# Optional: Play!
${CEXEC?} "agama -f yaml config show"

# Optional: show logs of autostarted services
${CEXEC?} "journalctl --since=-5min"

# Optional: show logs of explicitly started services
${CEXEC?} "cat /checkout/service/service.log"

# Optional: Interactive shell in the container
podman exec --tty --interactive ${CNAME?} bash
```
The script, which used to be inlined here, is now at
[`/testing_using_container.sh`](../../../testing_using_container.sh).
>>>>>>> 8f2f0404 (copied the script part of rust/agama-cli/doc/backend-for-testing.md)
9 changes: 9 additions & 0 deletions setup-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ fi
# Rubygem dependencies
(
cd $MYDIR/service

if [ -d /checkout-ruby-dbus ]; then
# we are in a container, told to use that one
# instead of a released version
# edit +Gemfile and -gemspec
sed -e '/ruby-dbus/d' -i Gemfile agama.gemspec
sed -e '/gemspec/a gem "ruby-dbus", path: "/checkout-ruby-dbus"' -i Gemfile
fi

bundle config set --local path 'vendor/bundle'
bundle install
)
Expand Down
56 changes: 56 additions & 0 deletions testing_using_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# Run checked-out Agama in a podman container.
# This is meant to be run from a working copy of the git repo.
# It uses the systemsmanagement:Agama:Staging/agama-testing image as
# a platform and runs /setup.sh
#
# Details:
# - container name: agama
# - port 9090 is exposed so that web UI works
# - 'WITH_RUBY_DBUS=1 $0' will prefer ../ruby-dbus to any ruby-dbus.gem

set -x
set -eu

# https://build.opensuse.org/package/show/systemsmanagement:Agama:Staging/agama-testing
CIMAGE=registry.opensuse.org/systemsmanagement/agama/staging/containers/opensuse/agama-testing:latest
# rename this if you test multiple things
CNAME=agama

test -f service/agama.gemspec || { echo "You should run this from a checkout of agama"; exit 1; }

# destroy the previous instance, can fail if there is no previous instance
podman stop ${CNAME?} || : no problem if there was nothing to stop
podman rm ${CNAME?} || : no problem if there was nothing to remove

# Update our image
podman pull ${CIMAGE?}

# Optionally use a git version of ruby-dbus
# because Agama pushes its limits so it's better
# to set up for easy testing
MORE_VOLUMES=()
if [ "${WITH_RUBY_DBUS-}" = 1 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe document that env variable at the top of script together with some documentation what script does?

MORE_VOLUMES=(-v ../ruby-dbus:/checkout-ruby-dbus)
fi

podman run --name ${CNAME?} \
--privileged --detach --ipc=host \
-v .:/checkout \
${MORE_VOLUMES[@]} \
-p 9090:9090 \
${CIMAGE?}

# shortcut for the following
CEXEC="podman exec ${CNAME?} bash -c"

${CEXEC?} "cd /checkout && ./setup.sh"

# Now the CLI is in the same repo, just symlink it
${CEXEC?} "ln -sfv /checkout/./rust/target/debug/agama /usr/bin/agama"

# Manually start cockpit as socket activation does not work with port forwarding
${CEXEC?} "systemctl start cockpit"

# Interactive shell in the container
podman exec --tty --interactive ${CNAME?} bash