backend
folder.
As a Flask developer you will immediately see a familiar pattern:
templates
with your HTML Jinja templatesapp.py
requirements.txt
file for our python dependenciesgunicorn_config.py
file which configures our Gunicorn WSGIDockerfile
to containarize the application for easier development and deploymentstatic
folder holding the bundled .js
and .css
files, they will be imported in our HTMLserverless.yml
file which defines our IAS (Infrastructure As Code), we will use it later to deploy a Lambda function.env
file. You will see an .env.example
file with keys and empty values.
Rename it to .env.local
and fill it with the according values througout the rest of this documentation. When
you are ready to deploy to production, you will create a .env
file and copy the info there.
Open app.py
, you will see that if we run the file locally with bash local.sh
, we will
use the .env.local
file, otherwise we use the default .env
file.
.env
file, use the one according
to your current stage. At the top of your .env
file will be a “SECRET_KEY”, used by your Flask application.
Make sure to change to something secure, like a UUID4 from here.
package.json
and take a look at:
watch-css
, watch-js
or watch
to watch and bundle the corresponding file types.
As you can see we use PostCSS and a build.mjs
file to transpile our content from our src
to our static
folder.
Open postcss.config.js
, here you can see the plugins that we use to:
.css
filesbuild.mjs
file. Here we loop over each file in our src/js
directory
and start watching them for changes, when one occurs we create bundle with the same name.
backend
we have a few more files, which we will need for deploying our Docker containers in a
provisioned way, for example the nginx
folder, which holds all the Configuration for our web server.
In the root dir you can see the Dockerfile for that.
When building, Docker copies the static files and serves them through Nginx
instead of our Flask application, since this is more efficient.
Besides that we have a docker-compose.yml
file, for managing multiple Docker containers and making the communicate.
bash local.sh
will start a local (!DEVELOPMENT!) server which listens on Port 8080
orbash docker.sh
will run the same application with a propper WSGI and
a production-ready Nginx web-server