Skip to content

Commit

Permalink
chore: move sync-nb-server-to-ironic into python package
Browse files Browse the repository at this point in the history
Moved the sync-nb-server-to-ironic code into the our workflows python
package. This required fixing up some places to craft the necessary
entry points as well as setting dependencies. Removed the building of
the container for the old directory and create a new container with
these pieces.
  • Loading branch information
cardoe committed Jul 29, 2024
1 parent 4254564 commit 21f445e
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 289 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/build-container-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ on:
env:
VERSION_PYTHON311: 0.0.1
VERSION_PYTHON312: 0.0.1
VERSION_PYTHON_IRONIC: 0.0.4
VERSION_ARGO_UTILS: 0.0.1
VERSION_OBM_UTILS: 0.0.1
VERSION_PYTHON_NAUTOBOT_INT_SYNC: 0.0.1
Expand Down Expand Up @@ -67,17 +66,6 @@ jobs:
labels: |
org.opencontainers.image.version=${{ env.VERSION_PYTHON312 }}
- name: Build and deploy Python 3.11 with Ironic client
uses: docker/build-push-action@v5
with:
context: argo-workflows/sync-nb-server-to-ironic
file: argo-workflows/sync-nb-server-to-ironic/containers/Dockerfile.ironic
# push for all main branch commits
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:latest,ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:${{ env.VERSION_PYTHON_IRONIC }}
labels: |
org.opencontainers.image.version=${{ env.VERSION_PYTHON_IRONIC }}
- name: Build and deploy Argo Utils image
uses: docker/build-push-action@v5
with:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,50 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

workflows:
runs-on: ubuntu-latest

strategy:
matrix:
container:
- name: ironic-nautobot-client
title: Understack Ironic Nautobot Clients

steps:
- name: setup docker buildx
uses: docker/setup-buildx-action@v3
- name: login to ghcr.io
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/rackerlabs/understack/${{ matrix.container.name }}
labels: |
org.opencontainers.image.title=${{ matrix.container.title }}
env:
# Create the annotations at the index as well since this
# defaults to manifest only and we have to manually merge
# the container is multi-arch because of provenance creating
# an 'unknown/unknown' arch with data. We've got no annotations
# that are arch specific so populate them at the index as well.
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index

- name: build and deploy container image to registry
uses: docker/build-push-action@v5
with:
file: containers/Dockerfile.${{ matrix.container.name }}
pull: true # ensure we always have an up to date source
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
# prod is the target that has the code installed
target: prod

This file was deleted.

100 changes: 0 additions & 100 deletions argo-workflows/sync-nb-server-to-ironic/code/synchronize-obm-creds.py

This file was deleted.

89 changes: 0 additions & 89 deletions argo-workflows/sync-nb-server-to-ironic/code/synchronize-server.py

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ spec:
parameters:
- name: device_id
container:
image: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:latest
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest
command:
- python
- /app/synchronize-interfaces.py
- synchronize-interfaces
args:
- --device-id
- "{{inputs.parameters.device_id}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ spec:
parameters:
- name: obm
container:
image: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:latest
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest
command:
- python
- /app/synchronize-obm-creds.py
- synchronize-obm-creds
args:
- "{{workflow.parameters.interface_update_event}}"
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ spec:
templates:
- name: synchronize-server
container:
image: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:0.0.3
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest
command:
- python
- /app/synchronize-server.py
- synchronize-server
args:
- "{{workflow.parameters.interface_update_event}}"
volumeMounts:
Expand Down
27 changes: 27 additions & 0 deletions containers/Dockerfile.ironic-nautobot-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG BASE=ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19:latest

FROM ${BASE} AS builder
ARG APP_PATH=/app
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG APP_USER_UID=1000
ARG APP_GROUP_GID=1000
RUN --mount=type=cache,target=/var/cache/apk apk add --virtual build-deps gcc python3-dev musl-dev linux-headers
RUN --mount=type=cache,target=/root/.cache/.pip /opt/venv/bin/pip install 'build==1.2.1' 'wheel==0.43.0'

# copy in the code
COPY --chown=${APP_USER}:${APP_GROUP} python/understack-workflows /app
# build wheels
RUN --mount=type=cache,target=/root/.cache/.pip cd /app && /opt/venv/bin/python -m build --wheel
# need netifaces built as a wheel
RUN --mount=type=cache,target=/root/.cache/.pip cd /app/dist && /opt/venv/bin/pip wheel netifaces

FROM ${BASE} AS prod

WORKDIR /app

COPY --from=builder /app/dist/*.whl /opt/venv/wheels/

USER $APP_USER

RUN /opt/venv/bin/pip install --no-cache-dir --find-links /opt/venv/wheels/ understack-workflows
11 changes: 11 additions & 0 deletions python/understack-workflows/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ dynamic = ["version"]
# but need to adjust ruff rules too
requires-python = ">= 3.11,<3.12"

dependencies = [
"pydantic==2.8.0",
"pynautobot==2.2.0",
"python-ironicclient==5.5.0",
]

[project.scripts]
synchronize-interfaces = "understack_workflows.main.synchronize_interfaces:main"
synchronize-obm-creds = "understack_workflows.main.synchronize_obm_creds:main"
synchronize-server = "understack_workflows.main.synchronize_server:main"

[build-system]
requires = [
"setuptools>=61.0",
Expand Down
Loading

0 comments on commit 21f445e

Please sign in to comment.