Skip to content

Commit

Permalink
Docker performance improvements and reduce image size (#1016)
Browse files Browse the repository at this point in the history
* refactor(makefile): ♻️ remove repetitive command

* chore(Dockerfile): Refactor Dockerfile to use multi-stage build
- Change base image from python:3.11-slim to python:3.11-alpine in the builder stage
- Use apk package manager instead of apt-get to install dependencies
- Remove unnecessary sudo command
- Use pip install --no-cache-dir instead of pip install
- Add second stage in Dockerfile for final image
- Copy dependencies and entrypoint script from builder stage to final stage

Signed-off-by: Plamen Ivanov <paco.iwanow@gmail.com>

* chore(entrypoint.sh): update shebang to use `/usr/bin/env sh`
- add coding utf-8 declaration
- use `find` command to patch permissions of generated files

Signed-off-by: Plamen Ivanov <paco.iwanow@gmail.com>

---------

Signed-off-by: Plamen Ivanov <paco.iwanow@gmail.com>
  • Loading branch information
k1lgor committed Mar 21, 2024
1 parent 164730a commit d5a73ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
22 changes: 16 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
FROM python:3.11-slim
# Stage 1: Builder stage
FROM python:3.11-alpine AS builder

RUN apt-get update \
&& apt-get install -y sudo tk tcl gcc curl
RUN apk update && apk add --no-cache tk tcl curl

WORKDIR /app

COPY . .
COPY docker/entrypoint.sh ./entrypoint.sh

RUN sudo pip install -e .
RUN pip install --no-cache-dir -e .

ENTRYPOINT ["bash", "/app/entrypoint.sh"]
# Stage 2: Final stage
FROM python:3.11-alpine

WORKDIR /app

COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /app .

COPY docker/entrypoint.sh .

ENTRYPOINT ["sh", "/app/entrypoint.sh"]
11 changes: 4 additions & 7 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash
#!/usr/bin/env sh
# -*- coding: utf-8 -*-

project_dir="/project"

# Run the gpt engineer script
gpt-engineer $project_dir "$@"

# Patch the permissions of the generated files to be owned by nobody except prompt file
for item in "$project_dir"/*; do
if [[ "$item" != "$project_dir/prompt" ]]; then
chown -R nobody:nogroup "$item"
chmod -R 777 "$item"
fi
done
find "$project_dir" -mindepth 1 -maxdepth 1 ! -path "$project_dir/prompt" -exec chown -R nobody:nogroup {} + -exec chmod -R 777 {} +

0 comments on commit d5a73ab

Please sign in to comment.