diff --git a/.github/workflows/container-image-build-validation.yaml b/.github/workflows/container-image-build-validation.yaml index 59ebf0b..a03a545 100644 --- a/.github/workflows/container-image-build-validation.yaml +++ b/.github/workflows/container-image-build-validation.yaml @@ -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 '
' >> ${GITHUB_STEP_SUMMARY} + echo ' Test output details' >> ${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 '
' >> ${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 '
' >> ${GITHUB_STEP_SUMMARY} + echo ' Test output details' >> ${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 '
' >> ${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 '
' >> ${GITHUB_STEP_SUMMARY} + echo ' Test output details' >> ${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 '
' >> ${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 '
' >> ${GITHUB_STEP_SUMMARY} + echo ' Test output details' >> ${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 '
' >> ${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 diff --git a/Dockerfile b/Dockerfile index d3c342c..812514d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/* @@ -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 @@ -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 " -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 diff --git a/README.md b/README.md index 0120fe4..7cc001a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/app/modbus_client.py b/src/app/modbus_client.py index 6181e69..f92a056 100644 --- a/src/app/modbus_client.py +++ b/src/app/modbus_client.py @@ -18,7 +18,7 @@ import FloatToHex from numpy import little_endian -VERSION='1.0.14' +VERSION='1.0.15' DEBUG=False """ ###############################################################################