From a57f2aa21e8c76129626f85fe93965705f9e2d57 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 3 Apr 2023 19:30:24 +0800 Subject: [PATCH] :rocket: add docker test --- .github/actions/test-docker/action.yml | 19 +++++++++++++++++++ .github/actions/test-docker/test_docker.sh | 19 +++++++++++++++++++ .github/workflows/main.yml | 7 +++++++ 3 files changed, 45 insertions(+) create mode 100644 .github/actions/test-docker/action.yml create mode 100755 .github/actions/test-docker/test_docker.sh diff --git a/.github/actions/test-docker/action.yml b/.github/actions/test-docker/action.yml new file mode 100644 index 0000000..b582d26 --- /dev/null +++ b/.github/actions/test-docker/action.yml @@ -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 diff --git a/.github/actions/test-docker/test_docker.sh b/.github/actions/test-docker/test_docker.sh new file mode 100755 index 0000000..a5512e3 --- /dev/null +++ b/.github/actions/test-docker/test_docker.sh @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f8296c..706e9a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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