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(build): supports cleanup of rpm/deb residual files after uninstall #12162

Merged
merged 7 commits into from
Dec 13, 2023
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
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ jobs:
VERBOSE: ${{ runner.debug == '1' && '1' || '' }}
run: build/tests/03-http2-admin-api.sh

- name: Smoke Tests - Uninstall Tests
env:
VERBOSE: ${{ runner.debug == '1' && '1' || '' }}
BUILD_LABEL: ${{ matrix.label }}
run: build/tests/04-uninstall.sh

release-packages:
name: Release Packages - ${{ matrix.label }} - ${{ needs.metadata.outputs.release-desc }}
needs: [metadata, build-packages, build-images, smoke-tests]
Expand Down
8 changes: 6 additions & 2 deletions build/package/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ license: "Apache-2.0"
contents:
- src: nfpm-prefix/bin
dst: /usr/local/bin
- src: kong/include
dst: /usr/local/kong/include
type: tree
- src: nfpm-prefix/kong
dst: /usr/local/kong
type: tree
- src: nfpm-prefix/lib
dst: /usr/local/lib
type: tree
- src: nfpm-prefix/etc/luarocks
dst: /usr/local/etc/luarocks
- src: nfpm-prefix/openresty
dst: /usr/local/openresty
type: tree
- src: nfpm-prefix/share
dst: /usr/local/share
type: tree
- src: nfpm-prefix/etc/kong
dst: /etc/kong
- src: bin/kong
dst: /usr/local/bin/kong
- src: bin/kong-health
dst: /usr/local/bin/kong-health
- src: kong/include
dst: /usr/local/kong/include
- src: build/package/kong.service
dst: /lib/systemd/system/kong.service
- src: build/package/kong.logrotate
Expand Down
53 changes: 53 additions & 0 deletions build/tests/04-uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

if [ -n "${VERBOSE:-}" ]; then
set -x
fi

source .requirements
source build/tests/util.sh

remove_kong_command() {
local pkg_name=""
local remove_cmd=""

case "${BUILD_LABEL}" in
"ubuntu"| "debian")
remove_cmd="apt-get remove -y kong"
;;
"rhel")
remove_cmd="yum remove -y kong"
;;
*)
return 1
esac

echo "$remove_cmd"
}

msg_test '"kong" remove command'

remove_command=$(remove_kong_command)
if [ $? -eq 0 ]; then
docker_exec root "$remove_command"
else
err_exit "can not find kong package"
fi

# kong would create include and lib directory in /usr/local/kong
# but in ubuntu, kong would use /usr/local/kong as default prefix
# so after remove kong, /usr/local/kong would left logs and conf files
# we only check /usr/local/kong/include and /usr/local/kong/lib
msg_test "/usr/local/kong/include has been removed after uninstall"
assert_exec 1 'kong' "test -d /usr/local/kong/include"

msg_test "/usr/local/kong/lib has been removed after uninstall"
assert_exec 1 'kong' "test -d /usr/local/kong/lib"

# if /usr/local/share/lua/5.1 has other files, it will not be removed
# only remove files which are installed by kong
msg_test "/usr/local/share/lua/5.1 has been removed after uninstall"
assert_exec 1 'kong' "test -d /usr/local/share/lua/5.1"

msg_test "/usr/local/openresty has been removed after uninstall"
assert_exec 1 'kong' "test -d /usr/local/openresty"
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/postremove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "cleanup of rpm/deb residual files after uninstall"
type: feature
scope: Core
Loading