Skip to content

Commit

Permalink
NIFI-12177 Added integration tests for MiNiFi and C2 Docker
Browse files Browse the repository at this point in the history
This closes apache#7919

Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
ChrisSamo632 authored and exceptionfactory committed Oct 26, 2023
1 parent a3e4f89 commit 2e8d021
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 42 deletions.
17 changes: 17 additions & 0 deletions minifi/minifi-c2/minifi-c2-docker/dockermaven/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

# Place files you want to exclude from the docker build here similar to .gitignore https://docs.docker.com/engine/reference/builder/#dockerignore-file
integration-test.sh
2 changes: 1 addition & 1 deletion minifi/minifi-c2/minifi-c2-docker/dockermaven/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ENV MINIFI_C2_HOME ${MINIFI_C2_BASE_DIR}/minifi-c2-current
RUN groupadd -g ${GID} ${MINIFI_C2_USER} \
&& useradd --shell /bin/bash -u ${UID} -g ${GID} -m ${MINIFI_C2_USER}

COPY --from=builder ${MINIFI_C2_BASE_DIR} ${MINIFI_C2_BASE_DIR}
COPY --chown=c2:c2 --from=builder ${MINIFI_C2_BASE_DIR} ${MINIFI_C2_BASE_DIR}

USER ${MINIFI_C2_USER}

Expand Down
74 changes: 74 additions & 0 deletions minifi/minifi-c2/minifi-c2-docker/dockermaven/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

set -exuo pipefail

TAG=$1
VERSION=$2

container_name="nifi-minifi-c2-${TAG}-integration-test"
image_name="apache/nifi-minifi-c2:${TAG}"
port=10090

trap '{ docker inspect -f "{{json .State}}" "${container_name}"; docker rm -f "${container_name}"; }' EXIT

echo "Deleting any existing ${container_name} containers"
docker rm -f "${container_name}"
echo

echo "Checking that all files are owned by C2"
test -z "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c "find /opt/minifi-c2 ! -user c2")"
echo

echo "Checking environment variables"
test "/opt/minifi-c2/minifi-c2-current" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'echo -n ${MINIFI_C2_HOME}')"
test "/opt/minifi-c2/minifi-c2-${VERSION}" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'readlink ${MINIFI_C2_BASE_DIR}/minifi-c2-current')"

test "/opt/minifi-c2" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'echo -n ${MINIFI_C2_BASE_DIR}')"
echo

echo "Starting MiNiFi C2 container..."
docker run -d --name "${container_name}" "${image_name}"
ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "${container_name}")
echo

max_iterations=10
sleep_time=10

sleep ${sleep_time}
for i in $(seq 1 "${max_iterations}") :; do
echo "Waiting for MiNiFi C2 startup - iteration: ${i}"
if docker exec "${container_name}" bash -c " echo Running < /dev/tcp/${ip}/${port}"; then
echo "MiNiFi C2 found active on port ${port}"
break
fi
echo
if [ "${i}" -eq "${max_iterations}" ]; then
echo "MiNiFi C2 did not start within expected time"
exit 1
fi
sleep 10
done
echo

echo "Checking MiNiFi C2 Config Access (Invalid request)"
test "400" = "$(docker exec "${container_name}" bash -c "curl -sSo /dev/null -w %{http_code} -m 10 --retry 5 --retry-connrefused --retry-max-time 60 http://${ip}:${port}/c2/config")"
echo

echo "Stopping MiNiFi C2 container"
time docker stop "${container_name}"
echo
65 changes: 65 additions & 0 deletions minifi/minifi-c2/minifi-c2-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,71 @@ limitations under the License.
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>${project.version}-maven</argument>
<argument>${project.version}</argument>
</arguments>
<executable>${project.basedir}/dockermaven/integration-test.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker-skip-tests</id>
<activation>
<property>
<name>skipTests</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker-test-skip-test</id>
<activation>
<property>
<name>maven.test.skip</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
17 changes: 17 additions & 0 deletions minifi/minifi-docker/dockermaven/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

# Place files you want to exclude from the docker build here similar to .gitignore https://docs.docker.com/engine/reference/builder/#dockerignore-file
integration-test.sh
2 changes: 1 addition & 1 deletion minifi/minifi-docker/dockermaven/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ENV MINIFI_HOME ${MINIFI_BASE_DIR}/minifi-current
RUN groupadd -g ${GID} ${MINIFI_USER} \
&& useradd --shell /bin/bash -u ${UID} -g ${GID} -m ${MINIFI_USER}

COPY --from=builder ${MINIFI_BASE_DIR} ${MINIFI_BASE_DIR}
COPY --chown=minifi:minifi --from=builder ${MINIFI_BASE_DIR} ${MINIFI_BASE_DIR}

USER ${MINIFI_USER}

Expand Down
69 changes: 69 additions & 0 deletions minifi/minifi-docker/dockermaven/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

set -exuo pipefail

TAG=$1
VERSION=$2

container_name="nifi-minifi-${TAG}-integration-test"
image_name="apache/nifi-minifi:${TAG}"

trap '{ docker logs "${container_name}" | tail -10; docker inspect -f "{{json .State}}" "${container_name}"; docker rm -f "${container_name}"; }' EXIT

echo "Deleting any existing ${container_name} containers"
docker rm -f "${container_name}"
echo

echo "Checking that all files are owned by MiNiFi"
test -z "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c "find /opt/minifi ! -user minifi")"
echo

echo "Checking environment variables"
test "/opt/minifi/minifi-current" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'echo -n ${MINIFI_HOME}')"
test "/opt/minifi/minifi-${VERSION}" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'readlink ${MINIFI_BASE_DIR}/minifi-current')"

test "/opt/minifi" = "$(docker run --rm --entrypoint /bin/bash "${image_name}" -c 'echo -n ${MINIFI_BASE_DIR}')"
echo

echo "Starting MiNiFi container..."
docker run -d --name "${container_name}" "${image_name}"
ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "${container_name}")
echo

max_iterations=10
sleep_time=10

sleep ${sleep_time}
for i in $(seq 1 "${max_iterations}") :; do
echo "Waiting for MiNiFi startup - iteration: ${i}"
if docker exec "${container_name}" bash -c './bin/minifi.sh status | grep -F "Apache MiNiFi is currently running"'; then
echo "MiNiFi found active"
break
fi
echo
if [ "${i}" -eq "${max_iterations}" ]; then
echo "MiNiFi did not start within expected time"
exit 1
fi
sleep 10
done
echo

echo "Stopping MiNiFi container"
time docker stop "${container_name}"
echo
65 changes: 65 additions & 0 deletions minifi/minifi-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,71 @@ limitations under the License.
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>${project.version}-maven</argument>
<argument>${project.version}</argument>
</arguments>
<executable>${project.basedir}/dockermaven/integration-test.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker-skip-tests</id>
<activation>
<property>
<name>skipTests</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker-test-skip-test</id>
<activation>
<property>
<name>maven.test.skip</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Docker integration tests</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Loading

0 comments on commit 2e8d021

Please sign in to comment.