Skip to content

Commit ed3abb9

Browse files
committed
switch runner
create dind service for tls
1 parent 36aef66 commit ed3abb9

1 file changed

Lines changed: 76 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ on:
55

66
jobs:
77
build:
8-
runs-on: ubuntu-22.04
8+
runs-on: ubuntu-latest
99
services:
10-
docker:
10+
# Docker without TLS (plain TCP) !DEPRECATED! with next docker release
11+
docker-no-tls:
1112
image: docker:28.1-dind
1213
env:
1314
DOCKER_TLS_CERTDIR: ""
1415
ports:
1516
- 2375:2375
16-
volumes:
17-
- /var/run/docker.sock:/var/run/docker.sock
1817
options: >-
1918
--privileged
2019
--tmpfs /var/lib/docker
21-
--health-cmd "docker info || exit 1"
22-
--health-interval 10s
23-
--health-timeout 5s
24-
--health-retries 5
20+
21+
# Docker with TLS (secure TCP)
22+
docker-tls:
23+
image: docker:28.1-dind
24+
env:
25+
DOCKER_TLS_CERTDIR: /certs
26+
ports:
27+
- 2376:2376
28+
options: >-
29+
--privileged
30+
--tmpfs /var/lib/docker
31+
volumes:
32+
- /tmp/certs:/certs
33+
2534
strategy:
2635
matrix:
2736
framework:
@@ -31,11 +40,70 @@ jobs:
3140
- uses: actions/checkout@v4
3241
with:
3342
fetch-depth: 0
43+
3444
- name: Setup .NET Core
3545
uses: actions/setup-dotnet@v4
3646
with:
3747
dotnet-version: 9.x
3848
- name: Build
3949
run: dotnet build -c Release --framework ${{ matrix.framework }}
50+
51+
- name: Generate TLS certs for Docker
52+
run: |
53+
mkdir -p /tmp/certs
54+
55+
# Generate CA key and cert
56+
openssl genrsa -out /tmp/certs/ca-key.pem 2048
57+
openssl req -x509 -new -nodes -key /tmp/certs/ca-key.pem -sha256 -days 365 -out /tmp/certs/ca.pem -subj "/CN=docker-ca"
58+
59+
# Generate server key and CSR
60+
openssl genrsa -out /tmp/certs/server-key.pem 2048
61+
openssl req -new -key /tmp/certs/server-key.pem -out /tmp/certs/server.csr -subj "/CN=localhost"
62+
63+
# Sign server cert with CA
64+
openssl x509 -req -in /tmp/certs/server.csr -CA /tmp/certs/ca.pem -CAkey /tmp/certs/ca-key.pem -CAcreateserial -out /tmp/certs/server-cert.pem -days 365 -sha256
65+
66+
# Generate client key and CSR
67+
openssl genrsa -out /tmp/certs/key.pem 2048
68+
openssl req -new -key /tmp/certs/key.pem -out /tmp/certs/client.csr -subj "/CN=client"
69+
70+
# Sign client cert with CA
71+
openssl x509 -req -in /tmp/certs/client.csr -CA /tmp/certs/ca.pem -CAkey /tmp/certs/ca-key.pem -CAcreateserial -out /tmp/certs/cert.pem -days 365 -sha256
72+
73+
# Copy certs for Docker
74+
cp /tmp/certs/ca.pem /tmp/certs/server-cert.pem /tmp/certs/server-key.pem /tmp/certs/cert.pem /tmp/certs/key.pem /tmp/certs/
75+
76+
# Clean up
77+
rm /tmp/certs/*.csr /tmp/certs/ca-key.pem
78+
79+
- name: Wait for Docker (no TLS) to be healthy
80+
run: |
81+
for i in {1..10}; do
82+
if docker --host=tcp://localhost:2375 version; then
83+
echo "Docker (no TLS) is ready!"
84+
exit 0
85+
fi
86+
echo "Waiting for Docker (no TLS) to be ready..."
87+
sleep 3
88+
done
89+
echo "Docker (no TLS) did not become ready in time."
90+
exit 1
91+
92+
- name: Wait for Docker (with TLS) to be healthy
93+
run: |
94+
for i in {1..10}; do
95+
if docker --host=tcp://localhost:2376 --tlsverify \
96+
--tlscacert=/tmp/certs/ca.pem \
97+
--tlscert=/tmp/certs/cert.pem \
98+
--tlskey=/tmp/certs/key.pem version; then
99+
echo "Docker (TLS) is ready!"
100+
exit 0
101+
fi
102+
echo "Waiting for Docker (TLS) to be ready..."
103+
sleep 3
104+
done
105+
echo "Docker (TLS) did not become ready in time."
106+
exit 1
107+
40108
- name: Test
41109
run: dotnet test -c Release --framework ${{ matrix.framework }} --no-build --logger console

0 commit comments

Comments
 (0)