Reduce Docker image size 80% via pyinstaller (#1)

* FROM scratch - initial commit

* Switch to debian + ADD middle-ground
This commit is contained in:
askiiart 2023-09-06 14:59:21 -05:00 committed by GitHub
parent 44da56ddaa
commit f82aa8b4bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 13 deletions

View file

@ -2,11 +2,15 @@ kind: pipeline
name: default name: default
steps: steps:
- name: Remove extra stuff to make Docker images lighter - name: Make semi-static build with pyinstaller (NOT actually static)
image: alpine:latest image: python:latest
commands: commands:
- apk add git - apt-get update
- cd /drone/src && git apply docker.patch - apt-get install binutils -y
- pip install pyinstaller
- cd /drone/src && pip install -r requirements.txt && pyinstaller main.py
- chmod 777 /repo/dist/main/main
- cd /drone/src/dist/main && tar cvfz /drone/src/AlwaysDungeons.tar.gz *
- name: build and publish - name: build and publish
image: plugins/docker image: plugins/docker
pull: always pull: always

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
dist/
build/
.env
*.spec
AlwaysDungeons.tar.gz

View file

@ -1,6 +1,4 @@
FROM python:latest FROM python:slim-bookworm
WORKDIR /data WORKDIR /data
COPY ./requirements.txt /data/ ADD AlwaysDungeons.tar.gz /data
RUN pip3 install -r /data/requirements.txt CMD ["/data/main"]
COPY ./*.py /data/
CMD python3 main.py

View file

@ -2,11 +2,13 @@
set -e set -e
ORG="askiiart" ORG="askiiart"
NAME="discord-always-dungeons" NAME="discord-always-dungeons"
ID=$(docker build . -q)
# Apply patch for Docker # Apply patch for Docker
git apply docker.patch docker run -v .:/repo python /bin/sh -c "cd /repo && pip install -r requirements.txt && apt-get update && apt-get install binutils -y && pip install pyinstaller && pyinstaller main.py && cd /repo/dist/main && chmod -R 777 /repo/dist/main && tar cvfz /repo/AlwaysDungeons.tar.gz *"
# Build image
#ID=$(docker build . -q)
# Could just do -t on the build, but this makes it easier to expand if needed. # Could just do -t on the build, but this makes it easier to expand if needed.
docker tag ${ID} ${ORG}/${NAME}:latest #docker tag ${ID} ${ORG}/${NAME}:latest
docker push ${ORG}/${NAME}:latest #docker push ${ORG}/${NAME}:latest