Skip to content

Commit

Permalink
Apply LTM 1.6 baked cookie changes
Browse files Browse the repository at this point in the history
  • Loading branch information
smk4664 committed Oct 18, 2024
1 parent 9710d45 commit 6695e30
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 129 deletions.
11 changes: 7 additions & 4 deletions development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ARG NAUTOBOT_VER="1.4"

# Accepts a desired Python version as build argument, default to 3.8
ARG PYTHON_VER="3.8"
ARG PYTHON_VER="3.11"

# Retrieve published development image of Nautobot base which should include most CI dependencies
FROM ghcr.io/nautobot/nautobot-dev:${NAUTOBOT_VER}-py${PYTHON_VER}
Expand All @@ -20,13 +20,14 @@ ARG NAUTOBOT_ROOT=/opt/nautobot

ENV prometheus_multiproc_dir=/prom_cache
ENV NAUTOBOT_ROOT ${NAUTOBOT_ROOT}
ENV INVOKE_NAUTOBOT_DEVICE_LIFECYCLE_MGMT_LOCAL=true

# Install Poetry manually via its installer script;
# We might be using an older version of Nautobot that includes an older version of Poetry
# and CI and local development may have a newer version of Poetry
# Since this is only used for development and we don't ship this container, pinning Poetry back is not expressly necessary
# We also don't need virtual environments in container
RUN curl -sSL https://install.python-poetry.org | python3 - && \
RUN which poetry || curl -sSL https://install.python-poetry.org | python3 - && \
poetry config virtualenvs.create false

# !!! USE CAUTION WHEN MODIFYING LINES ABOVE
Expand Down Expand Up @@ -68,11 +69,13 @@ RUN sort poetry_freeze_base.txt poetry_freeze_all.txt | uniq -u > poetry_freeze_

# Install all local project as editable, constrained on Nautobot version, to get any additional
# direct dependencies of the app
RUN pip install -c constraints.txt -e .
RUN --mount=type=cache,target="/root/.cache/pip",sharing=locked \
pip install -c constraints.txt -e .[all]

# Install any dev dependencies frozen from Poetry
# Can be improved in Poetry 1.2 which allows `poetry install --only dev`
RUN pip install -c constraints.txt -r poetry_freeze_dev.txt
RUN --mount=type=cache,target="/root/.cache/pip",sharing=locked \
pip install -c constraints.txt -r poetry_freeze_dev.txt

COPY development/nautobot_config.py ${NAUTOBOT_ROOT}/nautobot_config.py
# !!! USE CAUTION WHEN MODIFYING LINES ABOVE
31 changes: 17 additions & 14 deletions development/creds.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
# CREDS File: Store private information. Copied to creds.env and always ignored
################################################################################
# Nautobot Configuration Secret Items
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
NAUTOBOT_CREATE_SUPERUSER=true
NAUTOBOT_SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
NAUTOBOT_DB_PASSWORD=changeme
NAUTOBOT_NAPALM_USERNAME=''
NAUTOBOT_NAPALM_PASSWORD=''
NAUTOBOT_REDIS_PASSWORD=changeme
NAUTOBOT_SECRET_KEY='changeme'
NAUTOBOT_SUPERUSER_NAME=admin
NAUTOBOT_SUPERUSER_EMAIL=[email protected]
NAUTOBOT_SUPERUSER_PASSWORD=admin
NAUTOBOT_SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567

# Nauotbot DB Password to connect to the backend
# - NOTE: Should be the same as the selected backend (MySQL or Postgres password)
NAUTOBOT_DB_PASSWORD=notverysecurepwd
# Postgres
POSTGRES_PASSWORD=${NAUTOBOT_DB_PASSWORD}
PGPASSWORD=${NAUTOBOT_DB_PASSWORD}

# MySQL Credentials
MYSQL_ROOT_PASSWORD=notverysecurepwd
MYSQL_PASSWORD=notverysecurepwd

# Postgres Credentials
POSTGRES_PASSWORD=notverysecurepwd
MYSQL_ROOT_PASSWORD=${NAUTOBOT_DB_PASSWORD}
MYSQL_PASSWORD=${NAUTOBOT_DB_PASSWORD}

