🚀 add docker test

This commit is contained in:
felinae98
2023-04-03 19:30:24 +08:00
parent 46cc7c7fc4
commit a57f2aa21e
3 changed files with 45 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
name: Test Docker Image
description: Test the given docker image can run
inputs:
docker-image-name:
description: which docker image to test
required: true
wait-time:
description: how many seconds to wait for
required: true
default: '5'
runs:
using: composite
steps:
- name: run test
run: |
${{ github.action_path }}/test_docker.sh ${{ inputs.docker-image-name}} ${{ inputs.wait-time }}
shell: bash
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
DOCKER_IMAGE=$1
WAIT_TIME=$2
docker run --name test-docker-container -d $DOCKER_IMAGE > /dev/null
sleep $WAIT_TIME
CONTAINER_STATE=$(docker ps -f name=test-docker-container -a --format '{{.State}}')
if [[ $CONTAINER_STATE = "running" ]]; then
echo "container still running, check passed"
docker rm -f test-docker-container > /dev/null
exit
else
echo "container exited"
docker logs test-docker-container
docker rm test-docker-container > /dev/null
exit 1
fi