diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b06ba6a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,75 @@ +# Git files +.git +.gitignore + +# GitHub files +.github + +# IDE files +.vscode +*.code-workspace + +# Documentation +README.md +CHANGELOG.md +CONTRIBUTING.md +LICENSE.md + +# Python cache +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Virtual environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Testing +.pytest_cache/ +.coverage +htmlcov/ +.tox/ +.nox/ + +# MacOS +.DS_Store +.AppleDouble +.LSOverride +Icon +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +*.icloud \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..874cdb4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use Python 3.11 slim image as base +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Copy requirements file +COPY src/requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt + +# Copy application code +COPY src/ . + +# Expose port 8000 +EXPOSE 8000 + +# Run the application +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/README.md b/README.md index fe1e9df..e19f1cf 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,40 @@ This backend Album API sample is available in other languages: | [C#](https://github.com/azure-samples/containerapps-albumapi-csharp) | [Go](https://github.com/azure-samples/containerapps-albumapi-go) | [JavaScript](https://github.com/azure-samples/containerapps-albumapi-javascript) | [Java](https://github.com/azure-samples/containerapps-albumapi-java) | | -------------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------- | + +## Running with Docker + +### Prerequisites +- Docker +- Docker Compose (optional) + +### Build and Run with Docker + +Build the Docker image: +```bash +docker build -t albumapi-python . +``` + +Run the container: +```bash +docker run -p 8000:8000 albumapi-python +``` + +### Using Docker Compose + +Run with Docker Compose: +```bash +docker compose up +``` + +Stop the services: +```bash +docker compose down +``` + +### Testing the API + +Once running, the API will be available at `http://localhost:8000`: + +- Root endpoint: `http://localhost:8000/` +- Albums endpoint: `http://localhost:8000/albums` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..610dc8d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + albumapi: + build: . + ports: + - "8000:8000" + environment: + - PYTHONUNBUFFERED=1 + # Optional: Mount source code for development (uncomment if needed) + # volumes: + # - ./src:/app + restart: unless-stopped \ No newline at end of file