From 47176b672419e6b195ac5ba4d8dc239139633aab Mon Sep 17 00:00:00 2001 From: NeverBehave Date: Fri, 13 Aug 2021 21:22:32 -0700 Subject: [PATCH] chore(test): test running docker after build (#8010) * chore(test): test running docker after build * add test in the same step * add count times * workflow typo * add name when output * if then * test docker * use id * no tag * what is docker id * load single platform * do not test multi-arch for now * no load --- .github/workflows/docker-test.yml | 28 ++++++++++------------------ package.json | 3 ++- scripts/docker/test-docker.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100755 scripts/docker/test-docker.sh diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index 58d45cae9e..52aa9a9af9 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -7,29 +7,21 @@ on: - 'lib/**' - 'Dockerfile' - 'package.json' - push: - branches: '*' - paths: - - '.github/workflows/**' - - 'lib/**' - - 'Dockerfile' - - 'package.json' - + # Please, always create a pull request instead of push to master. jobs: test: runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - - name: Build dockerfile (without push) - run: | - docker buildx build \ - --platform=linux/amd64,linux/arm/v7,linux/arm64 \ - --output "type=image,push=false" \ - --file ./Dockerfile . + - name: Build dockerfile and Run (without push) + run: | + docker build \ + --tag rsshub:latest \ + --file ./Dockerfile . + chmod +x scripts/docker/test-docker.sh + scripts/docker/test-docker.sh \ No newline at end of file diff --git a/package.json b/package.json index 612218a6fb..08ddc0d534 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ "string-width": "4.2.2", "supertest": "6.1.3", "vuepress": "1.8.2", - "yorkie": "2.0.0" + "yorkie": "2.0.0", + "fs-extra": "^8.1.0" }, "dependencies": { "@koa/router": "10.0.0", diff --git a/scripts/docker/test-docker.sh b/scripts/docker/test-docker.sh new file mode 100755 index 0000000000..ad9b009263 --- /dev/null +++ b/scripts/docker/test-docker.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +MAX_RETRIES=60 +# Try running the docker and get the output +# then try getting homepage in 3 mins + +docker run -d -p 1200:1200 rsshub:latest + +if [[ $? -ne 0 ]] +then + echo "failed to run docker" + exit 1 +fi + +RETRY=1 +curl -m 10 localhost:1200 +while [[ $? -ne 0 ]] && [[ $RETRY -lt $MAX_RETRIES ]]; do + sleep 5 + ((RETRY++)) + echo "RETRY: ${RETRY}" + curl -m 10 localhost:1200 +done + +if [[ $RETRY -gt $MAX_RETRIES ]] +then + echo "Unable to run, aborted" + exit 1 +else + echo "Successfully acquire homepage, passing" + exit 0 +fi \ No newline at end of file