export PGPASSWORD=123
export PGUSER=testapp
docker run --rm --name testapp-postgres -p 5432:5432 -e POSTGRES_USER="$PGUSER" -e POSTGRES_PASSWORD="$PGPASSWORD" -d postgres
psql -h localhost
# python3 -m venv venv
# . venv/bin/activate
# pip install requirements.txt
export SQLALCHEMY_DATABASE_URI="postgresql://testapp:123@localhost:5432/testapp"
# flask db init
# flask db migrate
# flask db upgrade
When updating models it is necessary to prepare the db migrations while connected to a development database, by running:
# flask db migrate
then commit to git and build a new docker image.
Before the production image runs the application, it will run flask db upgrade
to run the db migrations on the production database.
pytest -v
export SQLALCHEMY_DATABASE_URI="postgresql://testapp:123@localhost:5432/testapp"
export FLASK_ENV=development
flask run
# brew install eksctl yq
# eksctl create cluster --name testcluster --region eu-west-1 --fargate
Run tests locally
. venv/bin/activate
pytest -v
Build and push to docker hub
docker login
docker build -t tpatrascuboom/testapp:v0.0.1 .
# docker push tpatrascuboom/testapp:v0.0.1
yq e -i '.spec.template.spec.containers[0].image = "tpatrascuboom/testapp:v0.0.1"' k8s-app-deploy.yaml
# kubectl -n default apply -f k8s-app-deploy.yaml
# kubectl -n default apply -f k8s-app-svc.yaml
kubectl get svc web
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web LoadBalancer 10.100.13.72 a6275b3db004c401da3a27e3cae15ded-d212d8afb2dfea9f.elb.eu-west-1.amazonaws.com 8080:32666/TCP 7m54s