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
steps:
- name: Remove extra stuff to make Docker images lighter
image: alpine:latest
- name: Make semi-static build with pyinstaller (NOT actually static)
image: python:latest
commands:
- apk add git
- cd /drone/src && git apply docker.patch
- apt-get update
- 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
image: plugins/docker
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
COPY ./requirements.txt /data/
RUN pip3 install -r /data/requirements.txt
COPY ./*.py /data/
CMD python3 main.py
ADD AlwaysDungeons.tar.gz /data
CMD ["/data/main"]

View file

@ -2,11 +2,13 @@
set -e
ORG="askiiart"
NAME="discord-always-dungeons"
ID=$(docker build . -q)
# 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.
docker tag ${ID} ${ORG}/${NAME}:latest
docker push ${ORG}/${NAME}:latest
#docker tag ${ID} ${ORG}/${NAME}:latest
#docker push ${ORG}/${NAME}:latest