diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e81e4e5c3e23..578b22f963b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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] diff --git a/build/package/nfpm.yaml b/build/package/nfpm.yaml index 2650569fc6da..388b7d0be89f 100644 --- a/build/package/nfpm.yaml +++ b/build/package/nfpm.yaml @@ -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 diff --git a/build/tests/04-uninstall.sh b/build/tests/04-uninstall.sh new file mode 100755 index 000000000000..5bb2b270eac9 --- /dev/null +++ b/build/tests/04-uninstall.sh @@ -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" diff --git a/changelog/unreleased/kong/postremove.yml b/changelog/unreleased/kong/postremove.yml new file mode 100644 index 000000000000..c3e0a805d12e --- /dev/null +++ b/changelog/unreleased/kong/postremove.yml @@ -0,0 +1,3 @@ +message: "cleanup of rpm/deb residual files after uninstall" +type: feature +scope: Core