Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZEA-4475: Python: Do not cache dependency installation layer #411

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions internal/python/__snapshots__/plan_test.snap
Original file line number Diff line number Diff line change
@@ -1,204 +1,172 @@

[TestDetermineInstallCmd_Snapshot/pdm-none - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-fastapi - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm add uvicorn
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-static-django - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm add gunicorn
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-static-nginx - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm add gunicorn
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-static-nginx-django - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm add gunicorn
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-streamlit-entry - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-tornado - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pdm-with-wsgi - 1]
RUN pip install pdm
COPY pyproject.toml* pdm.lock* ./
RUN pdm add gunicorn
RUN pdm install
---

[TestDetermineInstallCmd_Snapshot/pip-none - 1]
COPY requirements.txt* ./
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-fastapi - 1]
COPY requirements.txt* ./
RUN pip install uvicorn
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-static-django - 1]
COPY requirements.txt* ./
RUN pip install gunicorn
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-static-nginx - 1]
COPY requirements.txt* ./
RUN pip install gunicorn
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-static-nginx-django - 1]
COPY requirements.txt* ./
RUN pip install gunicorn
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-streamlit-entry - 1]
COPY requirements.txt* ./
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-tornado - 1]
COPY requirements.txt* ./
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pip-with-wsgi - 1]
COPY requirements.txt* ./
RUN pip install gunicorn
RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin
---

[TestDetermineInstallCmd_Snapshot/pipenv-none - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-fastapi - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install uvicorn
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-static-django - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install gunicorn
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-static-nginx - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install gunicorn
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-static-nginx-django - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install gunicorn
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-streamlit-entry - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-tornado - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/pipenv-with-wsgi - 1]
RUN pip install pipenv
COPY Pipfile* Pipfile.lock* ./
RUN pipenv install gunicorn
RUN pipenv install
---

[TestDetermineInstallCmd_Snapshot/poetry-none - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-fastapi - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry add uvicorn
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-static-django - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry add gunicorn
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-static-nginx - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry add gunicorn
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-static-nginx-django - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry add gunicorn
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-streamlit-entry - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-tornado - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry install
---

[TestDetermineInstallCmd_Snapshot/poetry-with-wsgi - 1]
RUN pip install poetry
COPY pyproject.toml* poetry.lock* ./
RUN poetry add gunicorn
RUN poetry install
---
Expand Down
13 changes: 0 additions & 13 deletions internal/python/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,22 +510,9 @@ func determineInstallCmd(ctx *pythonPlanContext) string {
}
}

var filesToCopy []string
if decl := getPmDeclarationFile(pm); decl != "" {
filesToCopy = append(filesToCopy, decl+"*")
}
if lock := getPmLockFile(pm); len(lock) > 0 {
for _, f := range lock {
filesToCopy = append(filesToCopy, f+"*")
}
}

if cmd := getPmInitCmd(pm); cmd != "" {
commands = append(commands, "RUN "+cmd)
}
if len(filesToCopy) > 0 {
commands = append(commands, fmt.Sprintf("COPY %s ./", strings.Join(filesToCopy, " ")))
}
if cmd := getPmAddCmd(pm, depToInstall...); cmd != "" {
commands = append(commands, "RUN "+cmd)
}
Expand Down
6 changes: 2 additions & 4 deletions internal/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ CMD ` + startCmd, nil
if serverless == "true" {
return `FROM docker.io/library/python:` + pyVer + `-slim AS builder
WORKDIR /app
` + installCmd + `
COPY . .
` + installCmd + `
` + buildCmd + `

FROM scratch AS output
Expand Down Expand Up @@ -88,9 +88,7 @@ server { \
}"> /etc/nginx/conf.d/default.conf` + "\n"
}

dockerfile += installCmd + `
COPY . .
` + buildCmd + `
dockerfile += "COPY . .\n" + installCmd + "\n" + buildCmd + `
EXPOSE 8080
CMD ["/bin/bash", "-c", ` + strconv.Quote(startCmd) + `]`

Expand Down
4 changes: 2 additions & 2 deletions tests/real_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ var projects = []struct {
/* static */
{
name: "static-html",
owner: "pan93412",
repo: "homepage-plain",
owner: "schoolofdevops",
repo: "html-sample-app",
},
{
name: "static-mkdocs",
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/python-django-static-whitenoise.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt\nRUN python manage.py collectstatic --noinput"
framework: "django"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { gunicorn --bind :8080 core.wsgi; }; _startup"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/python-django-static.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang nginx"
build: "RUN pip install -r requirements.txt\nRUN python manage.py collectstatic --noinput"
framework: "django"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { /usr/sbin/nginx && gunicorn --bind :8000 core.wsgi; }; _startup"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/python-django.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "django"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { gunicorn --bind :8080 mysite.wsgi; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-fastapi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "fastapi"
install: "COPY requirements.txt* ./\nRUN pip install uvicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install uvicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { uvicorn main:app --host 0.0.0.0 --port 8080; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-flask-mysql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "flask"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { gunicorn --bind :8080 app:app; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-flask-static.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "flask"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { gunicorn --bind :8080 main:app; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-flask.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "flask"
install: "COPY requirements.txt* ./\nRUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN pip install gunicorn\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { gunicorn --bind :8080 app:app; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-hnswlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PlanType: python
Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
install: "COPY requirements.txt* ./\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { python app.py; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-streamlit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
framework: "streamlit"
install: "COPY requirements.txt* ./\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { streamlit run streamlit_app.py --server.port=8080 --server.address=0.0.0.0; }; _startup"
2 changes: 1 addition & 1 deletion tests/snapshots/python-zba651.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PlanType: python
Meta:
apt-deps: "build-essential pkg-config clang"
build: "RUN pip install -r requirements.txt"
install: "COPY requirements.txt* ./\nRUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
install: "RUN sed '/-e/d' requirements.txt | pip install -r /dev/stdin"
packageManager: "pip"
pythonVersion: "3.10"
start: "_startup() { python main.py; }; _startup"
Loading