diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35170b805..010449c24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,9 +64,21 @@ jobs: - name: Run Component Tests run: make component-test - integration-test: - name: Integration Tests + integration-tests: runs-on: ubuntu-22.04 + name: Integration Tests + strategy: + matrix: + container: + - image: "rockylinux" + version: "8" + compose-file: "docker-compose-rpm.yml" + - image: "rockylinux" + version: "9" + compose-file: "docker-compose-rpm.yml" + - image: "ubuntu" + version: "22.04" + compose-file: "docker-compose-deb.yml" steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 @@ -74,7 +86,9 @@ jobs: go-version-file: 'go.mod' - name: Run Integration Tests run: | - go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }} + go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }} + OS_RELEASE="${{ matrix.container.image }}" OS_VERSION="${{ matrix.container.version }}" \ + TEST_DOCKER_COMPOSE_FILE="${{ matrix.container.compose-file }}" \ make integration-test performance-test: diff --git a/Makefile b/Makefile index 02d2af4ef..940a82b12 100644 --- a/Makefile +++ b/Makefile @@ -16,19 +16,22 @@ DATE = $(shell date +%F_%H-%M-%S) # | debian | bullseye-slim, buster-slim | | # | centos | 7 | centos 7 (below 7.4) uses plus-pkgs.nginx.com as PACKAGES_REPO | # | redhatenterprise | 7, 8, 9 | | +# | rockylinux | 8, 9 | | # | alpine | 3.13, 3.14, 3.15, 3.16 | | # | oraclelinux | 7, 8 | | # | suse | sles12sp5, sle15 | | # | freebsd | | Not supported | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -OS_RELEASE:=ubuntu -OS_VERSION:=22.04 -BASE_IMAGE="docker.io/${OS_RELEASE}:${OS_VERSION}" -IMAGE_TAG=agent_${OS_RELEASE}_${OS_VERSION} +OS_RELEASE ?= ubuntu +OS_VERSION ?= 22.04 +BASE_IMAGE = "docker.io/${OS_RELEASE}:${OS_VERSION}" +IMAGE_TAG = "agent_${OS_RELEASE}_${OS_VERSION}" + LDFLAGS = "-w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" DEBUG_LDFLAGS = "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" + CERTS_DIR := ./build/certs PACKAGE_PREFIX := nginx-agent PACKAGES_REPO := "pkgs.nginx.com" @@ -45,8 +48,9 @@ else endif endif -TEST_BUILD_DIR := build/test -PACKAGE_NAME := "${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}" +TEST_BUILD_DIR := build/test +TEST_DOCKER_COMPOSE_FILE ?= "docker-compose-deb.yml" +PACKAGE_NAME := "${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-SNAPSHOT-${COMMIT}" CERT_CLIENT_CA_CN := client-ca.local CERT_CLIENT_INT_CN := client-int.local @@ -188,9 +192,9 @@ test-component-run: ## Run component tests performance-test: ## Run performance tests $(CONTAINER_CLITOOL) run -v ${PWD}:/home/nginx/$(CONTAINER_VOLUME_FLAGS) --rm nginx-agent-benchmark:1.0.0 -integration-test: local-deb-package - PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test -v ./test/integration/install - PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} go test -v ./test/integration/api +integration-test: local-deb-package local-rpm-package + PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} DOCKER_COMPOSE_FILE=$(TEST_DOCKER_COMPOSE_FILE) go test -v ./test/integration/install + PACKAGE_NAME=${PACKAGE_NAME} BASE_IMAGE=${BASE_IMAGE} DOCKER_COMPOSE_FILE=${TEST_DOCKER_COMPOSE_FILE} go test -v ./test/integration/api test-bench: ## Run benchmark tests cd test/performance && GOWORK=off CGO_ENABLED=0 go test -mod=vendor -count 5 -timeout 2m -bench=. -benchmem metrics_test.go diff --git a/Makefile.packaging b/Makefile.packaging index e2836d2db..f88c78b23 100644 --- a/Makefile.packaging +++ b/Makefile.packaging @@ -10,6 +10,8 @@ GPG_PUBLIC_KEY := .key DEB_DISTROS?=ubuntu-jammy-22.04 ubuntu-focal-20.04 ubuntu-bionic-18.04 debian-bullseye-11 debian-buster-10 DEB_ARCHS?=arm64 amd64 RPM_DISTROS?=centos-7-x86_64 redhatenterprise-7-x86_64 redhatenterprise-8-x86_64 redhatenterprise-9-x86_64 amazon-2-x86_64 amazon-latest-x86_64 amazon-2017.09-x86_64 suse-12-x86_64 suse-15-x86_64 +ROCKY_VERSIONS?=rocky-8 rocky-9 +ROCKY_ARCHS?=aarch64 x86_64 RPM_ARCH=x86_64 FREEBSD_DISTROS?="FreeBSD:12:amd64" "FreeBSD:13:amd64" APK_VERSIONS?=3.13 3.14 3.15 3.16 @@ -39,27 +41,47 @@ package: gpg-key $(PACKAGES_DIR) $(GITHUB_PACKAGES_DIR) ## Create final packages for distro in $(DEB_DISTROS); do \ deb_codename=`echo $$distro | cut -d- -f 2`; \ VERSION=$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager deb --target ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb; \ - cp ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb; \ + cp ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb; \ done; \ rm -rf ./build/nginx-agent; \ done; \ # Create rpm packages - + @GOWORK=off CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent @for distro in $(RPM_DISTROS); do \ - rpm_distro=`echo $$distro | cut -d- -f 1`; \ + rpm_distro=`echo $$distro | cut -d- -f 1`; \ rpm_major=`echo $$distro | cut -d- -f 2`; \ rpm_codename='na'; \ if [ "$$rpm_distro" = "centos" ] || [ "$$rpm_distro" = "redhatenterprise" ]; then rpm_codename="el$$rpm_major"; \ - elif [ "$$rpm_distro" = "amazon" ] && [ "$$rpm_major" = "2" ]; then rpm_codename="amzn$$rpm_major"; fi; \ - if [ "$$rpm_distro" = "suse" ]; then rpm_codename="sles$$rpm_major"; fi; \ + elif [ "$$rpm_distro" = "amazon" ] && [ "$$rpm_major" = "2" ]; then rpm_codename="amzn$$rpm_major"; \ + elif [ "$$rpm_distro" = "suse" ]; then rpm_codename="sles$$rpm_major"; \ + fi; \ if [ "$$rpm_codename" != "na" ]; then \ VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=amd64 nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \ cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$(RPM_ARCH).rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \ fi; \ done; \ rm -rf ./build/nginx-agent + + # Create rocky rpm packages + + @for arch in $(ROCKY_ARCHS); do \ + goarch=amd64; \ + if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \ + GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \ + for distro in $(ROCKY_VERSIONS); do \ + rpm_distro=`echo $$distro | cut -d- -f 1`; \ + rpm_major=`echo $$distro | cut -d- -f 2`; \ + rpm_codename='na'; \ + if [ "$$rpm_distro" = "rocky" ]; then rpm_codename="rocky$$rpm_major"; fi; \ + if [ "$$rpm_codename" != "na" ]; then \ + VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \ + cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \ + fi; \ + done; \ + rm -rf ./build/nginx-agent; \ + done; \ # Create apk packages @for arch in $(APK_ARCHS); do \ @@ -69,7 +91,7 @@ package: gpg-key $(PACKAGES_DIR) $(GITHUB_PACKAGES_DIR) ## Create final packages for version in $(APK_VERSIONS); do \ if [ ! -d "$(PACKAGES_DIR)/apk/v$${version}/$${arch}" ]; then mkdir -p $(PACKAGES_DIR)/apk/v$${version}/$${arch}; fi; \ VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager apk --target $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').apk; \ - cp $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').apk ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-v$${version}-$${arch}.apk; \ + cp $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').apk ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-v$${version}-$${arch}.apk; \ done; \ rm -rf ./build/nginx-agent; \ done; \ @@ -78,8 +100,8 @@ package: gpg-key $(PACKAGES_DIR) $(GITHUB_PACKAGES_DIR) ## Create final packages rm -rf ./build/nginx-agent @GOWORK=off CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags=${LDFLAGS} -o ./build/nginx-agent - - docker run -v `pwd`:/nginx-agent/ build-signed-packager:1.0.0 + + docker run -v ${PWD}:/nginx-agent/ build-signed-packager:1.0.0 echo "DEB packages:"; \ find $(PACKAGES_DIR)/deb ;\ diff --git a/scripts/docker/nginx-oss/rockylinux/Dockerfile b/scripts/docker/nginx-oss/rockylinux/Dockerfile new file mode 100644 index 000000000..5702ba6b6 --- /dev/null +++ b/scripts/docker/nginx-oss/rockylinux/Dockerfile @@ -0,0 +1,36 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} as install-nginx +LABEL maintainer="NGINX Agent Maintainers " + +ARG NGINX_CONF +ARG ENTRY_POINT + +WORKDIR /agent +COPY ./ /agent +COPY $ENTRY_POINT /agent/entrypoint.sh + +RUN set -x \ + && groupadd --system --gid 101 nginx \ + && adduser -g nginx --system --no-create-home --home /nonexistent --shell /bin/false --uid 101 nginx \ + && usermod -s /sbin/nologin nginx \ + && usermod -L nginx \ + && yum install -y git \ + wget \ + procps \ + make \ + vim \ + nginx + +RUN chmod +x /agent/entrypoint.sh +STOPSIGNAL SIGTERM + +EXPOSE 80 443 + +ENTRYPOINT ["/agent/entrypoint.sh"] + + +FROM install-nginx as install-agent + +ARG PACKAGE_NAME + +RUN yum localinstall -y /agent/build/$PACKAGE_NAME.rpm diff --git a/test/integration/api/api_test.go b/test/integration/api/api_test.go index 3c57cd9b1..02b9dbd7c 100644 --- a/test/integration/api/api_test.go +++ b/test/integration/api/api_test.go @@ -25,7 +25,7 @@ const ( ) func setupTestContainer(t *testing.T) { - comp, err := compose.NewDockerCompose("docker-compose.yml") + comp, err := compose.NewDockerCompose(os.Getenv("DOCKER_COMPOSE_FILE")) assert.NoError(t, err, "NewDockerComposeAPI()") t.Cleanup(func() { diff --git a/test/integration/api/docker-compose.yml b/test/integration/api/docker-compose-deb.yml similarity index 100% rename from test/integration/api/docker-compose.yml rename to test/integration/api/docker-compose-deb.yml diff --git a/test/integration/api/docker-compose-rpm.yml b/test/integration/api/docker-compose-rpm.yml new file mode 100644 index 000000000..31fda79e5 --- /dev/null +++ b/test/integration/api/docker-compose-rpm.yml @@ -0,0 +1,23 @@ +version: '3.9' + +networks: + monitoring: + driver: bridge + +services: + agent: + build: + context: ../../../ + dockerfile: ./scripts/docker/nginx-oss/rockylinux/Dockerfile + target: install-agent + args: + PACKAGE_NAME: ${PACKAGE_NAME} + BASE_IMAGE: ${BASE_IMAGE} + ENTRY_POINT: "./scripts/docker/nginx-oss/entrypoint.sh" + ports: + - 9091:9091 + networks: + - monitoring + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./nginx-agent.conf:/etc/nginx-agent/nginx-agent.conf diff --git a/test/integration/install/docker-compose.yml b/test/integration/install/docker-compose-deb.yml similarity index 100% rename from test/integration/install/docker-compose.yml rename to test/integration/install/docker-compose-deb.yml diff --git a/test/integration/install/docker-compose-rpm.yml b/test/integration/install/docker-compose-rpm.yml new file mode 100644 index 000000000..8bf72aafe --- /dev/null +++ b/test/integration/install/docker-compose-rpm.yml @@ -0,0 +1,14 @@ +version: '3.9' + +services: + agent: + build: + context: ../../../ + dockerfile: ./scripts/docker/nginx-oss/rockylinux/Dockerfile + target: install-nginx + args: + PACKAGE_NAME: ${PACKAGE_NAME} + BASE_IMAGE: ${BASE_IMAGE} + ENTRY_POINT: "./scripts/docker/nginx-oss/agentless-entrypoint.sh" + ports: + - 80 diff --git a/test/integration/install/install_uninstall_test.go b/test/integration/install/install_uninstall_test.go index 66795a798..da3fcc01e 100644 --- a/test/integration/install/install_uninstall_test.go +++ b/test/integration/install/install_uninstall_test.go @@ -33,7 +33,7 @@ var ( func setupTestContainer(t *testing.T) { ctx := context.Background() - comp, err := compose.NewDockerCompose("docker-compose.yml") + comp, err := compose.NewDockerCompose(os.Getenv("DOCKER_COMPOSE_FILE")) assert.NoError(t, err, "NewDockerComposeAPI()") t.Cleanup(func() { @@ -95,9 +95,9 @@ func TestAgentManualInstallUninstall(t *testing.T) { assert.LessOrEqual(t, localAgentPkg.Size(), maxFileSize) - // Install Agent and record installation time/install output - dockerAgentPackagePath := getPackagePath(absContainerAgentPackageDir, string(osReleaseContent)) - installTime, installLog := installAgent(t, agentContainer, dockerAgentPackagePath, string(osReleaseContent)) + // Install Agent inside container and record installation time/install output + containerAgentPackagePath := getPackagePath(absContainerAgentPackageDir, string(osReleaseContent)) + installTime, installLog := installAgent(t, agentContainer, containerAgentPackagePath, string(osReleaseContent)) // Check the install time under 30s assert.LessOrEqual(t, installTime, maxInstallTime) @@ -120,6 +120,10 @@ func TestAgentManualInstallUninstall(t *testing.T) { uninstallLog := uninstallAgent(t, agentContainer, string(osReleaseContent)) // Check uninstall output + if strings.HasSuffix(containerAgentPackagePath, "rpm") { + expectedUninstallLogMsgs["UninstallAgent"] = "Removed:\n nginx-agent" + delete(expectedUninstallLogMsgs, "UninstallAgentPurgingFiles") + } for _, logMsg := range expectedUninstallLogMsgs { assert.Contains(t, uninstallLog, logMsg) } @@ -171,7 +175,7 @@ func createInstallCommand(agentPackageFilePath, osReleaseContent string) []strin if strings.Contains(osReleaseContent, "UBUNTU") || strings.Contains(osReleaseContent, "Debian") { return []string{"dpkg", "-i", agentPackageFilePath} } else { - return []string{"yum", "localinstall", agentPackageFilePath} + return []string{"yum", "localinstall", "-y", agentPackageFilePath} } } @@ -201,7 +205,9 @@ func getPackagePath(pkgDir, osReleaseContent string) string { if strings.Contains(osReleaseContent, "UBUNTU") || strings.Contains(osReleaseContent, "Debian") { return pkgPath + ".deb" - } else { + } else if strings.Contains(osReleaseContent, "rhel") || strings.Contains(osReleaseContent, "centos") { return pkgPath + ".rpm" + } else { + return pkgPath + ".apk" } }