docs(readme): add instructions to deploy via docker compose and via deta.space

This commit is contained in:
Kentai Radiquum 2024-05-15 00:02:29 +05:00
parent 59a61d3e7a
commit f2f83ad084
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
7 changed files with 239 additions and 5 deletions

56
.dockerignore Normal file
View file

@ -0,0 +1,56 @@
# Python
__pycache__
venv
.mypy_cache
# VSCode
.VSCode
*.code-workspace
# NextJS
## dependencies
node_modules
.pnp
.pnp.js
.yarn/install-state.gz
## testing
coverage
## next.js
.next
out
## production
build
## misc
.DS_Store
*.pem
## debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
## local env files
.env*.local
## vercel
.vercel
## typescript
*.tsbuildinfo
next-env.d.ts
# traefik
traefik
# OtherFiles
CHANGELOG.md
LICENSE
README.md
TODO.md
.cz.yaml
.pre-commit-config.yaml
docs

5
.env Normal file
View file

@ -0,0 +1,5 @@
EMAIL = your_email@example.com # EMAIL for certificate resolver.
DOMAIN = 127.0.0.1 # DOMAIN on which is app is hosted.
HTTP_PORT = 80
HTTPS_PORT = 443

View file

@ -118,13 +118,69 @@ To access the docker logs you can use `docker compose -f docker-compose.dev.yml
## Deployment
<!-- ### Docker Deployment
1. clone this repository via `git clone https://github.com/Radiquum/AniX.git`
2. cd into the repository folder.
3. deploy app with below instructions.
To be added soon . . . -->
### Docker Deployment
<!-- ### Deta Space
#### Docker Prerequisites
To be added soon . . . -->
1. **Docker:** Make sure Docker is installed on your system. You can download it from [https://www.docker.com/](https://www.docker.com/).
2. **Docker Compose:** Docker Compose should also be installed. It's usually included with Docker installations.
3. **Domain Name:** (optional) You need a registered domain name (e.g., `example.com`) and have it pointing to your server's IP address.
4. **SSL Certificate:** (optional) For HTTPS, you'll need an SSL certificate. Let's Encrypt is a free and popular option.
#### Docker steps
1. Edit the .env file
2. Edit the docker-compose.yml file to match your needs.
3. run `docker compose up -d` to build and run production images.
4. your app will be available at `http(s)://{DOMAIN}`.
5. run `docker compose down` to stop the containers.
*notes*:
- application is deployed as http by default, to enable https you need to edit docker compose and .env files.
if https is enabled, traefik will automatically issue HTTPS certificate from lets encrypt and redirect to HTTPS.
- you can also run `docker compose up --build` to build and run images without re-deploying the containers.
### Deta Space
1. **Install the Space CLI:**
```bash
curl -fsSL https://deta.space/assets/space-cli.sh | sh
```
2. **Login to Deta Space:**
```bash
space login
```
(You'll need to grab an access token from your Space dashboard)
3. **Create a new Space Project:**
```bash
space new
```
(This will guide you through setting up your project)
4. **Push your app to Deta Space:**
```bash
space push
```
(This will build and deploy your application)
You can find more details in the Deta Space documentation: [Deta Space Docs](https://docs.deta.space/)
<!-- ### Standalone

77
docker-compose.yml Normal file
View file

@ -0,0 +1,77 @@
services:
frontend:
env_file: .env
container_name: "AniX-frontend"
build:
context: ./frontend
dockerfile: ../docker/frontend.Dockerfile
labels:
# --- ${DOMAIN} will be replaced with DOMAIN from .env ---
- "traefik.enable=true"
- "traefik.http.routers.anix-frontend.rule=Host(`${DOMAIN}`)"
# --- !COMMENT THIS FOR HTTPS! ---
- "traefik.http.routers.anix-frontend.entrypoints=web"
# --- !UNCOMMENT THIS FOR HTTPS! ---
#- "traefik.http.routers.anix-frontend.entrypoints=websecure"
#- "traefik.http.routers.anix-frontend.tls=true"
#- "traefik.http.routers.user-api-backend.tls.certresolver=letsencrypt"
expose:
- 3000
backend:
env_file: .env
container_name: "AniX-backend"
build:
context: ./backend
dockerfile: ../docker/backend.Dockerfile
labels:
# --- ${DOMAIN} will be replaced with DOMAIN from .env ---
- "traefik.enable=true"
- "traefik.http.routers.anix-backend.rule=Host(`${DOMAIN}`) && PathPrefix(`/api`)"
- traefik.http.middlewares.anix-backend_stripprefix.stripprefix.prefixes=/api
- "traefik.http.routers.anix-backend.middlewares=anix-backend_stripprefix@docker"
# --- !COMMENT THIS FOR HTTPS! ---
- "traefik.http.routers.anix-backend.entrypoints=web"
# --- !UNCOMMENT THIS FOR HTTPS! ---
#- "traefik.http.routers.anix-backend.tls=true"
#- "traefik.http.routers.anix-backend.entrypoints=websecure"
#- "traefik.http.routers.user-api-backend.tls.certresolver=letsencrypt"
expose:
- 8000
traefik:
env_file: .env
image: "traefik:v3.0"
container_name: "AniX-traefik"
command:
- "--api.dashboard=false"
- "--api.insecure=false"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
# --- !COMMENT THIS FOR HTTPS! ---
- "--entryPoints.web.address=:${HTTP_PORT:-80}"
# --- !UNCOMMENT THIS FOR HTTPS! ---
#- "--entrypoints.websecure.address=:${HTTPS_PORT:-443}"
#- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
#- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
#- "--certificatesresolvers.letsencrypt.acme.tlschallenge=true"
#- "--certificatesresolvers.letsencrypt.acme.email=${EMAIL}"
#- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
ports:
# --- !COMMENT THIS FOR HTTPS! ---
- ${HTTP_PORT:-80}:${HTTP_PORT:-80}
# --- !UNCOMMENT THIS FOR HTTPS! ---
#- ${HTTPS_PORT:-443}:${HTTPS_PORT:-443}
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
depends_on:
- frontend
- backend
# --- !UNCOMMENT THIS FOR HTTPS! ---
# acme.json should be created on host instance!
#- "./acme.json:/letsencrypt/acme.json"

18
docker/backend.Dockerfile Normal file
View file

@ -0,0 +1,18 @@
# The first instruction is what image we want to base our container on
# We Use an official Python runtime as a parent image
FROM python:3.9
# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first
ENV PYTHONUNBUFFERED 1
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . .
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--root-path", "/api"]

View file

@ -0,0 +1,22 @@
FROM node:21-alpine
RUN mkdir /app
RUN mkdir /prepare
WORKDIR /prepare
ADD package.json .
RUN npm update -g npm --loglevel verbose
COPY . .
# RUN npm install --loglevel verbose
RUN npm ci --omit=dev --no-audit --maxsockets 1 --loglevel verbose
RUN npm run docker --loglevel verbose
RUN cp -a ./build/. /app/
WORKDIR /app
RUN rm -rf /prepare
RUN npm i sharp --loglevel verbose
CMD ["node", "./server.js"]

View file

@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"docker": "next build && mkdir -p .next/standalone/public/_next && cp -r .next/static .next/standalone/public/_next/ && mv .next/standalone ./build && rm -rf .next",
"lint": "next lint"
},
"dependencies": {