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

Astro CLI injects docker commands making docker cache unusable #1457

Open
ivanstillfront opened this issue Nov 21, 2023 · 0 comments
Open

Astro CLI injects docker commands making docker cache unusable #1457

ivanstillfront opened this issue Nov 21, 2023 · 0 comments

Comments

@ivanstillfront
Copy link

Describe the bug

When running a command, for example astro dev pytest the astro cli invokes a docker build command using the project's Dockerfile as a base.

To speed up these commands, we install dbt into its own stage. Our Dockerfile looks like this:

FROM quay.io/astronomer/astro-runtime:9.5.0 as dbt_build

ADD ./dbt_requirements.txt ./dbt_requirements.txt

RUN python -m venv --copies dbt_venv && source dbt_venv/bin/activate && \
    pip install --no-cache-dir -r dbt_requirements.txt && deactivate


FROM quay.io/astronomer/astro-runtime:9.5.0

COPY --chown=astro:0 --from=dbt_build /usr/local/airflow/dbt_venv dbt_venv

COPY --chown=astro:0 docker/aws_config /home/astro/.aws/config

ENV PATH="${AIRFLOW_HOME}/dbt_venv/bin:${PATH}"

dbt_requirements.txt contents is:

dbt-snowflake==1.6.4

The cli injects docker commands after each FROM quay.io/astronomer/astro-runtime:9.5.0 call, looking at the logs they are:

COPY packages.txt .
RUN if [[ -s packages.txt ]]; then     apt-get update && cat packages.txt | tr '\r\n' '\n' | sed -e 's/#.*//' | xargs apt-get install -y --no-install-recommends     && apt-get clean     && rm -rf /var/lib/apt/lists/*;   fi

COPY requirements.txt .
RUN if grep -Eqx 'apache-airflow\s*[=~>]{1,2}.*' requirements.txt; then     echo >&2 "Do not upgrade by specifying 'apache-airflow' in your requirements.txt, change the base image instead!";  exit 1;   fi;   pip install --no-cache-dir --root-user-action=ignore -r requirements.txt

COPY --chown=astro:0 . .

The last command COPY --chown=astro:0 . . is really slowing down any astro dev command because it causes the dbt_build stage venv creation step cache to invalidate if any file in the project folder changes.

This could be resolved by omitting the final COPY --chown=astro:0 . . command from build stages that are not part of the final build image.

What CLI Version did you experience this bug?

Astro CLI Version: 1.19.1

This CLI bug is related to which Astronomer Platform?

  • [ x ] Astro
  • [ x ] Software
  • [ x ] None/Unknown

What Operating System is the above CLI installed on?

MacOs & Linux

🪜 Steps To Reproduce

  1. Use the Dockerfile pasted above
  2. Run astro dev pytest
  3. Run astro dev pytest again, observe building the Docker container build is fully cached
  4. Change any file except dbt_requirements.txt, requirements.txt and packages.txt, observe the Docker container build cache is invalidated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant