From e880d7196017027bc8ae8f604311c867d72834ab Mon Sep 17 00:00:00 2001 From: leehk Date: Sun, 13 Apr 2025 07:24:00 +0800 Subject: [PATCH] remove unnecessary packages --- .github/workflows/develop.yml | 23 ++++++++++++++++++----- app/backend/Dockerfile.prod | 23 +++++++++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 991a12d..c10a006 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -16,9 +16,17 @@ jobs: 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 + run: | + docker system prune -a -f --volumes + docker volume rm $(docker volume ls -qf dangling=true) || true + docker rmi $(docker images -f "dangling=true" -q) || true + docker container prune -f + - name: Check disk space + run: df -h - name: Checkout uses: actions/checkout@v3 with: @@ -30,6 +38,8 @@ jobs: - name: Pull image run: | docker pull ${{ env.IMAGE }}:latest || true + - name: Check disk space + run: df -h - name: Build image run: | docker build \ @@ -49,6 +59,8 @@ jobs: runs-on: ubuntu-latest needs: build steps: + - name: Check disk space + run: df -h - name: Checkout uses: actions/checkout@v3 with: @@ -57,9 +69,14 @@ jobs: 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: Pull image run: | docker pull ${{ env.IMAGE }}:latest || true + - name: Check disk space + run: df -h - name: Build image run: | docker build \ @@ -67,15 +84,11 @@ jobs: --tag ${{ env.IMAGE }}:latest \ --file ./app/backend/Dockerfile.prod \ "./app/backend" - - name: Cleanup Docker resources - if: always() - run: docker system prune -a -f --volumes - name: Run container run: | docker run \ -d \ --name backend \ - --memory 8g \ -e PORT=8765 \ -e ENVIRONMENT=dev \ -e TESTING=0 \ diff --git a/app/backend/Dockerfile.prod b/app/backend/Dockerfile.prod index 8f70f74..e60cad7 100644 --- a/app/backend/Dockerfile.prod +++ b/app/backend/Dockerfile.prod @@ -3,7 +3,7 @@ ########### # pull official base image -FROM python:3.11-slim as builder +FROM python:3.11-alpine as builder # set working directory @@ -15,12 +15,14 @@ ENV PYTHONUNBUFFERED=1 # install system dependencies RUN apt-get update \ - && apt-get -y install build-essential netcat-traditional gcc \ - && apt-get clean + && apt-get -y install build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + # install python dependencies -RUN pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple -RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv +RUN pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple && rm -rf ~/.cache/pip +RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip COPY ./Pipfile . RUN pipenv install --deploy --dev @@ -36,7 +38,7 @@ RUN pipenv run pip install black==23.12.1 flake8==7.0.0 isort==5.13.2 ######### # pull official base image -FROM python:3.11-slim +FROM python:3.11-alpine # create directory for the app user RUN mkdir -p /home/app @@ -59,13 +61,14 @@ ENV TESTING=0 # install system dependencies RUN apt-get update \ - && apt-get -y install build-essential netcat-traditional gcc \ - && apt-get clean + && apt-get -y install build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* # install python dependencies COPY --from=builder /usr/src/app/Pipfile . -RUN pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple -RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv +RUN pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple && rm -rf ~/.cache/pip +RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip RUN pipenv install --deploy --dev RUN pipenv run pip install "uvicorn[standard]==0.26.0"