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

docs: update 12-factor tutorials #2085

Open
wants to merge 93 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
2236118
docs: remove django md file, add django rst file
erinecon Jan 17, 2025
84f07f9
fix: fix lint failures
erinecon Jan 17, 2025
04a4817
docs: add django tutorial spread test
erinecon Jan 17, 2025
1e9b7b6
fix: remove trailing spaces
erinecon Jan 17, 2025
da47d6b
fix: remove trailing spaces
erinecon Jan 17, 2025
5286e23
fix(store): better error message with fetch-lib (#2084)
lengau Jan 18, 2025
dc917b1
build(deps): update bugfixes
renovate[bot] Jan 18, 2025
65462a4
Merge branch 'main' into update-tutorials
erinecon Jan 20, 2025
7669dea
docs: remove experimental extension flag
erinecon Jan 21, 2025
ae603d9
Merge branch 'update-tutorials' of https://github.com/erinecon/charmc…
erinecon Jan 21, 2025
f3fd4b7
docs: add reuse setup file
erinecon Jan 21, 2025
92ac018
docs: replace code with wrapped commands
erinecon Jan 21, 2025
659b28d
fix: remove duplicate content, break commands up
erinecon Jan 21, 2025
69eb47d
Merge branch 'main' into update-tutorials
erinecon Jan 22, 2025
d28c88e
fix: incorporate changes from Design team
erinecon Jan 22, 2025
fd27611
Merge branch 'main' into update-tutorials
erinecon Jan 22, 2025
5514ed9
fix: revert command to run app locally
erinecon Jan 22, 2025
ae67ad0
Merge branch 'update-tutorials' of https://github.com/erinecon/charmc…
erinecon Jan 22, 2025
4b4a684
fix: update Django spread test
erinecon Jan 22, 2025
ac11344
Merge branch 'main' into update-tutorials
erinecon Jan 22, 2025
9046167
docs: update Django pack warning
erinecon Jan 23, 2025
bdc53c2
docs: update Django charm pack warning
erinecon Jan 23, 2025
ecd8773
fix: update Flask task file
erinecon Jan 23, 2025
2991bf5
docs: update Flask tutorial files
erinecon Jan 23, 2025
1438529
fix: make lint happy
erinecon Jan 23, 2025
a01b53b
docs: update setup instructions
erinecon Jan 23, 2025
f78d2f9
fix: make lint happy
erinecon Jan 23, 2025
da355e7
test: turn on tutorial spread tests
erinecon Jan 24, 2025
0d7ce15
test: force juju snap refresh
erinecon Jan 24, 2025
9f34fe1
fix: add substitutions to setup
erinecon Jan 28, 2025
1d28cd3
Merge branch 'main' into update-tutorials
erinecon Jan 28, 2025
a1badee
fix: make lint happy
erinecon Jan 28, 2025
62b982f
Merge branch 'main' into update-tutorials
erinecon Jan 29, 2025
48905f8
docs: update flask tutorial title
erinecon Jan 29, 2025
e2dacd4
docs: update flask tutorial title
erinecon Jan 29, 2025
06385cc
fix: sync Flask and Django tutorials
erinecon Jan 29, 2025
030bad6
test: update spread.yaml
erinecon Jan 29, 2025
8699139
docs: update fastapi tutorial
erinecon Jan 29, 2025
5019f95
test: update flask spread test
erinecon Jan 29, 2025
7d8b696
docs: update fastapi tutorial
erinecon Jan 29, 2025
0036d3a
docs: update fastapi tutorial
erinecon Jan 30, 2025
2edc394
test: pin postgres revision in flask spread test
erinecon Jan 30, 2025
483ec4b
fix: remove trailing whitespace
erinecon Jan 30, 2025
3f9dd67
Merge branch 'main' into update-tutorials
erinecon Jan 30, 2025
79462b1
fix: update tutorial index
erinecon Jan 30, 2025
7e0a28f
fix: update fastapi tutorial
erinecon Jan 30, 2025
508ea85
fix: revert postgres pin and turn off spread
erinecon Jan 31, 2025
85af6c1
test: output spread software versions
erinecon Jan 31, 2025
0a7a486
docs: update go tutorial
erinecon Jan 31, 2025
486b146
docs: update go tutorial
erinecon Jan 31, 2025
41ef9df
fix: make lint happy
erinecon Jan 31, 2025
968734c
fix: update reusable setups
erinecon Jan 31, 2025
d66f8b3
fix: correct issues with go tutorial
erinecon Jan 31, 2025
4864aa0
test: remove checks in flask spread
erinecon Jan 31, 2025
d7f1774
Merge branch 'main' into update-tutorials
erinecon Feb 6, 2025
be40d40
fix: update flask task.yaml
erinecon Feb 6, 2025
5c23618
fix: update curl command
erinecon Feb 6, 2025
7cd1575
fix: update curl command
erinecon Feb 6, 2025
c29053a
fix: update greeting config snippet
erinecon Feb 6, 2025
89b52c8
fix: update visitors requires snippet
erinecon Feb 6, 2025
b1ddb79
docs: add fastapi tutorial spread test
erinecon Feb 6, 2025
7f16b62
fix: add lines to end of fastapi files
erinecon Feb 6, 2025
4d47f18
Merge branch 'main' into update-tutorials
erinecon Feb 7, 2025
2b9ee02
Merge branch 'update-tutorials' of https://github.com/erinecon/charmc…
erinecon Feb 7, 2025
f40b54e
docs: include info for platforms in charmcraft.yaml
erinecon Feb 7, 2025
240dfec
docs: include info for platforms in charmcraft.yaml
erinecon Feb 7, 2025
9283b97
test: add debug line
erinecon Feb 7, 2025
b8f94a3
docs: add Go tutorial spread test
erinecon Feb 10, 2025
08c3bb3
test: swap postgres and fastapi juju checks
erinecon Feb 10, 2025
e358e82
test: increase flask and postgres times
erinecon Feb 10, 2025
d729154
docs: add spread commands to fastapi tutorial
erinecon Feb 10, 2025
294a179
fix: improve fastapi tutorial readability
erinecon Feb 10, 2025
ff40563
docs: add spread commands to go tutorial
erinecon Feb 10, 2025
4bffb35
fix: lint issues
erinecon Feb 10, 2025
0f10402
Merge branch 'main' of https://github.com/canonical/charmcraft into u…
erinecon Feb 11, 2025
db1b0b2
docs: remove flask file
erinecon Feb 11, 2025
34f5d66
fix(docs): first file creation instructions
erinecon Feb 11, 2025
9a2495b
fix(docs): create app.py instructions
erinecon Feb 11, 2025
37b954b
fix(docs): create migrate.py instructions
erinecon Feb 11, 2025
1bce948
Merge branch 'main' into update-tutorials
erinecon Feb 11, 2025
6ea939e
fix(docs): use stable setup for django
erinecon Feb 11, 2025
5cb6e0f
fix(docs): update DJANGO_ALLOWED_HOSTS
erinecon Feb 11, 2025
6103ba1
docs: have tutorials use juju 3.6
erinecon Feb 11, 2025
bf617d2
docs: swap microk8s setup order
erinecon Feb 11, 2025
c8d6e0a
docs: tell users to use juju 3.6
erinecon Feb 11, 2025
2e8e781
fix(docs): update juju status output
erinecon Feb 11, 2025
be56c25
fix(docs): remove django config-allowed-hosts
erinecon Feb 11, 2025
336e9e4
fix(docs): clarify django imports
erinecon Feb 11, 2025
c632385
fix(docs): update django curl
erinecon Feb 11, 2025
974c981
fix(docs): update django env var
erinecon Feb 11, 2025
d3c78c1
fix(docs): update django curl commands
erinecon Feb 11, 2025
f0f1940
fix(docs): update tutorial summary
erinecon Feb 11, 2025
5f48600
test(docs): add another fastapi wait-for
erinecon Feb 11, 2025
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
90 changes: 90 additions & 0 deletions docs/reuse/tutorial/setup_edge.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
First, install Multipass.

.. seealso::

See more: `Multipass |
How to install Multipass <https://multipass.run/docs/install-multipass>`_

Use Multipass to launch an Ubuntu VM with the name ``charm-dev``
from the 24.04 blueprint:

.. code-block:: bash
multipass launch --cpus 4 --disk 50G --memory 4G --name charm-dev 24.04
Once the VM is up, open a shell into it:

.. code-block:: bash
multipass shell charm-dev
In order to create the rock, you'll need to install Rockcraft with the
``--classic`` confinement to allow access to the whole file system:

.. code-block:: bash
sudo snap install rockcraft --classic
``LXD`` will be required for building the rock.
Make sure it is installed and initialized:

.. code-block:: bash
lxd --version
lxd init --auto
If ``LXD`` is not installed, install it with ``sudo snap install lxd``.

In order to create the charm, you'll need to install Charmcraft:

.. code-block:: bash
sudo snap install charmcraft --channel latest/edge --classic
.. warning::

This tutorial requires version ``3.2.0`` or later of Charmcraft.
Check the version of Charmcraft using ``charmcraft --version``.

MicroK8s is required to deploy the |12FactorApp| application on Kubernetes.
Let's install MicroK8s using the ``1.31-strict/stable`` track:

.. code-block:: bash
sudo snap install microk8s --channel 1.31-strict/stable
sudo adduser $USER snap_microk8s
newgrp snap_microk8s
Several MicroK8s add-ons are required for deployment:

.. code-block:: bash
# Required for Juju to provide storage volumes
sudo microk8s enable hostpath-storage
# Required to host the OCI image of the application
sudo microk8s enable registry
# Required to expose the application
sudo microk8s enable ingress
Wait for MicroK8s to be ready:

.. code-block:: bash
sudo microk8s status --wait-ready
Juju is required to deploy the |12FactorApp| application.
Install Juju using the ``3.6/stable`` track, and bootstrap a
development controller:

.. code-block:: bash
sudo snap install juju --channel 3.6/stable
mkdir -p ~/.local/share
juju bootstrap microk8s dev-controller
.. note::

It could take a few minutes to download the images.

43 changes: 32 additions & 11 deletions docs/reuse/tutorial/setup_stable.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
First, `install Multipass <https://multipass.run/docs/install-multipass>`_.
First, install Multipass.

.. seealso::

See more: `Multipass |
How to install Multipass <https://multipass.run/docs/install-multipass>`_

Use Multipass to launch an Ubuntu VM with the name ``charm-dev``
from the 24.04 blueprint:
Expand All @@ -13,20 +18,23 @@ Once the VM is up, open a shell into it:
multipass shell charm-dev
In order to create the rock, you'll need to install Rockcraft:
In order to create the rock, you'll need to install Rockcraft with the
``--classic`` confinement to allow access to the whole file system:

.. code-block:: bash
sudo snap install rockcraft --classic
``LXD`` will be required for building the rock.
Make sure it is installed and initialised:
Make sure it is installed and initialized:

.. code-block:: bash
sudo snap install lxd
lxd --version
lxd init --auto
If ``LXD`` is not installed, install it with ``sudo snap install lxd``.

In order to create the charm, you'll need to install Charmcraft:

.. code-block:: bash
Expand All @@ -41,30 +49,43 @@ In order to create the charm, you'll need to install Charmcraft:
``sudo snap refresh charmcraft --channel latest/edge`` to get the latest
edge version of Charmcraft.

MicroK8s is required to deploy the Flask application on Kubernetes. Install MicroK8s:
MicroK8s is required to deploy the |12FactorApp| application on Kubernetes.
Let's install MicroK8s using the ``1.31-strict/stable`` track:

.. code-block:: bash
sudo snap install microk8s --channel 1.31-strict/stable
sudo adduser $USER snap_microk8s
newgrp snap_microk8s
Wait for MicroK8s to be ready using ``sudo microk8s status --wait-ready``.
Several MicroK8s add-ons are required for deployment:

.. code-block:: bash
# Required for Juju to provide storage volumes
sudo microk8s enable hostpath-storage
# Required to host the OCI image of the Flask application
# Required to host the OCI image of the application
sudo microk8s enable registry
# Required to expose the Flask application
# Required to expose the application
sudo microk8s enable ingress
Juju is required to deploy the Flask application.
Install Juju and bootstrap a development controller:
Wait for MicroK8s to be ready:

.. code-block:: bash
sudo microk8s status --wait-ready
Juju is required to deploy the |12FactorApp| application.
Install Juju using the ``3.6/stable`` track, and bootstrap a
development controller:

.. code-block:: bash
sudo snap install juju --channel 3.5/stable
sudo snap install juju --channel 3.6/stable
mkdir -p ~/.local/share
juju bootstrap microk8s dev-controller
.. note::

It could take a few minutes to download the images.
7 changes: 7 additions & 0 deletions docs/tutorial/code/django/greeting_charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config:
options:
greeting:
description: |
The greeting to be returned by the Django application.
default: "Hello, world!"
type: string
4 changes: 4 additions & 0 deletions docs/tutorial/code/django/postgres_requires_charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requires:
postgresql:
interface: postgresql_client
optional: false
2 changes: 2 additions & 0 deletions docs/tutorial/code/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Django
psycopg2-binary
129 changes: 129 additions & 0 deletions docs/tutorial/code/django/settings_init_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""
Django settings for django_hello_world project.
Generated by 'django-admin startproject' using Django 5.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
import json
import os
import secrets

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', secrets.token_hex(32))

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', 'false') == 'true'

ALLOWED_HOSTS = json.loads(os.environ.get('DJANGO_ALLOWED_HOSTS', '[]'))

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_hello_world.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_hello_world.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('POSTGRESQL_DB_NAME'),
'USER': os.environ.get('POSTGRESQL_DB_USERNAME'),
'PASSWORD': os.environ.get('POSTGRESQL_DB_PASSWORD'),
'HOST': os.environ.get('POSTGRESQL_DB_HOSTNAME'),
'PORT': os.environ.get('POSTGRESQL_DB_PORT'),
}
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Loading
Loading