-
-
Notifications
You must be signed in to change notification settings - Fork 2
201 lines (198 loc) · 8.27 KB
/
container-image-build-validation.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: container-image-build-validation
on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
jobs:
container-build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout GIT repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Test build
uses: docker/[email protected]
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/[email protected]
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/[email protected]
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 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 oitc/modbus-client:latest -s ${modbusserver} -p 5020 -t 1 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm oitc/modbus-client:latest -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 oitc/modbus-client:latest -s ${modbusserver} -p 5020 -t 2 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm oitc/modbus-client:latest -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 oitc/modbus-client:latest -s ${modbusserver} -p 5020 -t 3 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm oitc/modbus-client:latest -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 oitc/modbus-client:latest -s ${modbusserver} -p 5020 -t 4 -r 0 -l 10" >> ${GITHUB_STEP_SUMMARY}
docker run --rm oitc/modbus-client:latest -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/[email protected]
with:
image_name: container-build:test
image_artifact_filename: container.tar
image_artifact_name: container-build
login_dockerhub: false
trivy_tag: latest