Technologies:
- Docker
- Python FastAPI
- Vue JS
This guide assumes basic understanding of Docker, Python, and Javascript.
Getting the demo application up and running:
-
Create a new repo using this as a template: https://github.com/willfong/docker-fastapi-vue/generate
-
Clone the new repo locally:
git clone [email protected]:willfong/test-repo.git
-
Change to the new repo:
cd test-repo
-
Create a
.env
file and add session secret:JWT_SIGNING_TOKEN=SOME_SECRET_HERE
-
Build the Docker image:
docker build --tag dockerfastapivue .
-
Start a container named
app
from the image created above:docker run \ --rm -d \ --name app \ -p 5000:80 \ -v ${PWD}/data:/data \ --env-file .env \ dockerfastapivue
-
Check to make sure the
app
container is still running:docker ps
-
Create the SQLite datafile:
docker exec -it app sqlite3 /data/sqlite.db ".read /data/schema.sql"
-
Check the SQLite datafile to ensure there are tables:
docker exec -it app sqlite3 /data/sqlite.db .schema
-
Open a web browser to: http://localhost:5000/
-
Click "Login" in the top right corner
-
Click "Test Account Login" and enter in any username.
-
Add a new message and see the message displayed.
Make changes to the backend system:
-
Check the logs from the backend:
docker logs app
-
In
app/main.py
on line 16, add:@app.get("/echo/:message") def echo(message: str): util.logger.warning(f"Message: {message}") return {"msg": message}
-
Stop the Docker container:
docker stop app
-
Rebuild Docker image:
docker build --tag dockerfastapivue .
-
Start a new container with the new image:
docker run \ --rm -d \ --name app \ -p 5000:80 \ -v ${PWD}/data:/data \ dockerfastapivue
-
Test the new endpoint:
curl localhost:5000/echo/hello-world
-
Check the Docker logs for your test message:
docker logs app
Make changes to the frontend system:
-
Change to the
vue
directory:cd vue
-
Install the Javascript dependencies:
npm install
-
In
src/components/navbar.vue
, change:<h1 class="title">Example App</h1>
to<h1 class="title">Hello App!</h1>
-
Build the production distribution:
npm run build
-
Stop the existing Docker container:
docker stop app
-
Start a new container with the new image:
docker run \ --rm -d \ --name app \ -p 5000:80 \ -v ${PWD}:/vue \ -v ${PWD}/data:/data \ dockerfastapivue
-
Open a web browser to: http://localhost:5000 and verify
Create image locally:
docker build --tag dockerfastapivue .
Run an instance:
docker run \
--rm -d \
--name app \
-p 5000:80 \
-v ${PWD}/vue:/vue \
-v ${PWD}/data:/data \
dockerfastapivue
Access the database directly:
docker exec -it app sqlite3 /data/sqlite.db
GitHub OAuth is a bit easier to enable than Facebook and Google OAuth.
-
Create a GitHub OAuth Application: https://github.com/settings/applications/new
-
Application Name and Homepage URL are just for display. Set Authorization callback URL to
http://localhost:5000/oauth/github
-
Add the following to the
.env
file:GITHUB_CLIENT_ID=626...1d2 GITHUB_CLIENT_SECRET=cc3...350
-
Pass the
.env
file to Docker when you create the instance:docker run \ --rm -d \ --name app \ -p 5000:80 \ -v ${PWD}/vue:/vue \ -v ${PWD}/data:/data \ --env-file .env \ dockerfastapivue
-
You can use the GitHub login button now.
Details about the user profile passed back from GitHub: https://developer.github.com/v3/users/#get-the-authenticated-user