# Redis Credentials
REDIS_PASSWORD=notverysecurepwd
NAUTOBOT_REDIS_PASSWORD=${REDIS_PASSWORD}
NAUTOBOT_LOG_LEVEL=DEBUG
# Use these to override values in development.env
# NAUTOBOT_DB_HOST=localhost
# NAUTOBOT_REDIS_HOST=localhost
# NAUTOBOT_CONFIG=development/nautobot_config.py
38 changes: 12 additions & 26 deletions development/dev.env → development/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,39 @@
# DEV File: Store environment information. NOTE: Secrets NOT stored here!
################################################################################
# Nautobot Configuration Environment Variables
ALLOWED_HOSTS=*
BANNER_TOP="Local"
CHANGELOG_RETENTION=0
MAX_PAGE_SIZE=0
METRICS_ENABLED=True
NAPALM_TIMEOUT=5
NAUTOBOT_ROOT=/opt/nautobot
NAUTOBOT_ALLOWED_HOSTS=*
NAUTOBOT_BANNER_TOP="Local"
NAUTOBOT_CHANGELOG_RETENTION=0

NAUTOBOT_DEBUG=True
NAUTOBOT_DJANGO_EXTENSIONS_ENABLED=True
NAUTOBOT_DJANGO_TOOLBAR_ENABLED=True
NAUTOBOT_LOG_LEVEL=DEBUG
NAUTOBOT_METRICS_ENABLED=True
NAUTOBOT_NAPALM_TIMEOUT=5
NAUTOBOT_MAX_PAGE_SIZE=0

# Redis Configuration Environment Variables
REDIS_HOST=redis
NAUTOBOT_REDIS_HOST=${REDIS_HOST}
NAUTOBOT_REDIS_HOST=redis
NAUTOBOT_REDIS_PORT=6379
# Uncomment NAUTOBOT_REDIS_SSL if using SSL
# NAUTOBOT_REDIS_SSL=True

SUPERUSER_EMAIL=[email protected]
SUPERUSER_NAME=admin

# Nautobot DB Connection Environment Variables
NAUTOBOT_DB_HOST=db
NAUTOBOT_DB_NAME=nautobot
NAUTOBOT_DB_USER=nautobot
NAUTOBOT_DB_HOST=db
NAUTOBOT_DB_TIMEOUT=300

# Uncomment the environment variables that related to your DB backend.
NAUTOBOT_DB_ENGINE=django.db.backends.postgresql
NAUTOBOT_DB_PORT=5432
# NAUTOBOT_DB_ENGINE=django.db.backends.mysql
# NAUTOBOT_DB_PORT=3306
# Use them to overwrite the defaults in nautobot_config.py
# NAUTOBOT_DB_ENGINE=django.db.backends.postgresql
# NAUTOBOT_DB_PORT=5432

# Needed for Postgres should match the values for Nautobot above
POSTGRES_DB=nautobot
POSTGRES_USER=nautobot
PGUSER=nautobot
POSTGRES_HOST=postgres
POSTGRES_USER=${NAUTOBOT_DB_USER}
POSTGRES_DB=${NAUTOBOT_DB_NAME}

# Needed for MYSQL should match the values for Nautobot above
MYSQL_DATABASE=nautobot
MYSQL_USER=nautobot
MYSQL_USER=${NAUTOBOT_DB_USER}
MYSQL_DATABASE=${NAUTOBOT_DB_NAME}
MYSQL_ROOT_HOST=%

NAUTOBOT_DLM_ENABLED_METRICS = "nautobot_lcm_software_compliance_per_device_type,nautobot_lcm_software_compliance_per_inventory_item,nautobot_lcm_hw_end_of_support_per_part_number,nautobot_metrics_lcm_hw_end_of_support_site"
3 changes: 3 additions & 0 deletions development/development_mysql.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Custom ENVs for Mysql
# Due to docker image limitations for Mysql, we need "root" user to create more than one database table
NAUTOBOT_DB_USER=root
46 changes: 18 additions & 28 deletions development/docker-compose.base.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
---
x-nautobot-build:
&nautobot-build
x-nautobot-build: &nautobot-build
build:
args:
NAUTOBOT_VER: "${NAUTOBOT_VER}"
PYTHON_VER: "${PYTHON_VER}"
context: "../"
dockerfile: "development/Dockerfile"
x-nautobot-base:
&nautobot-base
x-nautobot-base: &nautobot-base
image: "nautobot-device-lifecycle-mgmt/nautobot:${NAUTOBOT_VER}-py${PYTHON_VER}"
env_file:
- "dev.env"
- "development.env"
- "creds.env"
tty: true

