Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .github/workflows/build-and-push-container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
!contains(github.event.pull_request.labels.*.name, 'chore')
steps:
- name: Checkout GIT repository
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Get the application version
id: application-version
run: |
Expand All @@ -28,20 +28,29 @@ jobs:
echo "ERROR: unable to detect version number!" >&2
exit 1
fi
echo "tag=${image_version}" >> $GITHUB_OUTPUT
echo "tag=${image_version}" >> "${GITHUB_OUTPUT}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4
- name: Login to container registry
uses: docker/login-action@v3
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
push: true
context: .
platforms: linux/amd64, linux/arm64
tags: oitc/modbus-client:${{steps.application-version.outputs.tag}},oitc/modbus-client:latest
labels: |
site.local.program.version=${{ steps.application-version.outputs.tag }}
context.github.repositoryUrl=${{ github.repositoryUrl }}
context.github.actor=${{ github.actor }}
context.github.event.repository.updated_at=${{ github.event.repository.updated_at}}
context.github.ref=${{ github.ref }}
context.github.job=${{ github.job }}
context.runner.os=${{ runner.os }}
context.runner.arch=${{ runner.arch }}
194 changes: 2 additions & 192 deletions .github/workflows/container-image-build-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,195 +7,5 @@ on:
- synchronize
- reopened
jobs:
container-build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout GIT repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Test build
uses: docker/build-push-action@v6
with:
push: false
load: false
context: .
platforms: linux/amd64, linux/arm64
tags: container-build:test
- name: Test build and export for further validation
uses: docker/build-push-action@v6
with:
push: false
load: true
context: .
tags: container-build:test
outputs: type=docker,dest=/tmp/container.tar
- name: Upload container image as artifact
uses: actions/upload-artifact@v4
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@v6
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
uses: cybcon/github_workflows/.github/workflows/container-vulnerability-scan.yaml@v1.4.0
with:
image_name: container-build:test
image_artifact_filename: container.tar
image_artifact_name: container-build
login_dockerhub: false
trivy_tag: latest
container-image-build-validation:
uses: cybcon/github_workflows/.github/workflows/container-image-build-validation.yaml@v2.1.0
3 changes: 1 addition & 2 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ on:
pull_request:
push:
branches:
- master
- main
jobs:
pre-commit:
uses: cybcon/github_workflows/.github/workflows/pre-commit.yaml@v1.4.0
uses: cybcon/github_workflows/.github/workflows/pre-commit.yaml@v2.1.0
2 changes: 1 addition & 1 deletion .github/workflows/release-from-label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ on:
- closed
jobs:
release:
uses: cybcon/github_workflows/.github/workflows/release-from-label.yaml@v1.4.0
uses: cybcon/github_workflows/.github/workflows/release-from-label.yaml@v2.1.0
2 changes: 1 addition & 1 deletion .github/workflows/release-label-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ on:
- unlabeled
jobs:
release-label-validation:
uses: cybcon/github_workflows/.github/workflows/release-label-validation.yaml@v1.4.0
uses: cybcon/github_workflows/.github/workflows/release-label-validation.yaml@v2.1.0
23 changes: 17 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: fix-byte-order-marker
- id: check-ast
- id: check-json
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ['--fix=lf']
description: Forces to replace line ending by the UNIX 'lf' character
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade
- repo: https://github.com/myint/autoflake
rev: v2.3.1
rev: v2.3.3
hooks:
- id: autoflake
args:
- --in-place
- --remove-unused-variables
- --remove-all-unused-imports
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
rev: v2.14.0
hooks:
- id: hadolint-docker
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.8.4
rev: v0.15.20
hooks:
- id: ruff
args:
- '--line-length=120'
- '--fix'
- '--exit-non-zero-on-fix'
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 8.0.1
hooks:
- id: isort
name: isort (python)
Expand All @@ -43,8 +50,12 @@ repos:
- black
- '--filter-files'
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 26.5.1
hooks:
- id: black
args:
- '--line-length=120'
- repo: https://github.com/rhysd/actionlint
rev: v1.7.11
hooks:
- id: actionlint
3 changes: 2 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pre-commit 4.0.1
pre-commit 4.6.0
python 3.14.6
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system"
}
Loading