-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor] add Dockerfile healthchecks to some core services (#370)
* Create HEALTHCHECK entries for core services * Ensure secret is set for cantaloupe API access * Add test to make sure healthcheck works Allow fpm status from ipv6 localhost * Add more tests * update README * Update README.md * Healthchecks review (#375) * Replace legacy cont-init.d for Cantaloupe service Changes the cantaloupe service init such that it respects service dependencies. This insures that the precedence for container environment follows what is outlined in the container-environment service. * Test compose projects require names. * Bump github action upload artifact * Add names to docker compose tests --------- Co-authored-by: Nigel Banks <nigelgbanks@users.noreply.github.com>
- Loading branch information
1 parent
c30e521
commit 6818439
Showing
33 changed files
with
482 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import plugins.TestsPlugin.DockerComposeUp | ||
import plugins.TestsPlugin.DockerComposeUp.Companion.pool | ||
import java.lang.Thread.sleep | ||
import java.time.Duration.ofSeconds | ||
import java.util.concurrent.CompletableFuture.supplyAsync | ||
import java.io.ByteArrayOutputStream | ||
|
||
tasks.named<DockerComposeUp>("test") { | ||
doFirst { | ||
supplyAsync( | ||
{ | ||
val maxAttempts = 10 | ||
val delayBetweenAttempts = 5000L // 5 seconds in milliseconds | ||
var attempt = 0 | ||
var foundHealthyService = false | ||
|
||
while (attempt < maxAttempts) { | ||
attempt++ | ||
val outputStream = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = baseArguments + listOf("ps", "--all") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
val output = outputStream.toString() | ||
|
||
val healthyServicePattern = """(?m)^.+\s+.+\s+Up \d+ seconds \(healthy\).*$""".toRegex() | ||
foundHealthyService = output.lines().any { line -> | ||
healthyServicePattern.matches(line) | ||
} | ||
|
||
if (foundHealthyService) { | ||
project.exec { | ||
commandLine = baseArguments + listOf("stop") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
break | ||
} | ||
|
||
if (attempt < maxAttempts) { | ||
println("No healthy service found. Retrying in ${delayBetweenAttempts / 1000} seconds...") | ||
sleep(delayBetweenAttempts) | ||
} | ||
} | ||
|
||
// Throw an exception if no healthy service was found after all attempts | ||
if (!foundHealthyService) { | ||
throw GradleException("No service is marked as healthy in docker compose ps output after $maxAttempts attempts.") | ||
} | ||
}, pool | ||
) | ||
} | ||
} |
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,15 @@ | ||
--- | ||
|
||
# Common to all services | ||
x-common: &common | ||
restart: "no" | ||
|
||
name: activemq-servicehealthcheck | ||
services: | ||
activemq: | ||
<<: *common | ||
image: ${ACTIVEMQ:-islandora/activemq:local} | ||
volumes: | ||
- ./test.sh:/test.sh # Test to run. | ||
command: | ||
- /test.sh # Run test and exit. |
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,13 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
on_terminate() { | ||
echo "Termination signal received. Exiting..." | ||
exit 0 | ||
} | ||
trap 'on_terminate' SIGTERM | ||
|
||
sleep 60 | ||
|
||
# The kotlin check should be stopping this container | ||
exit 1 |
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
Empty file.
1 change: 1 addition & 0 deletions
1
cantaloupe/rootfs/etc/s6-overlay/s6-rc.d/cantaloupe-defaults/type
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 @@ | ||
oneshot |
1 change: 1 addition & 0 deletions
1
cantaloupe/rootfs/etc/s6-overlay/s6-rc.d/cantaloupe-defaults/up
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 @@ | ||
/etc/s6-overlay/scripts/cantaloupe-defaults.sh |
Empty file.
9 changes: 9 additions & 0 deletions
9
cantaloupe/rootfs/etc/s6-overlay/scripts/cantaloupe-defaults.sh
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,9 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
set -ex | ||
|
||
# Set the default value for CANTALOUPE_ENDPOINT_API_SECRET if none provided. | ||
DEFAULT_SECRET=$(openssl rand -hex 16) | ||
cat <<EOF | /usr/local/bin/confd-import-environment.sh | ||
CANTALOUPE_ENDPOINT_API_SECRET="{{ getenv "CANTALOUPE_ENDPOINT_API_SECRET" "${DEFAULT_SECRET}" }}" | ||
EOF |
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,54 @@ | ||
import plugins.TestsPlugin.DockerComposeUp | ||
import plugins.TestsPlugin.DockerComposeUp.Companion.pool | ||
import java.lang.Thread.sleep | ||
import java.time.Duration.ofSeconds | ||
import java.util.concurrent.CompletableFuture.supplyAsync | ||
import java.io.ByteArrayOutputStream | ||
|
||
tasks.named<DockerComposeUp>("test") { | ||
doFirst { | ||
supplyAsync( | ||
{ | ||
val maxAttempts = 10 | ||
val delayBetweenAttempts = 5000L // 5 seconds in milliseconds | ||
var attempt = 0 | ||
var foundHealthyService = false | ||
|
||
while (attempt < maxAttempts) { | ||
attempt++ | ||
val outputStream = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = baseArguments + listOf("ps", "--all") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
val output = outputStream.toString() | ||
|
||
val healthyServicePattern = """(?m)^.+\s+.+\s+Up \d+ seconds \(healthy\).*$""".toRegex() | ||
foundHealthyService = output.lines().any { line -> | ||
healthyServicePattern.matches(line) | ||
} | ||
|
||
if (foundHealthyService) { | ||
project.exec { | ||
commandLine = baseArguments + listOf("stop") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
break | ||
} | ||
|
||
if (attempt < maxAttempts) { | ||
println("No healthy service found. Retrying in ${delayBetweenAttempts / 1000} seconds...") | ||
sleep(delayBetweenAttempts) | ||
} | ||
} | ||
|
||
// Throw an exception if no healthy service was found after all attempts | ||
if (!foundHealthyService) { | ||
throw GradleException("No service is marked as healthy in docker compose ps output after $maxAttempts attempts.") | ||
} | ||
}, pool | ||
) | ||
} | ||
} |
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,15 @@ | ||
--- | ||
|
||
# Common to all services | ||
x-common: &common | ||
restart: "no" | ||
|
||
name: cantaloupe-servicehealthcheck | ||
services: | ||
cantaloupe: | ||
<<: *common | ||
image: ${CANTALOUPE:-islandora/cantaloupe:local} | ||
volumes: | ||
- ./test.sh:/test.sh # Test to run. | ||
command: | ||
- /test.sh # Run test and exit. |
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,13 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
on_terminate() { | ||
echo "Termination signal received. Exiting..." | ||
exit 0 | ||
} | ||
trap 'on_terminate' SIGTERM | ||
|
||
sleep 60 | ||
|
||
# The kotlin check should be stopping this container | ||
exit 1 |
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,55 @@ | ||
import plugins.TestsPlugin.DockerComposeUp | ||
import plugins.TestsPlugin.DockerComposeUp.Companion.pool | ||
import java.lang.Thread.sleep | ||
import java.time.Duration.ofSeconds | ||
import java.util.concurrent.CompletableFuture.supplyAsync | ||
import java.io.ByteArrayOutputStream | ||
|
||
tasks.named<DockerComposeUp>("test") { | ||
doFirst { | ||
supplyAsync( | ||
{ | ||
val maxAttempts = 10 | ||
val delayBetweenAttempts = 5000L // 5 seconds in milliseconds | ||
var attempt = 0 | ||
var foundHealthyService = false | ||
|
||
while (attempt < maxAttempts) { | ||
attempt++ | ||
val outputStream = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = baseArguments + listOf("ps", "--all") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
val output = outputStream.toString() | ||
|
||
val healthyServicePattern = """(?m)^.+\s+.+\s+Up \d+ seconds \(healthy\).*$""".toRegex() | ||
foundHealthyService = output.lines().any { line -> | ||
healthyServicePattern.matches(line) | ||
} | ||
|
||
if (foundHealthyService) { | ||
println("Service is healthy. Exiting test...") | ||
project.exec { | ||
commandLine = baseArguments + listOf("stop") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
break | ||
} | ||
|
||
if (attempt < maxAttempts) { | ||
println("No healthy service found. Retrying in ${delayBetweenAttempts / 1000} seconds...") | ||
sleep(delayBetweenAttempts) | ||
} | ||
} | ||
|
||
// Throw an exception if no healthy service was found after all attempts | ||
if (!foundHealthyService) { | ||
throw GradleException("No service is marked as healthy in docker compose ps output after $maxAttempts attempts.") | ||
} | ||
}, pool | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import plugins.TestsPlugin.DockerComposeUp | ||
import plugins.TestsPlugin.DockerComposeUp.Companion.pool | ||
import java.lang.Thread.sleep | ||
import java.time.Duration.ofSeconds | ||
import java.util.concurrent.CompletableFuture.supplyAsync | ||
import java.io.ByteArrayOutputStream | ||
|
||
tasks.named<DockerComposeUp>("test") { | ||
doFirst { | ||
supplyAsync( | ||
{ | ||
val maxAttempts = 10 | ||
val delayBetweenAttempts = 5000L // 5 seconds in milliseconds | ||
var attempt = 0 | ||
var foundHealthyService = false | ||
|
||
while (attempt < maxAttempts) { | ||
attempt++ | ||
val outputStream = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = baseArguments + listOf("ps", "--all") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
val output = outputStream.toString() | ||
|
||
val healthyServicePattern = """(?m)^.+\s+.+\s+Up \d+ seconds \(healthy\).*$""".toRegex() | ||
foundHealthyService = output.lines().any { line -> | ||
healthyServicePattern.matches(line) | ||
} | ||
|
||
if (foundHealthyService) { | ||
project.exec { | ||
commandLine = baseArguments + listOf("stop") | ||
standardOutput = outputStream | ||
workingDir = project.projectDir | ||
} | ||
break | ||
} | ||
|
||
if (attempt < maxAttempts) { | ||
println("No healthy service found. Retrying in ${delayBetweenAttempts / 1000} seconds...") | ||
sleep(delayBetweenAttempts) | ||
} | ||
} | ||
|
||
// Throw an exception if no healthy service was found after all attempts | ||
if (!foundHealthyService) { | ||
throw GradleException("No service is marked as healthy in docker compose ps output after $maxAttempts attempts.") | ||
} | ||
}, pool | ||
) | ||
} | ||
} |
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 @@ | ||
--- | ||
|
||
# Common to all services | ||
x-common: &common | ||
restart: "no" | ||
|
||
name: fcrepo6-servicehealthcheck | ||
services: | ||
activemq: | ||
<<: *common | ||
image: ${ACTIVEMQ:-islandora/activemq:local} | ||
fcrepo6: | ||
volumes: | ||
- ./test.sh:/test.sh # Test to run. | ||
command: | ||
- /test.sh # Run test and exit. | ||
image: ${FCREPO6:-islandora/fcrepo6:local} | ||
depends_on: | ||
- activemq |
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,13 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
on_terminate() { | ||
echo "Termination signal received. Exiting..." | ||
exit 0 | ||
} | ||
trap 'on_terminate' SIGTERM | ||
|
||
sleep 60 | ||
|
||
# The kotlin check should be stopping this container | ||
exit 1 |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../ci/healthcheck.gradle.kts |
Oops, something went wrong.