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

add fallback to git branch for invoke lock and Dockerfile poetry add #44

Merged
merged 3 commits into from
Sep 17, 2024
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
1 change: 1 addition & 0 deletions changes/44.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed build failing when `NAUTOBOT_VER` doesn't exist in PyPi, for example when using a branch name.
6 changes: 4 additions & 2 deletions development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ WORKDIR /source
COPY . /source

# Build args must be declared in each stage
ARG NAUTOBOT_VER
ARG PYTHON_VER

# Constrain the Nautobot version to NAUTOBOT_VER
# Constrain the Nautobot version to NAUTOBOT_VER, fall back to installing from git branch if not available on PyPi
# In CI, this should be done outside of the Dockerfile to prevent cross-compile build failures
ARG CI
RUN if [ -z "${CI+x}" ]; then \
INSTALLED_NAUTOBOT_VER=$(pip show nautobot | grep "^Version" | sed "s/Version: //"); \
poetry add --lock nautobot@${INSTALLED_NAUTOBOT_VER} --python ${PYTHON_VER}; fi
poetry add --lock nautobot@${INSTALLED_NAUTOBOT_VER} --python ${PYTHON_VER} || \
poetry add --lock git+https://github.com/nautobot/nautobot.git#${NAUTOBOT_VER} --python ${PYTHON_VER}; fi

# Install the app
RUN poetry install --extras all --with dev
Expand Down
1 change: 1 addition & 0 deletions nautobot_dev_example/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Meta:
model = models.DevExample
fields = "__all__"


class DevExampleBulkEditForm(TagsBulkEditFormMixin, NautobotBulkEditForm): # pylint: disable=too-many-ancestors
"""DevExample bulk edit form."""

Expand Down
12 changes: 10 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from time import sleep

from invoke.collection import Collection
from invoke.exceptions import Exit
from invoke.exceptions import Exit, UnexpectedExit
from invoke.tasks import task as invoke_task


Expand Down Expand Up @@ -249,9 +249,17 @@ def lock(context, check=False, constrain_nautobot_ver=False, constrain_python_ve
command = f"poetry add --lock nautobot@{docker_nautobot_version}"
if constrain_python_ver:
command += f" --python {context.nautobot_dev_example.python_ver}"
try:
run_command(context, command, hide=True)
except UnexpectedExit:
print("Unable to add Nautobot dependency with version constraint, falling back to git branch.")
command = f"poetry add --lock git+https://github.com/nautobot/nautobot.git#{context.nautobot_dev_example.nautobot_ver}"
if constrain_python_ver:
command += f" --python {context.nautobot_dev_example.python_ver}"
run_command(context, command)
else:
command = f"poetry {'check' if check else 'lock --no-update'}"
run_command(context, command)
run_command(context, command)


# ------------------------------------------------------------------------------
Expand Down