generated from canonical/platform-engineering-charm-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Haproxy-route-policy add snapcraft.yaml #415
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
Open
Thanhphan1147
wants to merge
17
commits into
haproxy-route-policy-switch-default-db-to-postgresql
Choose a base branch
from
haproxy-route-policy-add-snap
base: haproxy-route-policy-switch-default-db-to-postgresql
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−1
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8a13f6a
Add snap files
Thanhphan1147 d2eaf1b
fix build issue
Thanhphan1147 73858c1
update module-name
Thanhphan1147 c837b78
set secret key as default, drop fetching from file
Thanhphan1147 572302f
update readme, fix secret key generation
0c2f206
add change artifact
Thanhphan1147 abf3699
add build snap workflow
Thanhphan1147 b4ef747
use upload-artifact v4
Thanhphan1147 b1e838a
update path
Thanhphan1147 8f50f40
add checkout step
Thanhphan1147 5fb4762
change working dir for build action
Thanhphan1147 21d7eea
sparse checkout the policy directory
Thanhphan1147 ab94eb0
debug
Thanhphan1147 c2a95b6
debug path
Thanhphan1147 9ea1329
remove debug
Thanhphan1147 3ba8099
update scripts to guard against empty DB config values and update all…
Thanhphan1147 3902302
update docs link
Thanhphan1147 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| version_schema: 2 | ||
|
|
||
| changes: | ||
| - title: Added snap packaging and runtime scripts for haproxy-route-policy | ||
| author: tphan025 | ||
| type: minor | ||
| description: > | ||
| Added snap packaging for the haproxy-route-policy app, including | ||
| `snap/snapcraft.yaml`, install/configure hooks, and helper scripts to run | ||
| Gunicorn and Django management commands with snap configuration values. | ||
| Added Gunicorn as a dependency and configured uv build metadata in | ||
| `pyproject.toml` for packaging. Updated the app README with a basic setup | ||
| flow for PostgreSQL and snap configuration. | ||
| urls: | ||
| pr: | ||
| - https://github.com/canonical/haproxy-operator/pull/415 | ||
| related_doc: | ||
| related_issue: | ||
| visibility: public | ||
| highlight: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #### Basic setup | ||
|
|
||
| Start a PostgreSQL database: | ||
|
|
||
| ``` | ||
| docker run -d --name postgres -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USERNAME=postgres postgres:latest | ||
| ``` | ||
|
|
||
| Basic snap configurations: | ||
|
|
||
| ``` | ||
| sudo snap set haproxy-route-policy database-password=postgres | ||
| sudo snap set haproxy-route-policy database-host=localhost | ||
| sudo snap set haproxy-route-policy database-port=5432 | ||
| sudo snap set haproxy-route-policy database-user=postgres | ||
| sudo snap set haproxy-route-policy database-name=postgres | ||
| ``` | ||
|
|
||
| ## Learn more | ||
| * [Read more](https://documentation.ubuntu.com/haproxy-charm/latest/) | ||
|
|
||
| ## Project and community | ||
| * [Issues](https://github.com/canonical/haproxy-operator/issues) | ||
| * [Matrix](https://matrix.to/#/#charmhub-charmdev:ubuntu.com) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| DJANGO_DEBUG="$(snapctl get debug)" | ||
| export DJANGO_DEBUG | ||
|
|
||
| case "$DJANGO_DEBUG" in | ||
| "true") ;; | ||
| "false") ;; | ||
| *) | ||
| >&2 echo "'$DJANGO_DEBUG is not a supported value for django_debug. Possible values are true, false" | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
| DJANGO_LOG_LEVEL="$(snapctl get log-level)" | ||
| export DJANGO_LOG_LEVEL | ||
|
|
||
| case "$DJANGO_LOG_LEVEL" in | ||
| "debug") ;; | ||
| "info") ;; | ||
| "warning") ;; | ||
| "error") ;; | ||
| "critical") ;; | ||
| "DEBUG") ;; | ||
| "INFO") ;; | ||
| "WARNING") ;; | ||
| "ERROR") ;; | ||
| "CRITICAL") ;; | ||
| *) | ||
| >&2 echo "'$DJANGO_LOG_LEVEL is not a supported value for debug. Possible values are debug, info, warning, error, critical" | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
| DJANGO_ALLOWED_HOSTS="$(snapctl get allowed-hosts)" | ||
| export DJANGO_ALLOWED_HOSTS | ||
| DJANGO_DATABASE_PASSWORD="$(snapctl get database-password)" | ||
| export DJANGO_DATABASE_PASSWORD | ||
| DJANGO_DATABASE_HOST="$(snapctl get database-host)" | ||
| export DJANGO_DATABASE_HOST | ||
| DJANGO_DATABASE_PORT="$(snapctl get database-port)" | ||
| export DJANGO_DATABASE_PORT | ||
| DJANGO_DATABASE_USER="$(snapctl get database-user)" | ||
| export DJANGO_DATABASE_USER | ||
| DJANGO_DATABASE_NAME="$(snapctl get database-name)" | ||
| export DJANGO_DATABASE_NAME | ||
|
|
||
| if [ -z "$DJANGO_DATABASE_HOST" ] || [ -z "$DJANGO_DATABASE_PORT" ] || [ -z "$DJANGO_DATABASE_USER" ] || [ -z "$DJANGO_DATABASE_PASSWORD" ] || [ -z "$DJANGO_DATABASE_NAME" ]; then | ||
| >&2 echo "One or more database configuration values are missing. Please ensure database-host, database-port, database-user, database-password, and database-name are all set." | ||
| return 1 | ||
| fi | ||
|
|
||
| snapctl stop "$SNAP_INSTANCE_NAME" | ||
| snapctl start "$SNAP_INSTANCE_NAME" | ||
Thanhphan1147 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| set -xe | ||
|
|
||
| # set default configuration values | ||
| snapctl set debug='false' | ||
| snapctl set log-level='INFO' | ||
| snapctl set allowed-hosts='["localhost", "127.0.0.1"]' | ||
| SECRET_KEY="$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c 50)" | ||
| snapctl set secret-key="$SECRET_KEY" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| set -xe | ||
|
|
||
Thanhphan1147 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| DJANGO_SECRET_KEY="$(snapctl get secret-key)" | ||
| export DJANGO_SECRET_KEY | ||
| DJANGO_DEBUG="$(snapctl get debug)" | ||
| export DJANGO_DEBUG | ||
| DJANGO_ALLOWED_HOSTS="$(snapctl get allowed-hosts)" | ||
| export DJANGO_ALLOWED_HOSTS | ||
| DJANGO_LOG_LEVEL="$(snapctl get log-level)" | ||
| export DJANGO_LOG_LEVEL | ||
| DJANGO_DATABASE_PASSWORD="$(snapctl get database-password)" | ||
| export DJANGO_DATABASE_PASSWORD | ||
| DJANGO_DATABASE_HOST="$(snapctl get database-host)" | ||
| export DJANGO_DATABASE_HOST | ||
| DJANGO_DATABASE_PORT="$(snapctl get database-port)" | ||
| export DJANGO_DATABASE_PORT | ||
| DJANGO_DATABASE_USER="$(snapctl get database-user)" | ||
| export DJANGO_DATABASE_USER | ||
| DJANGO_DATABASE_NAME="$(snapctl get database-name)" | ||
| export DJANGO_DATABASE_NAME | ||
|
|
||
| LOG_LEVEL="info" | ||
| if [ "$DJANGO_DEBUG" = "true" ]; then | ||
| LOG_LEVEL="debug" | ||
| fi | ||
|
|
||
| if [ -z "$DJANGO_DATABASE_HOST" ] || [ -z "$DJANGO_DATABASE_PORT" ] || [ -z "$DJANGO_DATABASE_USER" ] || [ -z "$DJANGO_DATABASE_PASSWORD" ] || [ -z "$DJANGO_DATABASE_NAME" ]; then | ||
| >&2 echo "One or more database configuration values are missing. Please ensure database-host, database-port, database-user, database-password, and database-name are all set." | ||
| return 1 | ||
| fi | ||
|
|
||
| exec gunicorn --bind 0.0.0.0:8080 haproxy_route_policy.wsgi \ | ||
| --capture-output --log-level="$LOG_LEVEL" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| set -e | ||
|
|
||
| DJANGO_SECRET_KEY="$(snapctl get secret-key)" | ||
| export DJANGO_SECRET_KEY | ||
| DJANGO_DEBUG="$(snapctl get debug)" | ||
| export DJANGO_DEBUG | ||
| DJANGO_ALLOWED_HOSTS="$(snapctl get allowed-hosts)" | ||
| if [ -z "$DJANGO_ALLOWED_HOSTS" ]; then | ||
| DJANGO_ALLOWED_HOSTS="[]" | ||
| fi | ||
| export DJANGO_ALLOWED_HOSTS | ||
| DJANGO_LOG_LEVEL="$(snapctl get log-level)" | ||
| export DJANGO_LOG_LEVEL | ||
| DJANGO_DATABASE_PASSWORD="$(snapctl get database-password)" | ||
| export DJANGO_DATABASE_PASSWORD | ||
| DJANGO_DATABASE_HOST="$(snapctl get database-host)" | ||
| export DJANGO_DATABASE_HOST | ||
| DJANGO_DATABASE_PORT="$(snapctl get database-port)" | ||
| export DJANGO_DATABASE_PORT | ||
| DJANGO_DATABASE_USER="$(snapctl get database-user)" | ||
| export DJANGO_DATABASE_USER | ||
| DJANGO_DATABASE_NAME="$(snapctl get database-name)" | ||
| export DJANGO_DATABASE_NAME | ||
|
|
||
| if [ -z "$DJANGO_DATABASE_HOST" ] || [ -z "$DJANGO_DATABASE_PORT" ] || [ -z "$DJANGO_DATABASE_USER" ] || [ -z "$DJANGO_DATABASE_PASSWORD" ] || [ -z "$DJANGO_DATABASE_NAME" ]; then | ||
| >&2 echo "One or more database configuration values are missing. Please ensure database-host, database-port, database-user, database-password, and database-name are all set." | ||
| return 1 | ||
| fi | ||
|
|
||
| exec $SNAP/bin/uv run $SNAP/app/manage.py "$@" --settings=haproxy_route_policy.settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| name: haproxy-route-policy | ||
| base: core24 | ||
| version: "0.1" | ||
| license: Apache-2.0 | ||
| summary: HAProxy Route Policy API | ||
| description: | | ||
| This snap bundles the HAProxy Route Policy Django application to be included in the haproxy-route-policy-operator. | ||
| confinement: strict | ||
| platforms: | ||
| amd64: | ||
| build-on: [amd64] | ||
| build-for: [amd64] | ||
|
|
||
| system-usernames: | ||
| _daemon_: shared | ||
|
|
||
| parts: | ||
| haproxy-route-policy: | ||
| plugin: uv | ||
| source: . | ||
| build-snaps: | ||
| - astral-uv | ||
| stage-snaps: | ||
| - astral-uv | ||
| override-build: | | ||
| # Also copy the source code to the install directory for the manage.py script | ||
| cp -r . $SNAPCRAFT_PART_INSTALL/app | ||
| chown -R 584792:584792 $SNAPCRAFT_PART_INSTALL/app | ||
| craftctl default | ||
|
|
||
| scripts: | ||
| plugin: dump | ||
| source: ./snap/scripts | ||
| override-prime: | | ||
| craftctl default | ||
| chmod -R +rx $CRAFT_PRIME/bin | ||
|
|
||
| apps: | ||
| gunicorn: | ||
| command: bin/gunicorn-start | ||
| daemon: simple | ||
| restart-condition: always | ||
| plugs: | ||
| - network | ||
| - network-bind | ||
|
|
||
| manage: | ||
| command: bin/manage | ||
| plugs: | ||
| - network | ||
| - network-bind |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.