diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a459723..e418dd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,6 @@ jobs: wget https://github.com/newrelic/nri-apache/releases/download/v0.0.1/nri-apache_0.0.1-1_amd64.deb -O ./dist/nri-apache_0.0.1-1_amd64.deb - uses: ./ with: - TAG: '0.0.1' - INTEGRATION: 'nri-apache' - TEST_EXISTENCE: '/var/db/newrelic-infra/newrelic-integrations/bin/nri-apache /etc/newrelic-infra/integrations.d/apache-config.yml.sample /var/db/newrelic-infra/newrelic-integrations/apache-definition.yml' \ No newline at end of file + tag: '0.0.1' + integration: 'nri-apache' + upgrade: false diff --git a/README.md b/README.md index 9aac7ff..b3e6a69 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,29 @@ # test-packages-action -Usage: +An action to test for correct installation and upgrades of New Relic integration packages. + +It tests clean installation and upgrade for integration packages in CentOS, Suse and Ubuntu. + +Usage and defaults: ```yaml - name: Test packages installation uses: paologallinaharbur/test-packages-action@v1.0.5 with: - TAG: '0.0.1' - INTEGRATION: 'nri-apache' - TEST_EXISTENCE: 'file1 file2 file3' -``` \ No newline at end of file + tag: '0.0.1' # required + integration: 'nri-apache' # required +``` + +## Extra parameters + +The following inputs can be specified to override the default behavior + +* `upgrade`: Whether to test upgrade path against the version of the same integration in the newrelic repo + - default: `true` + `postInstallExtra`: Extra checks to run in addition to the default post-install script. This is specified as a multi-line shell script, which is run line-by-line in different containers. A non-zero exit code for any line causes the installation check to fail. + - default: empty +* `postInstall`: Override the post-install test script. This is run line-by-line in different containers. A non-zero exit code causes the install check to fail. + - default: See `entrypoint.sh` +* `distros`: Space-separated list of distros to run the test on. Supported values are "ubuntu", "suse" and "centos" + - default: `centos suse ubuntu` +* `pkgDir`: Path where archives (.deb and .rpm) reside + - default: `./dist` diff --git a/action.yml b/action.yml index b191898..8c8b29a 100644 --- a/action.yml +++ b/action.yml @@ -1,24 +1,45 @@ name: 'Test packages installation' -description: 'This action test packages installation in Suse Centos Debian' +description: 'This action test packages installation in Suse, CentOS and Ubuntu' inputs: - TAG: + tag: description: 'Tag of the integration to test' required: true default: '0.0.0' - INTEGRATION: - description: 'Integration to test' + integration: + description: 'Name of the integration to test' required: true default: 'nri-test' - TEST_EXISTENCE: - description: 'file to test es "/var /bin/nri-test"' + upgrade: + description: 'Wether to test upgrade path as well' required: false - default: '' + default: "true" + postInstall: + description: 'Script to run after installation is completed. Default will test for existence of the integration binary and -show_version output' + required: false + default: "" + postInstallExtra: + description: 'Extra check lines to append to the default postInstall script.' + required: false + default: "" + distros: + description: 'Space-separated list of distros to run the test on. Supported values are "ubuntu", "suse" and "centos"' + required: false + default: "" + pkgDir: + description: 'Folder containing installer packages' + required: false + default: "" + runs: using: "composite" steps: - run: $GITHUB_ACTION_PATH/entrypoint.sh shell: bash env: - TAG: ${{ inputs.TAG }} - INTEGRATION: ${{ inputs.INTEGRATION }} - TEST_EXISTENCE: ${{ inputs.TEST_EXISTENCE }} + TAG: ${{ inputs.tag }} + INTEGRATION: ${{ inputs.integration }} + UPGRADE: ${{ inputs.upgrade }} + POST_INSTALL: ${{ inputs.postInstall }} + POST_INSTALL_EXTRA: ${{ inputs.postInstallExtra }} + DISTROS: ${{ inputs.distros }} + PKGDIR: ${{ inputs.pkgDir }} diff --git a/dockerfiles-base/Dockerfile-base-centos b/dockerfiles-base/Dockerfile-base-centos index b0e6f95..fc2b157 100644 --- a/dockerfiles-base/Dockerfile-base-centos +++ b/dockerfiles-base/Dockerfile-base-centos @@ -1,13 +1,11 @@ -FROM centos:centos8 as centos-test +FROM centos:centos8 # Installing needed tools -RUN yum update -y -RUN yum install -y wget +RUN yum update -y && \ + yum install -y wget # Adding Newrelic repository -RUN wget -O /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/8/x86_64/newrelic-infra.repo -RUN yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra' -RUN yum update -y - -# Installing Agent -RUN yum -y install newrelic-infra \ No newline at end of file +RUN wget -O /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/8/x86_64/newrelic-infra.repo && \ + yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra' && \ + yum update -y && \ + yum -y install newrelic-infra diff --git a/dockerfiles-base/Dockerfile-base-debian b/dockerfiles-base/Dockerfile-base-debian deleted file mode 100644 index eafb5b3..0000000 --- a/dockerfiles-base/Dockerfile-base-debian +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:bionic as debian-test - -# Installing needed tools -RUN apt update -RUN apt -y install wget gnupg - -# Installing Agent -RUN wget https://download.newrelic.com/infrastructure_agent/linux/apt/pool/main/n/newrelic-infra/newrelic-infra_upstart_1.14.2_upstart_amd64.deb -RUN apt install ./newrelic-infra_upstart_1.14.2_upstart_amd64.deb - -# Adding Newrelic repository -RUN wget https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg -O - | apt-key add - -RUN echo "deb [arch=amd64] https://download.newrelic.com/infrastructure_agent/linux/apt focal main" > /etc/apt/sources.list.d/newrelic-infra.list -RUN apt update diff --git a/dockerfiles-base/Dockerfile-base-suse b/dockerfiles-base/Dockerfile-base-suse index aa8b66c..285e364 100644 --- a/dockerfiles-base/Dockerfile-base-suse +++ b/dockerfiles-base/Dockerfile-base-suse @@ -1,13 +1,11 @@ -FROM opensuse/tumbleweed as suste-test +FROM opensuse/tumbleweed # Installing needed tools RUN zypper -n install wget gnupg curl # Adding Newrelic repository -RUN curl https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg -s | gpg --import -RUN curl -o /etc/zypp/repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/zypp/sles/12.4/x86_64/newrelic-infra.repo -RUN zypper --gpg-auto-import-keys ref -RUN zypper -n ref -r newrelic-infra - -# Installing Agent -RUN zypper -n install newrelic-infra \ No newline at end of file +RUN curl https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg -s | gpg --import && \ + curl -o /etc/zypp/repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/zypp/sles/12.4/x86_64/newrelic-infra.repo && \ + zypper --gpg-auto-import-keys ref && \ + zypper -n ref -r newrelic-infra && \ + zypper -n install newrelic-infra diff --git a/dockerfiles-base/Dockerfile-base-ubuntu b/dockerfiles-base/Dockerfile-base-ubuntu new file mode 100644 index 0000000..39e5267 --- /dev/null +++ b/dockerfiles-base/Dockerfile-base-ubuntu @@ -0,0 +1,19 @@ +FROM ubuntu:focal + +# Installing needed tools +RUN apt update && \ + apt -y install wget gnupg + +ARG AGENT_PACKAGE=newrelic-infra_upstart_1.14.2_upstart_amd64.deb +# Installing Agent +RUN wget https://download.newrelic.com/infrastructure_agent/linux/apt/pool/main/n/newrelic-infra/${AGENT_PACKAGE} && \ + apt install ./${AGENT_PACKAGE} + +# Adding Newrelic repository +RUN wget https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg -O - | apt-key add - && \ + echo "deb [arch=amd64] https://download.newrelic.com/infrastructure_agent/linux/apt focal main" > /etc/apt/sources.list.d/newrelic-infra.list && \ + apt update + +# By default, dockerized ubuntu drops files in /usr/share/doc when installing. We do not want this, as we want +# to be able to test for their existence +RUN rm /etc/dpkg/dpkg.cfg.d/excludes || true diff --git a/dockerfiles-test/Dockerfile-centos b/dockerfiles-test/Dockerfile-centos index be31579..9e195dd 100644 --- a/dockerfiles-test/Dockerfile-centos +++ b/dockerfiles-test/Dockerfile-centos @@ -1,15 +1,11 @@ -FROM pgallina/centos-test as centos-test +FROM centos-base -ARG INTEGRATION=nri-apache -ARG TAG=0.0.1 -ARG TEST_EXISTENCE="" -ARG TEST_UPDATE=false +ARG INTEGRATION +ARG TAG +ARG PKGDIR +ARG UPGRADE=false -ADD ./dist ./dist +ADD ${PKGDIR} ./dist -RUN echo "centos-test-test for ${INTEGRATION} ${TAG}" -RUN if [[ "${TEST_UPDATE}" = true ]] ; then yum -y install ${INTEGRATION} ; fi -RUN yum -y install ./dist/${INTEGRATION}-${TAG}-1.x86_64.rpm - -RUN ls $TEST_EXISTENCE -RUN /var/db/newrelic-infra/newrelic-integrations/bin/${INTEGRATION} -show_version | grep ${TAG} +RUN if [ "${UPGRADE}" = "true" ]; then yum -y install ${INTEGRATION}; fi; \ + yum -y install ./dist/${INTEGRATION}-${TAG}-1.x86_64.rpm diff --git a/dockerfiles-test/Dockerfile-debian b/dockerfiles-test/Dockerfile-debian deleted file mode 100644 index 58eae71..0000000 --- a/dockerfiles-test/Dockerfile-debian +++ /dev/null @@ -1,15 +0,0 @@ -FROM pgallina/debian-test as debian-test - -ARG INTEGRATION=nri-apache -ARG TAG=0.0.1 -ARG TEST_EXISTENCE="" -ARG TEST_UPDATE=false - -ADD ./dist ./dist - -RUN echo "debian-test for ${INTEGRATION} ${TAG}" -RUN if [[ "${TEST_UPDATE}" = true ]] ; then apt install -y ${INTEGRATION} ; fi -RUN apt install -y ./dist/${INTEGRATION}_${TAG}-1_amd64.deb - -RUN ls $TEST_EXISTENCE -RUN /var/db/newrelic-infra/newrelic-integrations/bin/${INTEGRATION} -show_version | grep ${TAG} \ No newline at end of file diff --git a/dockerfiles-test/Dockerfile-suse b/dockerfiles-test/Dockerfile-suse index e844746..74c8d15 100644 --- a/dockerfiles-test/Dockerfile-suse +++ b/dockerfiles-test/Dockerfile-suse @@ -1,15 +1,11 @@ -FROM pgallina/suse-test as suse-test +FROM suse-base -ARG INTEGRATION=nri-apache -ARG TAG=0.0.1 -ARG TEST_EXISTENCE="" -ARG TEST_UPDATE=false +ARG INTEGRATION +ARG TAG +ARG PKGDIR +ARG UPGRADE=false -ADD ./dist ./dist +ADD ${PKGDIR} ./dist -RUN echo "suse-test-test for ${INTEGRATION} ${TAG}" -RUN if [[ "${TEST_UPDATE}" = true ]] ; then zypper -n install ${INTEGRATION} ; fi -RUN zypper -n install ./dist/${INTEGRATION}-${TAG}-1.x86_64.rpm - -RUN ls $TEST_EXISTENCE -RUN /var/db/newrelic-infra/newrelic-integrations/bin/${INTEGRATION} -show_version | grep ${TAG} \ No newline at end of file +RUN if [ "${UPGRADE}" = "true" ]; then zypper -n install ${INTEGRATION}; fi; \ + zypper -n install ./dist/${INTEGRATION}-${TAG}-1.x86_64.rpm diff --git a/dockerfiles-test/Dockerfile-ubuntu b/dockerfiles-test/Dockerfile-ubuntu new file mode 100644 index 0000000..d346515 --- /dev/null +++ b/dockerfiles-test/Dockerfile-ubuntu @@ -0,0 +1,11 @@ +FROM ubuntu-base + +ARG INTEGRATION +ARG TAG +ARG PKGDIR +ARG UPGRADE=false + +ADD ${PKGDIR} ./dist + +RUN if [ "${UPGRADE}" = "true" ]; then apt install -y ${INTEGRATION}; fi; \ + apt install -y ./dist/${INTEGRATION}_${TAG}-1_amd64.deb diff --git a/entrypoint.sh b/entrypoint.sh index 1c609d2..d4b00b3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,44 +1,69 @@ #!/bin/bash -n=0 -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-suse --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" . -if [[ $? -ne 0 ]] ; then - echo "suse tests failed" - ((n+=1)) -fi +set -o errexit +set -o pipefail -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-suse --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" --build-arg TEST_UPDATE=true . -if [[ $? -ne 0 ]] ; then - echo "suse update tests failed" - ((n+=1)) -fi +[[ -n $GITHUB_ACTION_PATH ]] || GITHUB_ACTION_PATH=$(pwd) +[[ -n $DISTROS ]] || DISTROS="centos suse ubuntu" +[[ -n $PKGDIR ]] || PKGDIR="./dist" -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-centos --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" . -if [[ $? -ne 0 ]] ; then - echo "centos tests failed" - ((n+=1)) +if [[ -z $POST_INSTALL ]]; then + POST_INSTALL=" + test -e /etc/newrelic-infra/integrations.d/${INTEGRATION/nri-/}-config.yml.sample + test -e /var/db/newrelic-infra/newrelic-integrations/${INTEGRATION/nri-/}-definition.yml + test -e /usr/share/doc/${INTEGRATION}/LICENSE* + test -e /usr/share/doc/${INTEGRATION}/CHANGELOG* + test -e /usr/share/doc/${INTEGRATION}/README* + test -x /var/db/newrelic-infra/newrelic-integrations/bin/${INTEGRATION} + /var/db/newrelic-infra/newrelic-integrations/bin/${INTEGRATION} -show_version 2>&1 | grep -e $TAG + " fi +POST_INSTALL="$POST_INSTALL +$POST_INSTALL_EXTRA" -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-centos --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" --build-arg TEST_UPDATE=true . -if [[ $? -ne 0 ]] ; then - echo "centos update tests failed" - ((n+=1)) -fi +function build_and_test() { + if [[ $1 = "true" ]]; then upgradesuffix="-upgrade"; fi + dockertag="$INTEGRATION:$distro-$TAG$upgradesuffix" -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-debian --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" . -if [[ $? -ne 0 ]] ; then - echo "debian tests failed" - ((n+=1)) -fi + echo "ℹ️ Running installation test for $dockertag" + if ! docker build -t "$dockertag" -f "$GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-$distro"\ + --build-arg TAG="$TAG"\ + --build-arg INTEGRATION="$INTEGRATION"\ + --build-arg UPGRADE="$1"\ + --build-arg PKGDIR="$PKGDIR"\ + .; then + echo "❌ Install for $dockertag failed" + return 1 + fi + echo "✅ Installation for $dockertag succeeded" -docker build -f $GITHUB_ACTION_PATH/dockerfiles-test/Dockerfile-debian --build-arg TAG="${TAG}" --build-arg INTEGRATION="${INTEGRATION}" --build-arg TEST_EXISTENCE="${TEST_EXISTENCE}" --build-arg TEST_UPDATE=true . -if [[ $? -ne 0 ]] ; then - echo "debian update tests failed" - ((n+=1)) -fi + echo "ℹ️ Running post-installation checks for $dockertag" + echo "$POST_INSTALL" | while read -r check; do + [[ -n $check ]] || continue + if ! ( echo "$check" | docker run --rm -i "$dockertag" ); then + echo " ❌ $check" + return 2 + fi + echo " ✅ $check" + done + echo "✅ Post-installation checks for $dockertag succeeded" + return 0 +} + +echo "$DISTROS" | tr " " "\n" | while read -r distro; do + echo "::group::Build base image for $distro" + docker build -t "$distro-base" -f "$GITHUB_ACTION_PATH/dockerfiles-base/Dockerfile-base-$distro" . + echo "::endgroup::" + + echo "::group::Clean install on $distro" + build_and_test false + echo "::endgroup::" -if [ $n -gt 0 ]; -then - echo $n "tests failed" - exit 1 -fi \ No newline at end of file + if [[ "$UPGRADE" = "true" ]]; then + echo "::group::Upgrade path on $distro" + build_and_test true + echo "::endgroup::" + else + echo "ℹ️ Skipping upgrade path on $distro" + fi +done