From 453b2265b6342c6cafc3574f0e87c86aead93798 Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 14 Oct 2021 18:13:57 +0800 Subject: [PATCH] test: docker --- .github/workflows/docker-test.yml | 50 +++++++++++++++++++++++++++++++ .gitignore | 3 ++ scripts/workflow/test-docker.sh | 46 ++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .github/workflows/docker-test.yml create mode 100644 scripts/workflow/test-docker.sh diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml new file mode 100644 index 00000000..fb822a38 --- /dev/null +++ b/.github/workflows/docker-test.yml @@ -0,0 +1,50 @@ +name: Docker Build + +on: + push: + branches: + - master + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + innei/mx-server + # generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and export to Docker + uses: docker/build-push-action@v2 + with: + context: . + load: true + tags: ${{ env.TEST_TAG }} + - name: Test + run: | + sh ./scripts/workflow/test-docker.sh + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }},innei/mx-server:latest + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index aa5fb9a6..678a8af9 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ run data assets .env + +scripts/workflow/docker-compose.yml +scripts/workflow/data diff --git a/scripts/workflow/test-docker.sh b/scripts/workflow/test-docker.sh new file mode 100644 index 00000000..54a01b4a --- /dev/null +++ b/scripts/workflow/test-docker.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +MAX_RETRIES=60 +# Try running the docker and get the output +# then try getting homepage in 3 mins + +docker -v + +if [[ $? -ne 0 ]]; then + echo "failed to run docker" + exit 1 +fi + +docker-compose -v + +if [[ $? -ne 0 ]]; then + echo "failed to run docker-compose" + exit 1 +fi + +curl https://cdn.jsdelivr.net/gh/mx-space/server-next@master/docker-compose.yml >docker-compose.yml + +docker-compose up -d + +if [[ $? -ne 0 ]]; then + echo "failed to run docker-compose instance" + exit 1 +fi + +RETRY=3 +curl -m 10 localhost:2333/api/v2 + +while [[ $? -ne 0 ]] && [[ $RETRY -lt $MAX_RETRIES ]]; do + sleep 5 + ((RETRY++)) + echo "RETRY: ${RETRY}" + curl -m 10 localhost:2333/api/v2 +done + +if [[ $RETRY -gt $MAX_RETRIES ]]; then + echo "Unable to run, aborted" + exit 1 +else + echo -e "\nSuccessfully acquire homepage, passing" + exit 0 +fi