🚀 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
.github/actions/test-docker/action.yml vendored Normal file
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
.github/actions/test-docker/test_docker.sh vendored Executable file
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

View File

@ -142,10 +142,17 @@ jobs:
context: .
file: ./docker/Dockerfile_with_frontend
push: false
load: true
tags: felinae98/nonebot-bison:dummy
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test image
uses: ./.github/actions/test-docker
with:
docker-image-name: felinae98/nonebot-bison:dummy
wait-time: 10
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1