mirror of
https://github.com/aimingmed/aimingmed-ai.git
synced 2026-01-19 21:37:31 +08:00
136 lines
4.2 KiB
YAML
136 lines
4.2 KiB
YAML
name: CI/CD - develop
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- develop
|
|
|
|
env:
|
|
IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')/aimingmed-ai-backend
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Docker Image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Check disk space
|
|
run: df -h
|
|
- name: Cleanup Docker resources
|
|
if: always()
|
|
run: |
|
|
docker system prune -a -f --volumes
|
|
- name: Remove unnecessary files
|
|
run: |
|
|
sudo rm -rf /usr/share/dotnet
|
|
sudo rm -rf /opt/ghc
|
|
sudo rm -rf "/usr/local/share/boost"
|
|
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
|
- name: Check disk space
|
|
run: df -h
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: develop
|
|
- name: Log in to GitHub Packages
|
|
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Pull image
|
|
run: |
|
|
docker pull ${{ env.IMAGE }}:latest || true
|
|
- name: Check disk space
|
|
if: always()
|
|
run: df -h
|
|
- name: Build image
|
|
run: |
|
|
docker build \
|
|
--cache-from ${{ env.IMAGE }}:latest \
|
|
--tag ${{ env.IMAGE }}:latest \
|
|
--file ./app/backend/Dockerfile.prod \
|
|
"./app/backend"
|
|
- name: Push image
|
|
run: |
|
|
docker push ${{ env.IMAGE }}:latest
|
|
- name: Check disk space
|
|
if: always()
|
|
run: df -h
|
|
- name: Cleanup Docker resources
|
|
if: always()
|
|
run: docker system prune -a -f --volumes
|
|
- name: Check disk space
|
|
if: always()
|
|
run: df -h
|
|
|
|
test:
|
|
name: Test Docker Image
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
steps:
|
|
- name: Check disk space
|
|
run: df -h
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: develop
|
|
- name: Log in to GitHub Packages
|
|
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Cleanup Docker resources
|
|
if: always()
|
|
run: docker system prune -a -f --volumes
|
|
- name: Remove unnecessary files
|
|
run: |
|
|
sudo rm -rf /usr/share/dotnet
|
|
sudo rm -rf /opt/ghc
|
|
sudo rm -rf "/usr/local/share/boost"
|
|
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
|
- name: Pull image
|
|
run: |
|
|
docker pull ${{ env.IMAGE }}:latest || true
|
|
- name: Check disk space
|
|
if: always()
|
|
run: df -h
|
|
- name: Build image
|
|
run: |
|
|
docker build \
|
|
--cache-from ${{ env.IMAGE }}:latest \
|
|
--tag ${{ env.IMAGE }}:latest \
|
|
--file ./app/backend/Dockerfile.prod \
|
|
"./app/backend"
|
|
- name: Check disk space
|
|
if: always()
|
|
run: df -h
|
|
- name: Run container
|
|
run: |
|
|
docker run \
|
|
-d \
|
|
--name backend-backend \
|
|
-e PORT=8765 \
|
|
-e ENVIRONMENT=dev \
|
|
-e TESTING=0 \
|
|
-p 8004:8765 \
|
|
${{ env.IMAGE }}:latest
|
|
- name: Monitor memory usage
|
|
run: free -h
|
|
# - name: Run Pytest directly
|
|
# run: |
|
|
# # install python 3.11 and pip3
|
|
# sudo apt-get update
|
|
# sudo apt-get install -y python3.11 python3.11-distutils
|
|
# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && cd ./app/backend/ && pipenv install && pipenv run python -m pytest --disable-warnings
|
|
# - name: Pytest
|
|
# run: docker exec backend-backend pipenv run python -m pytest -v
|
|
# - name: Flake8
|
|
# run: docker exec backend-backend pipenv run python -m flake8 .
|
|
# - name: Black
|
|
# run: docker exec backend-backend pipenv run python -m black . --check
|
|
- name: isort
|
|
run: docker exec backend-backend pipenv run python -m isort . --check-only
|
|
- name: Cleanup container at end of job
|
|
if: always()
|
|
run: docker stop backend-backend || true && docker rm backend-backend || true
|