From e0125b61985912a7e1378fdd0ecabc063c00bd9e Mon Sep 17 00:00:00 2001 From: Banghua Zhao Date: Sun, 22 Sep 2024 12:23:19 +1200 Subject: [PATCH] Config docker (#1) * Config docker * Update workflow folder * Update readme to include some useful badegs --- .github/{.workflows => workflows}/ci.yml | 0 Dockerfile | 18 ++++++++ README.md | 53 +++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) rename .github/{.workflows => workflows}/ci.yml (100%) create mode 100644 Dockerfile diff --git a/.github/.workflows/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/.workflows/ci.yml rename to .github/workflows/ci.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5489961 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements.txt file and install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the current directory contents into the container +COPY . . + +# Expose the port that FastAPI runs on (default: 8000) +EXPOSE 8000 + +# Run the FastAPI app with Uvicorn server +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index a96b7c0..3c73328 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # SwiftComp-API +[![Version](https://img.shields.io/github/v/release/wenbinyugroup/swiftcomp-api)](https://github.com/wenbinyu/swiftcomp-api/releases) +[![Build Status](https://github.com/wenbinyugroup/swiftcomp-api/actions/workflows/ci.yml/badge.svg)](https://github.com/wenbinyugroup/swiftcomp-api/actions) +[![codecov](https://codecov.io/gh/wenbinyugroup/swiftcomp-api/branch/main/graph/badge.svg)](https://codecov.io/gh/wenbinyugroup/swiftcomp-api) +[![Last Commit](https://img.shields.io/github/last-commit/wenbinyugroup/swiftcomp-api)](https://github.com/wenbinyugroup/swiftcomp-api/commits/main) + **SwiftComp-API** is a FastAPI-based backend designed to perform calculations related to composite laminate materials. It exposes various endpoints for computing engineering constants, plate properties, 3D laminate properties, and more. This API is suitable for researchers, engineers, and developers working in composite materials and structural analysis. @@ -34,7 +39,53 @@ --- -## Installation +## Installation Using Docker (recommend) + +### Prerequisites +- Docker + +### Step-by-Step Guide + +1. **Clone the repository**: +```bash +git clone https://github.com/wenbinyugroup/swiftcomp-api.git +cd swiftcomp-api +``` +2. **Building the Docker Image**: +You can build a Docker image for the FastAPI app using the following command: + +```bash +docker build -t swiftcomp-api . +``` +3. **Running the Docker Container**: +Once the image is built, you can run the application in a Docker container: + +```bash +docker run -d -p 8000:8000 swiftcomp-api +``` +This will run the SwiftComp API app in a container and map port 8000 from the container to your local machine. You can access the application at http://localhost:8000. + +4. **Running Tests Inside the Docker Container**: +To run the tests inside the running Docker container: + +```bash +docker exec $(docker ps -q -f ancestor=swiftcomp-api) bash -c "PYTHONPATH=./ pytest" +``` +This command sets the `PYTHONPATH` and runs `pytest` inside the running Docker container. + +5. **Monitoring Logs**: +To monitor the logs from the running Docker container in real time: + +```bash +docker logs -f +``` +You can get the container ID or name by running: + +```bash +docker ps +``` + +## Installation Locally To set up the project locally, follow these steps: