remove unnecessary packages

This commit is contained in:
leehk 2025-04-13 07:24:00 +08:00
parent faca3d23bb
commit e880d71960
2 changed files with 31 additions and 15 deletions

View File

@ -16,9 +16,17 @@ jobs:
contents: read contents: read
packages: write packages: write
steps: steps:
- name: Check disk space
run: df -h
- name: Cleanup Docker resources - name: Cleanup Docker resources
if: always() 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 - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
@ -30,6 +38,8 @@ jobs:
- name: Pull image - name: Pull image
run: | run: |
docker pull ${{ env.IMAGE }}:latest || true docker pull ${{ env.IMAGE }}:latest || true
- name: Check disk space
run: df -h
- name: Build image - name: Build image
run: | run: |
docker build \ docker build \
@ -49,6 +59,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build needs: build
steps: steps:
- name: Check disk space
run: df -h
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
@ -57,9 +69,14 @@ jobs:
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cleanup Docker resources
if: always()
run: docker system prune -a -f --volumes
- name: Pull image - name: Pull image
run: | run: |
docker pull ${{ env.IMAGE }}:latest || true docker pull ${{ env.IMAGE }}:latest || true
- name: Check disk space
run: df -h
- name: Build image - name: Build image
run: | run: |
docker build \ docker build \
@ -67,15 +84,11 @@ jobs:
--tag ${{ env.IMAGE }}:latest \ --tag ${{ env.IMAGE }}:latest \
--file ./app/backend/Dockerfile.prod \ --file ./app/backend/Dockerfile.prod \
"./app/backend" "./app/backend"
- name: Cleanup Docker resources
if: always()
run: docker system prune -a -f --volumes
- name: Run container - name: Run container
run: | run: |
docker run \ docker run \
-d \ -d \
--name backend \ --name backend \
--memory 8g \
-e PORT=8765 \ -e PORT=8765 \
-e ENVIRONMENT=dev \ -e ENVIRONMENT=dev \
-e TESTING=0 \ -e TESTING=0 \

View File

@ -3,7 +3,7 @@
########### ###########
# pull official base image # pull official base image
FROM python:3.11-slim as builder FROM python:3.11-alpine as builder
# set working directory # set working directory
@ -15,12 +15,14 @@ ENV PYTHONUNBUFFERED=1
# install system dependencies # install system dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get -y install build-essential netcat-traditional gcc \ && apt-get -y install build-essential \
&& apt-get clean && apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# install python dependencies # install python dependencies
RUN pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple 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 RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip
COPY ./Pipfile . COPY ./Pipfile .
RUN pipenv install --deploy --dev 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 # pull official base image
FROM python:3.11-slim FROM python:3.11-alpine
# create directory for the app user # create directory for the app user
RUN mkdir -p /home/app RUN mkdir -p /home/app
@ -59,13 +61,14 @@ ENV TESTING=0
# install system dependencies # install system dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get -y install build-essential netcat-traditional gcc \ && apt-get -y install build-essential \
&& apt-get clean && apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# install python dependencies # install python dependencies
COPY --from=builder /usr/src/app/Pipfile . 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 --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 RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip
RUN pipenv install --deploy --dev RUN pipenv install --deploy --dev
RUN pipenv run pip install "uvicorn[standard]==0.26.0" RUN pipenv run pip install "uvicorn[standard]==0.26.0"