Skip to content

Commit

Permalink
ci: add testing via docker compose
Browse files Browse the repository at this point in the history
Auto testing as well as good example on:
how to run SWTPM in docker or compose.

Simply run `docker-compose up` to bring both swtpm and test.
Or run `docker-compose up --build --force-recreate` to re-build.
Or run `docker-compose up swtpm` to only start swtpm service without
test.

Added new job in the github action to automate this as well.

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Jul 18, 2024
1 parent bfeff99 commit 209ae43
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,32 @@ jobs:
platforms: linux/amd64,linux/arm/v7,linux/arm/v6
cache-from: type=gha
cache-to: type=gha,mode=max

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3.0.0
- name: Start containers
run: docker-compose up --build --force-recreate --detach
- name: Run Tests
run: |
set -x
docker-compose ps
name=$(docker-compose ps | grep swtpm-test | awk '{print $1}')
rc=$(docker wait "${name}")
if [ "${rc}" != "0" ]; then
echo "test failed:"
docker logs "${name}"
exit 1
fi
- name: Logs
if: always()
run: docker-compose logs

- name: Stop containers
if: always()
run: docker-compose down

37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: '3.7'

services:

swtpm:
build:
context: .
volumes:
- tpm-data:/swtpm
networks:
- swtpm
command: ['socket', '--tpm2',
'--server', 'type=unixio,path=/swtpm/swtpm.sock',
'--ctrl', 'type=unixio,path=/swtpm/swtpm.sock.ctrl',
'--tpmstate', 'dir=/swtpm',
'--log', 'file=swtpm.log',
'--log', 'level=20',
'--flags', 'not-need-init,startup-clear']

swtpm-test:
image: docker.io/strongx509/tpm:5.9.13
depends_on:
- swtpm
volumes:
- tpm-data:/swtpm
networks:
- swtpm
environment:
TPM2TOOLS_TCTI: swtpm:path=/swtpm/swtpm.sock
command: ['tpm2', 'clear']

volumes:
tpm-data:

networks:
swtpm:

0 comments on commit 209ae43

Please # to comment.