Some set up instructions for local development.
In web backend, print statements will not appear in the console. Instead, you can import the app
instance,
and use app.logger.info()
or app.logger.error()
etc.
This project uses Python 3.9. Please create a virtual environment and upgrade your pip.
cd web
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip wheel pip-tools
pip install -r dev-requirements.txt
pre-commit install
Note that the web backend uses the environment variable CONFIG_ENV
to choose the config
yaml file. The default is dev.yml
if the environment variable is unspecified, and the web
backend will use the corresponding config file. All the configs will be merged
into web/config/base.yml recursively to produce the final config.
You can run docker compose build && docker compose up
to spin up a development server.
- The web backend server is accessible at
localhost:5000
. - The React web client will run at
localhost:3001
. - The postgres server will run at
localhost:5432
.
During development, the code to run both React and Flask will be mounted into the docker container
using volumes. This means changes in code are synced between the hosts and the dockers, while
Docker images are kept at a reasonable size. However in deployment, separate Dockerfiles should be created
that actually add the code into the images themselves via COPY
or ADD
.
In development context, the Postgres server is running as a docker image. We use Flask-Migrate
to do automatic database migrations through SQLAlchemy. Normally you do not have to carry out migration
unless you define a new SQLAlchemy model or modify an existing one. You cannot run flask db <command>
directly
because the web backend runs in a Docker container. There are three ways to run those commands.
# First make sure you start the Postgres server.
docker compose up db
# You can ssh into the web_backend server and run commands from within.
docker compose run web_backend /bin/bash
flask db init
flask db migrate -m "Some migration"
flask db upgrade
# You can also run these commands from the host directly.
docker compose run web_backend flask db init
docker compose run web_backend flask db migrate -m "Some migration"
docker compose run web_backend flask db upgrade
# It's possible to run these commands from host because of port mapping.
# Make sure your `FLASK_APP` is set to `application`.
export FLASK_APP="application"
# Then you can run the commands from your host.
flask db init
flask db migrate -m "Some migration"
flask db upgrade
In most circumstances, this repository already has alemibc initialized, so you most likely do not
need to run flask db init
. If you just cloned the repository and need to have the latest database
tables, you do not need to run any migration either. You can simply invoke the flask db upgrade
command.
Always double-check the auto-generated migration file before commiting to the upgrade.
curl https://get.okteto.com -sSfL | sh
to install the Okteto CLI.okteto context use https://cloud.okteto.com -n <namespace> -t <token>
to configure CLI.okteto build . -f Dockerfile.web -t okteto.dev/yield-optimizer-web:latest
to build and push image to Okteto registry.okteto build . -f Dockerfile.client -t okteto.dev/yield-optimizer-client:latest
to build and push image to Okteto registry.kubectl config set-context --current --namespace <namespace>
after uploading kubernetes config file to~/.kube/config
.kubectl apply -f k8s/
kubectl delete -f k8s/
kubectl create secret generic <secret-name> --from-literal='<key>=<secret>'
.- Specify the secret in the file.
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: nginx
volumeMounts:
# name must match the volume name below
- name: <secret-volume>
mountPath: <mount-path>
# The secret data is exposed to Containers in the Pod through a Volume.
volumes:
- name: <secret-volume>
secret:
secretName: <secret-name>