-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from paologallinaharbur/roobre
Refactor and beautifying
- Loading branch information
Showing
12 changed files
with
176 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] | ||
with: | ||
TAG: '0.0.1' | ||
INTEGRATION: 'nri-apache' | ||
TEST_EXISTENCE: 'file1 file2 file3' | ||
``` | ||
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
RUN if [ "${UPGRADE}" = "true" ]; then zypper -n install ${INTEGRATION}; fi; \ | ||
zypper -n install ./dist/${INTEGRATION}-${TAG}-1.x86_64.rpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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 |