Skip to content

Commit

Permalink
Feature/container function test (#21)
Browse files Browse the repository at this point in the history
* Add functionalit test

* Upgrade dependencies and increase version number

* fixing duplicated job name

* fixing docker pull command for modbus-client pull

* use the modbus-client from function-test-preparation
  • Loading branch information
cybcon authored Sep 3, 2024
1 parent b193bca commit 5891612
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 6 deletions.
151 changes: 151 additions & 0 deletions .github/workflows/container-image-build-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,157 @@ jobs:
with:
name: container-build
path: /tmp/container.tar

function-test-preparation:
name: Container functionality test preparation
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout GIT repository
uses: actions/checkout@v4
- name: Log in to Github container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build container for functionality test
uses: docker/build-push-action@v5
with:
push: true
load: false
context: .
file: ./Dockerfile
tags: ghcr.io/cybcon/modbus-client/modbus-client:test

function-test-execution:
name: Container functionality test execution
needs: function-test-preparation
runs-on: ubuntu-latest
services:
modbusserver:
image: oitc/modbus-server:latest
ports:
- 5020:5020
steps:
- name: Log in to Github container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Pull Modbus Client for functionality test
run: |
docker pull ghcr.io/cybcon/modbus-client/modbus-client:test
echo "# Modbus functionality test" >> ${GITHUB_STEP_SUMMARY}
- name: Get modbus server address
id: modbus-server-address
run: |
LOCAL_MACHINE=$(ifconfig -a eth0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
echo "DEBUG: ${LOCAL_MACHINE}"
echo "ip=${LOCAL_MACHINE}" >> $GITHUB_OUTPUT
- name: Validate server endpoint
run: |
modbusserver=${{steps. modbus-server-address.outputs.ip}}
ping -c 1 -q ${modbusserver}
RC=$?
if [ ${RC} -gt 0 ]; then
echo "ERROR: Modbus slave not reachable" >&2
exit 1
fi
- name: Test Discrete Output Coils
run: |
modbusserver=${{steps. modbus-server-address.outputs.ip}}
echo "## Get Discrete Output Coils" >> ${GITHUB_STEP_SUMMARY}
echo '<details>' >> ${GITHUB_STEP_SUMMARY}
echo ' <summary>Test output details</summary>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo " docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 1 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 1 -r 0 -l 10 > output.tmp 2>&1
cat output.tmp | while read line
do
echo " ${line}" >> ${GITHUB_STEP_SUMMARY}
done
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo '</details>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
# analyze output
RESULT=$(cat output.tmp | grep ^2 | awk '{print $3}')
if [ "${RESULT}" == "False" ]; then
echo "Test succesfull :white_check_mark:" >> ${GITHUB_STEP_SUMMARY}
else
echo "Test failed :x:" >> ${GITHUB_STEP_SUMMARY}
exit 1
fi
- name: Test Discrete Input Contacts
run: |
modbusserver=${{steps. modbus-server-address.outputs.ip}}
echo "## Get Discrete Input Contacts" >> ${GITHUB_STEP_SUMMARY}
echo '<details>' >> ${GITHUB_STEP_SUMMARY}
echo ' <summary>Test output details</summary>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo " docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 2 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 2 -r 0 -l 10 > output.tmp 2>&1
cat output.tmp | while read line
do
echo " ${line}" >> ${GITHUB_STEP_SUMMARY}
done
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo '</details>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
# analyze output
RESULT=$(cat output.tmp | grep ^10002 | awk '{print $3}')
if [ "${RESULT}" == "False" ]; then
echo "Test succesfull :white_check_mark:" >> ${GITHUB_STEP_SUMMARY}
else
echo "Test failed :x:" >> ${GITHUB_STEP_SUMMARY}
exit 1
fi
- name: Test Analog Output Holding Register
run: |
modbusserver=${{steps. modbus-server-address.outputs.ip}}
echo "## Get Analog Output Holding Register" >> ${GITHUB_STEP_SUMMARY}
echo '<details>' >> ${GITHUB_STEP_SUMMARY}
echo ' <summary>Test output details</summary>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo " docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 3 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 3 -r 0 -l 10 > output.tmp 2>&1
cat output.tmp | while read line
do
echo " ${line}" >> ${GITHUB_STEP_SUMMARY}
done
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo '</details>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
# analyze output
RESULT=$(cat output.tmp | grep ^40002 | awk '{print $2}')
if [ "${RESULT}" == "0x0000" ]; then
echo "Test succesfull :white_check_mark:" >> ${GITHUB_STEP_SUMMARY}
else
echo "Test failed :x:" >> ${GITHUB_STEP_SUMMARY}
exit 1
fi
- name: Test Analog Input Register
run: |
modbusserver=${{steps. modbus-server-address.outputs.ip}}
echo "## Get Analog Input Register" >> ${GITHUB_STEP_SUMMARY}
echo '<details>' >> ${GITHUB_STEP_SUMMARY}
echo ' <summary>Test output details</summary>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo " docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 4 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm ghcr.io/cybcon/modbus-client/modbus-client:test -s ${modbusserver} -p 5020 -t 4 -r 0 -l 10 > output.tmp 2>&1
cat output.tmp | while read line
do
echo " ${line}" >> ${GITHUB_STEP_SUMMARY}
done
echo ' ```' >> ${GITHUB_STEP_SUMMARY}
echo '</details>' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
# analyze output
RESULT=$(cat output.tmp | grep ^30002 | head -1 | awk '{print $2}')
if [ "${RESULT}" == "0x0000" ]; then
echo "Test succesfull :white_check_mark:" >> ${GITHUB_STEP_SUMMARY}
else
echo "Test failed :x:" >> ${GITHUB_STEP_SUMMARY}
exit 1
fi
scan:
name: Container vulnerability scan
needs: container-build
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.18.4 AS base
FROM alpine:3.18.8 AS base
RUN apk upgrade --available --no-cache --update \
&& apk add --no-cache --update \
python3=3.11.6-r0 \
python3=3.11.8-r1 \
py3-pip=23.1.2-r0 \
# Cleanup APK
&& rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
Expand All @@ -12,7 +12,7 @@ RUN apk upgrade --available --no-cache --update \
FROM base as builder
RUN apk add --no-cache --update \
g++=12.2.1_git20220924-r10 \
python3-dev=3.11.6-r0 \
python3-dev=3.11.8-r1 \
&& ln -s /usr/include/locale.h /usr/include/xlocale.h
COPY --chown=root:root FloatToHex /FloatToHex

Expand All @@ -26,7 +26,7 @@ RUN python3 setup.py install
# Building the docker image with already compiled modules
FROM base
LABEL maintainer="Michael Oberdorf IT-Consulting <[email protected]>"
LABEL site.local.program.version="1.0.14"
LABEL site.local.program.version="1.0.15"

COPY --from=builder /usr/lib/python3.11/site-packages /usr/lib/python3.11/site-packages

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Container Registry: [DockerHub](https://hub.docker.com/r/oitc/modbus-client)

# Supported tags and respective `Dockerfile` links

* [`latest`, `1.0.14`](https://github.com/cybcon/modbus-client/blob/v1.0.14/Dockerfile)
* [`latest`, `1.0.15`](https://github.com/cybcon/modbus-client/blob/v1.0.15/Dockerfile)
* [`1.0.14`](https://github.com/cybcon/modbus-client/blob/v1.0.14/Dockerfile)
* [`1.0.13`](https://github.com/cybcon/modbus-client/blob/v1.0.13/Dockerfile)
* [`1.0.12`](https://github.com/cybcon/modbus-client/blob/v1.0.12/Dockerfile)
* [`1.0.11`](https://github.com/cybcon/modbus-client/blob/v1.0.11/Dockerfile)
Expand Down
2 changes: 1 addition & 1 deletion src/app/modbus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import FloatToHex
from numpy import little_endian

VERSION='1.0.14'
VERSION='1.0.15'
DEBUG=False
"""
###############################################################################
Expand Down

0 comments on commit 5891612

Please sign in to comment.