Skip to content

Commit

Permalink
Add Paketo image building system tests
Browse files Browse the repository at this point in the history
A new system test plugin is being made available for running test
suites that should be run less frequently than with every commit, such
as tests that verify Spring Boot compatibility with external
projects. CI pipeline configuration for running system tests is also
provided.

The first system tests verify the behavior of the Spring Boot image
building plugins when building images using Paketo buildpacks.

Closes gh-25824
  • Loading branch information
scottfrederick committed Jul 8, 2021
1 parent d82b46b commit 18c7c0a
Show file tree
Hide file tree
Showing 51 changed files with 1,326 additions and 73 deletions.
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Expand Up @@ -67,6 +67,10 @@ gradlePlugin {
id = "org.springframework.boot.integration-test"
implementationClass = "org.springframework.boot.build.test.IntegrationTestPlugin"
}
systemTestPlugin {
id = "org.springframework.boot.system-test"
implementationClass = "org.springframework.boot.build.test.SystemTestPlugin"
}
mavenPluginPlugin {
id = "org.springframework.boot.maven-plugin"
implementationClass = "org.springframework.boot.build.mavenplugin.MavenPluginPlugin"
Expand Down
@@ -0,0 +1,83 @@
/*
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build.test;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.testing.Test;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;

/**
* A {@link Plugin} to configure system testing support in a {@link Project}.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
public class SystemTestPlugin implements Plugin<Project> {

/**
* Name of the {@code systemTest} task.
*/
public static String SYSTEM_TEST_TASK_NAME = "systemTest";

/**
* Name of the {@code systemTest} source set.
*/
public static String SYSTEM_TEST_SOURCE_SET_NAME = "systemTest";

@Override
public void apply(Project project) {
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> configureSystemTesting(project));
}

private void configureSystemTesting(Project project) {
SourceSet systemTestSourceSet = createSourceSet(project);
createTestTask(project, systemTestSourceSet);
project.getPlugins().withType(EclipsePlugin.class, (eclipsePlugin) -> {
EclipseModel eclipse = project.getExtensions().getByType(EclipseModel.class);
eclipse.classpath((classpath) -> classpath.getPlusConfigurations().add(
project.getConfigurations().getByName(systemTestSourceSet.getRuntimeClasspathConfigurationName())));
});
}

private SourceSet createSourceSet(Project project) {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
SourceSet systemTestSourceSet = sourceSets.create(SYSTEM_TEST_SOURCE_SET_NAME);
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
systemTestSourceSet
.setCompileClasspath(systemTestSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput()));
systemTestSourceSet
.setRuntimeClasspath(systemTestSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput()));
return systemTestSourceSet;
}

