Skip to content
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
96 changes: 96 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

**/.DS_Store
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

**/node_modules
**/.env
**/.venv
**/env/
**/venv/
**/ENV/
**/env.bak/
**/venv.bak/
**/venv*/
**/venv*
**/venv**
**/src/tmp_venv/
**/virtualenv/
**/skillcorner_venv/
**/__pypackages__/
__pycache__/

*.py[cod]
*$py.class
*.sql
*.so

.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/


instance/
.webassets-cache


src/_example/**.sql*
3 changes: 3 additions & 0 deletions src/_example/django/.env.docker.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# forest environment settings
FOREST_ENV_SECRET=
FOREST_AUTH_SECRET=
50 changes: 50 additions & 0 deletions src/_example/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/

ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim AS base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_VIRTUALENVS_IN_PROJECT=false \
POETRY_NO_INTERACTION=1 \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
POETRY_HOME='/opt/poetry/'

RUN \
# install system requirement
apt update && \
apt install -y iputils-ping curl && \
# cleanup
apt clean

# Copy the source code into the container.
# we're using a volume for that, but for initialization
COPY ./ /app/

WORKDIR /app/src/_example/django/

RUN curl -sSL https://install.python-poetry.org | python3 - ;\
export PATH="/opt/poetry/bin:$PATH"

RUN /opt/poetry/bin/poetry install --no-cache

# for a bind mount on running repo
VOLUME /app

# Expose the port that the application listens on.
EXPOSE 8000

# set entrypoint
ENTRYPOINT ["/app/src/_example/django/docker-entrypoint.sh"]

# Run the application.
CMD /opt/poetry/bin/poetry run poe runserver
41 changes: 31 additions & 10 deletions src/_example/django/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,36 @@
## See django version lifecycle
[https://endoflife.date/django](https://endoflife.date/django)

## Requirements
## Using docker

First you need to create a `.env` file from [.env.docker.sample](./.env.docker.sample) file to add your `FOREST_ENV_SECRET` and `FOREST_AUTH_SECRET`

Normally with docker, you just have a few command to use, in the correct folder:

```bash
cd src/_example/django

docker compose up -d # to start in background
# Example project is now running on port 8000 with auto reload

docker compose logs -f # to see the output

docker compose down # to cleanup
```

⚠️ If you already have a [`.env`](./.env) at the root of this example project, it will be used, overriding environment variables defined in the [docker-compose.yaml](./docker-compose.yaml) file.

## Setup a dev environment on your machine

### Requirements

To manage your demo's dependencies you should install [poetry](https://python-poetry.org/docs/).

```bash
curl -sSL https://install.python-poetry.org | python3 -
```

### Already met problems
#### Already met problems

- If you're having SSL issue with Python while installing poetry, visit this link: <https://matduggan.com/til-python-3-6-and-up-is-broken-on-mac/>
- Make sure poetry is in your $PATH, sometimes on mac there is conflict between python installed graphically and installed with brew. You can use these commands to help you to find the problems
Expand All @@ -23,48 +44,48 @@ which python3.10
echo "PATH=$PATH;~/Library/Application Support/pypoetry/venv/bin" >> ~/.zshrc # this is default installation path for poetry on mac
```

## (Optional) Auto-load .env files with poetry
### (Optional) Auto-load .env files with poetry

```bash
poetry self add poetry-dotenv-plugin
```

## create a virtual env
### create a virtual env

```bash
python -m venv venv # the last 'venv' is the relative path where you want your virtual env
```

## activate it
### activate it

```bash
source venv/bin/activate # adapt venv with the path previously used
```

## Install the dependencies
### Install the dependencies

```bash
poetry install --with dev
```

## Init your database
### Init your database

```bash
poetry run poe init-db
```

## Populate your database with fake data
### Populate your database with fake data

```bash
poetry run poe populate-db
```

## Run the server
### Run the server

```bash
poetry run poe runserver
```

## Next step
### Next step

The last needed step is to onboard the project on [forestadmin](https://www.forestadmin.com/)
4 changes: 2 additions & 2 deletions src/_example/django/django_demo/.forestadmin-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3542,10 +3542,10 @@
],
"meta": {
"liana": "agent-python",
"liana_version": "1.17.0",
"liana_version": "1.18.5",
"stack": {
"engine": "python",
"engine_version": "3.12.4"
"engine_version": "3.11.11"
}
}
}
31 changes: 31 additions & 0 deletions src/_example/django/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/compose/compose-file/

# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
agent-python_django-example:
container_name: agent-python_django-example
build:
context: ../../../
dockerfile: src/_example/django/Dockerfile
args:
PYTHON_VERSION: 3.11 # 3.11 is default if not set
environment:
# forest related
FOREST_VERIFY_SSL: "False"
FOREST_SERVER_URL: 'https://api.development.forestadmin.com'
# django related
DJANGO_SECRET_KEY: "^=k+h&r(f7d+#@3f)%h2xef!zvsn2f5_^ahuo*9v7k^6gk=*ey"
DJANGO_DEBUG: True
DJANGO_ALLOWED_HOSTS: "*"
volumes:
# root of repo at /app
- ../../../:/app
ports:
- 8000:8000

25 changes: 25 additions & 0 deletions src/_example/django/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# set -x

# api.development.forestadmin.com as host machine
if ! grep -q api.development.forestadmin.com /etc/hosts
then
FOREST_BE=$(ping -c 1 host.docker.internal | awk 'NR==1 {print $3}' | cut -d \( -f2 | cut -d \) -f1)
echo "$FOREST_BE api.development.forestadmin.com" >> /etc/hosts
fi

# install requirements
echo "updating requirements"
/opt/poetry/bin/poetry install --no-cache -q

# init and seed db
if [ ! -f django_demo/db.sqlite3 ]
then
echo "creating and seeding databases"
/opt/poetry/bin/poetry run poe init-db
/opt/poetry/bin/poetry run poe populate-db
fi

# set of command
# start long running process at the end that is passed from CMD
exec "$@"
2 changes: 1 addition & 1 deletion src/_example/django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ type = "simple"
[tool.poe.tasks]
init-db = { shell = "cd django_demo && python manage.py migrate" }
populate-db = { shell = "cd django_demo && python manage.py populate-db && python manage.py sqlalchemy_init" }
runserver = { shell = "cd django_demo && python manage.py runserver" }
runserver = { shell = "cd django_demo && python manage.py runserver 0.0.0.0:8000" }
Loading