Skip to content

Commit

Permalink
test(compose): add integration test for depends_on in compose #888
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm authored and rohanKanojia committed Nov 11, 2023
1 parent e36ea8d commit 29a779f
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions it/docker-compose-dependon/Postgres.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:13-alpine
HEALTHCHECK --interval=5s --timeout=5s --retries=5 \
CMD "pg_isready" "-U" "postgres"
27 changes: 27 additions & 0 deletions it/docker-compose-dependon/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "2.4"
services:
init:
image: alpine:latest
command:
- echo
- "Hello world!"
db:
image: localpg
build:
context: .
dockerfile: Postgres.Dockerfile
environment:
POSTGRES_PASSWORD: supersecret
tmpfs:
- /var/lib/postgresql/data
depends_on:
init:
condition: service_completed_successfully
web:
image: alpine:latest
command:
- echo
- "Hello foobar (after hello world)!"
depends_on:
db:
condition: service_healthy
77 changes: 77 additions & 0 deletions it/docker-compose-dependon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!--
Integration test demo with wait configurations mapped from Docker compose depends_on long syntax
Call it with: 'mvn verify'
The test does the following:
* Builds a custom postgres image with a healtcheck (because we do not support adding healthchecks from compose yet)
* Start an init container printing a message
* When successfully exited, database container starts
* Once Postgres enters state healthy, another simple container printing a message is started
* Stops and removes the containers.
-->

<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-parent</artifactId>
<version>0.44-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dmp-it-docker-compose-dependon</artifactId>
<version>0.44-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<alias>web</alias>
<name>alpine:latest</name>
<external>
<type>compose</type>
<basedir>${project.basedir}</basedir>
</external>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build</id>
<goals>
<goal>build</goal>
</goals>
<phase>verify</phase>
</execution>
<execution>
<id>start</id>
<goals>
<goal>start</goal>
</goals>
<phase>verify</phase>
<configuration>
<showLogs>true</showLogs>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>stop</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
1 change: 1 addition & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<module>buildx-dockerfile</module>
<module>buildx-push</module>
<module>docker-compose</module>
<module>docker-compose-dependon</module>
<module>dockerfile</module>
<module>dockerignore</module>
<module>healthcheck</module>
Expand Down

0 comments on commit 29a779f

Please sign in to comment.