Reduce Docker image size 80% via pyinstaller (#1)
* FROM scratch - initial commit * Switch to debian + ADD middle-ground
This commit is contained in:
parent
44da56ddaa
commit
f82aa8b4bb
4 changed files with 22 additions and 13 deletions
12
.drone.yml
12
.drone.yml
|
@ -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
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
dist/
|
||||
build/
|
||||
.env
|
||||
*.spec
|
||||
AlwaysDungeons.tar.gz
|
|
@ -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"]
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue