forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): add orca-integration module to exercise the just-built d…
…ocker image (backport spinnaker#4721) (spinnaker#4737) * feat(build): add orca-integration module to exercise the just-built docker image (spinnaker#4721) * feat(docker): add HEALTHCHECK to facilitate testing container startup * feat(build): add orca-integration module to exercise the just-built docker image * feat(gha): run integration test in pr builds multi-arch with --load doesn't work, so add a separate step using the local platform to make an image available for testing. see docker/buildx#59 * feat(gha): run integration test in branch builds (cherry picked from commit b360ad5) # Conflicts: # .github/workflows/build.yml # .github/workflows/pr.yml # Dockerfile.java11.slim # Dockerfile.java11.ubuntu # Dockerfile.slim # Dockerfile.ubuntu * fix(build): resolve conflicts while backporting to release-1.32.x There are Dockerfile.java11.* files on this branch * fix(integration): add useJUnitPlatform to orca-integration.gradle so the tests actually run --------- Co-authored-by: David Byron <[email protected]> Co-authored-by: David Byron <[email protected]>
- Loading branch information
1 parent
2613c51
commit 3f8965d
Showing
8 changed files
with
227 additions
and
2 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
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,9 +1,10 @@ | ||
FROM alpine:3.16 | ||
LABEL maintainer="[email protected]" | ||
RUN apk --no-cache add --update bash openjdk11-jre | ||
RUN apk --no-cache add --update bash curl openjdk11-jre | ||
RUN addgroup -S -g 10111 spinnaker | ||
RUN adduser -S -G spinnaker -u 10111 spinnaker | ||
COPY orca-web/build/install/orca /opt/orca | ||
RUN mkdir -p /opt/orca/plugins && chown -R spinnaker:nogroup /opt/orca/plugins | ||
USER spinnaker | ||
HEALTHCHECK CMD curl --fail http://localhost:8083/health | ||
CMD ["/opt/orca/bin/orca"] |
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,8 +1,9 @@ | ||
FROM ubuntu:bionic | ||
LABEL maintainer="[email protected]" | ||
RUN apt-get update && apt-get -y install openjdk-11-jre-headless wget | ||
RUN apt-get update && apt-get -y install curl openjdk-11-jre-headless wget | ||
RUN adduser --system --uid 10111 --group spinnaker | ||
COPY orca-web/build/install/orca /opt/orca | ||
RUN mkdir -p /opt/orca/plugins && chown -R spinnaker:nogroup /opt/orca/plugins | ||
USER spinnaker | ||
HEALTHCHECK CMD curl --fail http://localhost:8083/health | ||
CMD ["/opt/orca/bin/orca"] |
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,27 @@ | ||
dependencies { | ||
testImplementation "com.fasterxml.jackson.core:jackson-databind" | ||
testImplementation "org.assertj:assertj-core" | ||
testImplementation "org.junit.jupiter:junit-jupiter-api" | ||
testImplementation "org.slf4j:slf4j-api" | ||
testImplementation "org.testcontainers:testcontainers" | ||
testImplementation "org.testcontainers:junit-jupiter" | ||
testRuntimeOnly "ch.qos.logback:logback-classic" | ||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" | ||
} | ||
|
||
test.configure { | ||
def fullDockerImageName = System.getenv('FULL_DOCKER_IMAGE_NAME') | ||
onlyIf("there is a docker image to test") { | ||
fullDockerImageName != null && fullDockerImageName.trim() != '' | ||
} | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
|
||
// So stdout and stderr from the just-built container are available in CI | ||
testLogging.showStandardStreams = true | ||
|
||
// Run the tests when the docker image changes | ||
inputs.property 'fullDockerImageName', System.getenv('FULL_DOCKER_IMAGE_NAME') | ||
} |
133 changes: 133 additions & 0 deletions
133
orca-integration/src/test/java/com/netflix/spinnaker/orca/StandaloneContainerTest.java
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,133 @@ | ||
/* | ||
* Copyright 2024 Salesforce, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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 com.netflix.spinnaker.orca; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@Testcontainers | ||
class StandaloneContainerTest { | ||
|
||
private static final String REDIS_NETWORK_ALIAS = "redisHost"; | ||
|
||
private static final int REDIS_PORT = 6379; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(StandaloneContainerTest.class); | ||
|
||
private static final Network network = Network.newNetwork(); | ||
|
||
private static final GenericContainer redis = | ||
new GenericContainer(DockerImageName.parse("library/redis:5-alpine")) | ||
.withNetwork(network) | ||
.withNetworkAliases(REDIS_NETWORK_ALIAS) | ||
.withExposedPorts(REDIS_PORT); | ||
|
||
private static GenericContainer orcaContainer; | ||
|
||
@BeforeAll | ||
static void setupOnce() throws Exception { | ||
String fullDockerImageName = System.getenv("FULL_DOCKER_IMAGE_NAME"); | ||
|
||
// Skip the tests if there's no docker image. This allows gradlew build to work. | ||
assumeTrue(fullDockerImageName != null); | ||
|
||
redis.start(); | ||
|
||
DockerImageName dockerImageName = DockerImageName.parse(fullDockerImageName); | ||
|
||
orcaContainer = | ||
new GenericContainer(dockerImageName) | ||
.withNetwork(network) | ||
.withExposedPorts(8083) | ||
.dependsOn(redis) | ||
.waitingFor(Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(90))) | ||
.withEnv("SPRING_APPLICATION_JSON", getSpringApplicationJson()); | ||
|
||
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(logger); | ||
orcaContainer.start(); | ||
orcaContainer.followOutput(logConsumer); | ||
} | ||
|
||
private static String getSpringApplicationJson() throws JsonProcessingException { | ||
String redisUrl = "redis://" + REDIS_NETWORK_ALIAS + ":" + REDIS_PORT; | ||
logger.info("redisUrl: '{}'", redisUrl); | ||
Map<String, String> properties = | ||
Map.of("redis.connection", redisUrl, "services.fiat.baseUrl", "http://nowhere"); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
return mapper.writeValueAsString(properties); | ||
} | ||
|
||
@AfterAll | ||
static void cleanupOnce() { | ||
if (orcaContainer != null) { | ||
orcaContainer.stop(); | ||
} | ||
|
||
if (redis != null) { | ||
redis.stop(); | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void init(TestInfo testInfo) { | ||
System.out.println("--------------- Test " + testInfo.getDisplayName()); | ||
} | ||
|
||
@Test | ||
void testHealthCheck() throws Exception { | ||
// hit an arbitrary endpoint | ||
HttpRequest request = | ||
HttpRequest.newBuilder() | ||
.uri( | ||
new URI( | ||
"http://" | ||
+ orcaContainer.getHost() | ||
+ ":" | ||
+ orcaContainer.getFirstMappedPort() | ||
+ "/health")) | ||
.GET() | ||
.build(); | ||
|
||
HttpClient client = HttpClient.newHttpClient(); | ||
|
||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
assertThat(response).isNotNull(); | ||
logger.info("response: {}, {}", response.statusCode(), response.body()); | ||
assertThat(response.statusCode()).isEqualTo(200); | ||
} | ||
} |
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,36 @@ | ||
<!-- | ||
Copyright 2024 Salesforce, Inc. | ||
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 | ||
http://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. | ||
--> | ||
<configuration> | ||
|
||
<!-- see https://java.testcontainers.org/supported_docker_environment/logging_config/ --> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="DEBUG"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
<logger name="org.testcontainers" level="INFO"/> | ||
<logger name="tc" level="INFO"/> | ||
<logger name="com.github.dockerjava" level="WARN"/> | ||
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/> | ||
<logger name="wiremock.org.eclipse.jetty" level="INFO"/> | ||
</configuration> |
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