Skip to content

Commit

Permalink
ci: optimized workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Oct 16, 2024
1 parent eb56598 commit 247ce3c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 205 deletions.
197 changes: 0 additions & 197 deletions .github/workflows/docker-crawlab-tencent.yml

This file was deleted.

76 changes: 68 additions & 8 deletions .github/workflows/docker-crawlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
IMAGE_NAME_CRAWLAB: crawlabteam/crawlab
IMAGE_NAME_CRAWLAB_BACKEND: crawlabteam/crawlab-backend
IMAGE_NAME_CRAWLAB_FRONTEND: crawlabteam/crawlab-frontend
IMAGE_NAME_CRAWLAB_TENCENT: ccr.ccs.tencentyun.com/crawlabteam/crawlab

jobs:
setup:
Expand Down Expand Up @@ -131,6 +132,8 @@ jobs:
if: ${{ always() }}
needs: [ setup, build-backend, build-frontend ]
runs-on: ubuntu-latest
outputs:
test_passed: ${{ steps.build_and_test.outputs.test_passed }}
services:
mongo:
image: mongo:4.2
Expand Down Expand Up @@ -179,19 +182,76 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
python-version: '3.12'

- name: Test demo
run: |
pip install crawlab-demo
crawlab-demo validate

- name: Log into registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Push image
- name: Build and test image
id: build_and_test
run: |
# Update Dockerfile
IMAGE_VERSION=${{needs.setup.outputs.version}}
IMAGE_ID=$IMAGE_NAME_CRAWLAB
docker tag image $IMAGE_ID:$IMAGE_VERSION
docker push $IMAGE_ID:$IMAGE_VERSION
if [[ $IMAGE_VERSION != "latest" ]]; then
for n in crawlab-backend crawlab-frontend; do
IMAGE_NAME=$n
sed -i "s/${IMAGE_NAME}:latest/${IMAGE_NAME}:${IMAGE_VERSION}/" Dockerfile
done
fi

# Build image
docker build . --file Dockerfile --tag image

# Test image
docker run --rm -d --name crawlab_master \
-e CRAWLAB_NODE_MASTER=true \
-e CRAWLAB_DEMO=true \
-e CRAWLAB_MONGO_HOST=localhost \
-e CRAWLAB_MONGO_PORT=27017 \
-p 8080:8080 \
--network host \
image
docker exec crawlab_master env
docker logs -f crawlab_master &
sleep 10
docker ps
cmd='curl http://localhost:8080/api/system-info -s'
echo "cmd: ${cmd}"
res=`${cmd}`
echo "res: ${res}"
if [[ $res =~ "success" ]]; then
echo "test_passed=true" >> $GITHUB_OUTPUT
else
echo "test_passed=false" >> $GITHUB_OUTPUT
exit 1
fi
docker stop crawlab_master

push-images:
needs: [setup, build-crawlab]
if: needs.build-crawlab.outputs.test_passed == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
registry: [dockerhub, tencent]
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ (matrix.registry == 'dockerhub' && secrets.DOCKER_USERNAME) || (matrix.registry == 'tencent' && secrets.DOCKER_TENCENT_USERNAME) }}
password: ${{ (matrix.registry == 'dockerhub' && secrets.DOCKER_PASSWORD) || (matrix.registry == 'tencent' && secrets.DOCKER_TENCENT_PASSWORD) }}

- name: Push to DockerHub
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ (matrix.registry == 'dockerhub' && env.IMAGE_NAME_CRAWLAB) || (matrix.registry == 'tencent' && env.IMAGE_NAME_CRAWLAB_TENCENT) }}:${{ needs.setup.outputs.version }}

0 comments on commit 247ce3c

Please sign in to comment.