version: "3.4"
services:
nautobot:
ports:
- "0.0.0.0:8080:8080"
depends_on:
redis:
condition: "service_started"
db:
condition: "service_healthy"
<<: [ *nautobot-build, *nautobot-base ]
celery_worker:
<<:
- *nautobot-base
- *nautobot-build
worker:
entrypoint:
- "sh"
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL --events"
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL --events" ## $$ because of docker-compose
depends_on:
- "nautobot"
- "redis"
nautobot:
condition: "service_healthy"
healthcheck:
interval: "30s"
timeout: "10s"
start_period: "30s"
retries: 3
test:
[
"CMD",
"bash",
"-c",
"nautobot-server celery inspect ping --destination celery@$$HOSTNAME"
]
test: ["CMD", "bash", "-c", "nautobot-server celery inspect ping --destination celery@$$HOSTNAME"] ## $$ because of docker-compose
<<: *nautobot-base
celery_beat:
beat:
entrypoint:
- "sh"
- "-c"
- "nautobot-server celery beat -l $$NAUTOBOT_LOG_LEVEL" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
healthcheck:
disable: true
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "nautobot-server celery beat -l $$NAUTOBOT_LOG_LEVEL" ## $$ because of docker-compose
depends_on:
- "nautobot"
- "redis"
<<: *nautobot-base
healthcheck:
disable: true
<<: *nautobot-base
46 changes: 35 additions & 11 deletions development/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
# any override will need to include these volumes to use them.
# see: https://github.com/docker/compose/issues/3729
---
version: "3.4"
services:
nautobot:
command: "nautobot-server runserver 0.0.0.0:8080 --nothreading --insecure"
command: "nautobot-server runserver 0.0.0.0:8080"
ports:
- "8080:8080"
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
healthcheck:
disable: true
celery_worker:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
celery_beat:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
interval: "30s"
timeout: "10s"
start_period: "60s"
retries: 3
test: ["CMD", "true"] # Due to layering, disable: true won't work. Instead, change the test
docs:
entrypoint: "mkdocs serve -v -a 0.0.0.0:8080"
ports:
Expand All @@ -30,3 +27,30 @@ services:
healthcheck:
disable: true
tty: true
worker:
entrypoint:
- "sh"
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL --events" ## $$ because of docker-compose
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
healthcheck:
test: ["CMD", "true"] # Due to layering, disable: true won't work. Instead, change the test
beat:
entrypoint:
- "sh"
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery beat -l $$NAUTOBOT_LOG_LEVEL" ## $$ because of docker-compose
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
healthcheck:
test: ["CMD", "true"] # Due to layering, disable: true won't work. Instead, change the test
# To expose postgres or redis to the host uncomment the following
# postgres:
# ports:
# - "5432:5432"
# redis:
# ports:
# - "6379:6379"
34 changes: 25 additions & 9 deletions development/docker-compose.mysql.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
---
version: "3.4"

services:
nautobot:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
worker:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
db:
image: "mysql:8"
command:
- "--default-authentication-plugin=mysql_native_password"
- "--max_connections=1000"
env_file:
- "dev.env"
- "development.env"
- "creds.env"
- "development_mysql.env"
volumes:
- "lcm_mysql_data:/var/lib/mysql"
ports:
- "3306:3306"
- "mysql_data:/var/lib/mysql"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
test:
- "CMD"
- "mysqladmin"
- "ping"
- "-h"
- "localhost"
timeout: "20s"
retries: 10
volumes:
lcm_mysql_data: # yamllint disable-line rule:empty-values
mysql_data: {}
14 changes: 8 additions & 6 deletions development/docker-compose.postgres.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---
version: "3.4"

services:
nautobot:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.postgresql"
db:
image: "postgres:13-alpine"
command:
- "-c"
- "max_connections=200"
env_file:
- "dev.env"
- "development.env"
- "creds.env"
volumes:
- "postgres_data:/var/lib/postgresql/data"
ports:
- "127.0.0.1:5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
test: "pg_isready --username=$$POSTGRES_USER --dbname=$$POSTGRES_DB"
interval: "10s"
timeout: "5s"
retries: 10
Expand Down
9 changes: 3 additions & 6 deletions development/docker-compose.redis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
version: "3.4"
services:
redis:
image: "redis:6-alpine"
command:
- "sh"
- "-c" # this is to evaluate the $REDIS_PASSWORD from the env
- "redis-server --appendonly yes --requirepass $$REDIS_PASSWORD"
- "-c" # this is to evaluate the $NAUTOBOT_REDIS_PASSWORD from the env
- "redis-server --appendonly yes --requirepass $$NAUTOBOT_REDIS_PASSWORD"
env_file:
- "dev.env"
- "development.env"
- "creds.env"
ports:
- "6379:6379"
Loading

0 comments on commit 6695e30

Please sign in to comment.