private void createTestTask(Project project, SourceSet systemTestSourceSet) {
Test systemTest = project.getTasks().create(SYSTEM_TEST_TASK_NAME, Test.class);
systemTest.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
systemTest.setDescription("Runs system tests.");
systemTest.setTestClassesDirs(systemTestSourceSet.getOutput().getClassesDirs());
systemTest.setClasspath(systemTestSourceSet.getRuntimeClasspath());
systemTest.shouldRunAfter(JavaPlugin.TEST_TASK_NAME);
}

}
89 changes: 89 additions & 0 deletions ci/pipeline.yml
Expand Up @@ -41,6 +41,14 @@ anchors:
BRANCH: ((branch))
<<: *gradle-enterprise-task-params
<<: *docker-hub-task-params
run-system-tests-task-params: &run-system-tests-task-params
privileged: true
timeout: ((task-timeout))
file: git-repo/ci/tasks/run-system-tests.yml
params:
BRANCH: ((branch))
<<: *gradle-enterprise-task-params
<<: *docker-hub-task-params
artifactory-repo-put-params: &artifactory-repo-put-params
signing_key: ((signing-key))
signing_passphrase: ((signing-passphrase))
Expand Down Expand Up @@ -165,6 +173,12 @@ resources:
source:
<<: *registry-image-resource-source
repository: ((docker-hub-organization))/spring-boot-ci-jdk16
- name: paketo-builder-base-image
type: registry-image
icon: docker
source:
repository: paketobuildpacks/builder
tag: base
- name: artifactory-repo
type: artifactory-resource
icon: package-variant
Expand Down Expand Up @@ -668,11 +682,86 @@ jobs:
- put: homebrew-tap-repo
params:
repository: updated-homebrew-tap-repo
- name: run-system-tests
serial: true
public: true
plan:
- get: ci-image
- get: git-repo
- get: paketo-builder-base-image
trigger: true
- get: daily
trigger: true
- do:
- task: run-system-tests
image: ci-image
<<: *run-system-tests-task-params
on_failure:
do:
- put: slack-alert
params:
<<: *slack-fail-params
- put: slack-alert
params:
<<: *slack-success-params
- name: jdk11-run-system-tests
serial: true
public: true
plan:
- get: ci-image-jdk11
- get: git-repo
- get: paketo-builder-base-image
trigger: true
- get: daily
trigger: true
- do:
- task: run-system-tests
image: ci-image-jdk11
<<: *run-system-tests-task-params
on_failure:
do:
- put: slack-alert
params:
<<: *slack-fail-params
- put: slack-alert
params:
<<: *slack-success-params
- name: jdk16-run-system-tests
serial: true
public: true
plan:
- get: ci-image-jdk16
- get: git-repo
- get: paketo-builder-base-image
trigger: true
- get: daily
trigger: true
- do:
- task: run-system-tests
image: ci-image-jdk16
privileged: true
timeout: ((task-timeout))
file: git-repo/ci/tasks/run-system-tests.yml
params:
BRANCH: ((branch))
TOOLCHAIN_JAVA_VERSION: 16
<<: *gradle-enterprise-task-params
<<: *docker-hub-task-params
on_failure:
do:
- put: slack-alert
params:
<<: *slack-fail-params
- put: slack-alert
params:
<<: *slack-success-params
groups:
- name: "builds"
jobs: ["build", "jdk11-build", "jdk16-build", "windows-build"]
- name: "releases"
jobs: ["stage-milestone", "stage-rc", "stage-release", "promote-milestone", "promote-rc", "promote-release", "create-github-release", "publish-gradle-plugin", "publish-to-sdkman", "update-homebrew-tap"]
- name: "system-tests"
jobs: ["run-system-tests", "jdk11-run-system-tests", "jdk16-run-system-tests"]
- name: "ci-images"
jobs: ["build-ci-images", "detect-docker-updates", "detect-jdk-updates", "detect-ubuntu-image-updates"]
- name: "pull-requests"
Expand Down
12 changes: 12 additions & 0 deletions ci/scripts/run-system-tests.sh
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

source $(dirname $0)/common.sh

pushd git-repo > /dev/null
if [[ -d /opt/openjdk-toolchain ]]; then
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 --rerun-tasks systemTest -PtoolchainVersion=${TOOLCHAIN_JAVA_VERSION} -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.auto-download=false -Porg.gradle.java.installations.paths=/opt/openjdk-toolchain/
else
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 --rerun-tasks systemTest
fi
popd > /dev/null
21 changes: 21 additions & 0 deletions ci/tasks/run-system-tests.yml
@@ -0,0 +1,21 @@
---
platform: linux
inputs:
- name: git-repo
caches:
- path: gradle
params:
BRANCH:
CI: true
GRADLE_ENTERPRISE_ACCESS_KEY:
GRADLE_ENTERPRISE_CACHE_USERNAME:
GRADLE_ENTERPRISE_CACHE_PASSWORD:
GRADLE_ENTERPRISE_URL: https://ge.spring.io
run:
path: bash
args:
- -ec
- |
source /docker-lib.sh
start_docker
${PWD}/git-repo/ci/scripts/run-system-tests.sh
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -75,6 +75,7 @@ include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configurati
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-launch-script-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-server-tests"
include "spring-boot-system-tests:spring-boot-image-tests"

file("${rootDir}/spring-boot-project/spring-boot-starters").eachDirMatch(~/spring-boot-starter.*/) {
include "spring-boot-project:spring-boot-starters:${it.name}"
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

/**
* Tests for the getting started documentation.
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,8 +20,8 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.Dsl;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.Dsl;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumingThat;
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.util.FileCopyUtils;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Expand Up @@ -26,7 +26,7 @@

import org.springframework.boot.gradle.junit.GradleCompatibility;
import org.springframework.boot.gradle.tasks.buildinfo.BuildInfo;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.util.ReflectionUtils;

/**
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extension;

import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;

/**
* {@link Extension} that runs {@link TestTemplate templated tests} against multiple
Expand Down

0 comments on commit 18c7c0a

Please sign in to comment.