Git Product home page Git Product logo

docker-fastapi-vue's Introduction

Docker + FastAPI + Vue

Technologies:

  • Docker
  • Python FastAPI
  • Vue JS

Getting Started

This guide assumes basic understanding of Docker, Python, and Javascript.

Getting the demo application up and running:

  1. Create a new repo using this as a template: https://github.com/willfong/docker-fastapi-vue/generate

  2. Clone the new repo locally: git clone [email protected]:willfong/test-repo.git

  3. Change to the new repo: cd test-repo

  4. Create a .env file and add session secret:

    JWT_SIGNING_TOKEN=SOME_SECRET_HERE
    
  5. Build the Docker image: docker build --tag dockerfastapivue .

  6. 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
    
  7. Check to make sure the app container is still running: docker ps

  8. Create the SQLite datafile: docker exec -it app sqlite3 /data/sqlite.db ".read /data/schema.sql"

  9. Check the SQLite datafile to ensure there are tables: docker exec -it app sqlite3 /data/sqlite.db .schema

  10. Open a web browser to: http://localhost:5000/

  11. Click "Login" in the top right corner

  12. Click "Test Account Login" and enter in any username.

  13. Add a new message and see the message displayed.

Make changes to the backend system:

  1. Check the logs from the backend: docker logs app

  2. 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}
    
  3. Stop the Docker container: docker stop app

  4. Rebuild Docker image: docker build --tag dockerfastapivue .

  5. Start a new container with the new image:

    docker run \
      --rm -d \
      --name app \
      -p 5000:80 \
      -v ${PWD}/data:/data \
      dockerfastapivue
    
  6. Test the new endpoint: curl localhost:5000/echo/hello-world

  7. Check the Docker logs for your test message: docker logs app

Make changes to the frontend system:

  1. Change to the vue directory: cd vue

  2. Install the Javascript dependencies: npm install

  3. In src/components/navbar.vue, change: <h1 class="title">Example App</h1> to <h1 class="title">Hello App!</h1>

  4. Build the production distribution: npm run build

  5. Stop the existing Docker container: docker stop app

  6. 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
    
  7. Open a web browser to: http://localhost:5000 and verify

Docker Commands

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 Auth Flow

GitHub OAuth is a bit easier to enable than Facebook and Google OAuth.

  1. Create a GitHub OAuth Application: https://github.com/settings/applications/new

  2. Application Name and Homepage URL are just for display. Set Authorization callback URL to http://localhost:5000/oauth/github

  3. Add the following to the .env file:

    GITHUB_CLIENT_ID=626...1d2
    GITHUB_CLIENT_SECRET=cc3...350
    
  4. 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
    
  5. 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.