Examples
Real-world examples and use cases for deploying applications with Asantiya.
Table of Contents
- Simple Web Applications
- Full-Stack Applications
- Microservices
- Development Environments
- Production Deployments
- CI/CD Integration
Simple Web Applications
Static Website with Nginx
Deploy a static website using Nginx.
Project Structure:
my-website/
├── index.html
├── css/
│ └── style.css
├── js/
│ └── app.js
├── Dockerfile
└── deploy.yamlDockerfile:
FROM nginx:alpine
# Copy static files
COPY . /usr/share/nginx/html/
# Copy custom nginx config (optional)
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80deploy.yaml:
service: my-website
image: my-website
server: 127.0.0.1
app_ports: "8080:80"
host: false
builder:
arch: amd64
local: trueDeploy:
asantiya deployNode.js Express Application
Deploy a simple Node.js Express application.
Project Structure:
my-api/
├── package.json
├── server.js
├── Dockerfile
└── deploy.yamlpackage.json:
{
"name": "my-api",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.18.2"
}
}server.js:
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({ message: 'Hello from Asantiya!' });
});
app.get('/health', (req, res) => {
res.json({ status: 'healthy' });
});
app.listen(port, '0.0.0.0', () => {
console.log(`Server running on port ${port}`);
});Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]deploy.yaml:
service: my-api
image: my-api
server: 127.0.0.1
app_ports: "8080:3000"
host: false
builder:
arch: amd64
local: true
build_args:
NODE_ENV: productionFull-Stack Applications
React Frontend with Node.js Backend
Deploy a React frontend with a Node.js API backend.
Project Structure:
fullstack-app/
├── frontend/
│ ├── package.json
│ ├── src/
│ └── Dockerfile
├── backend/
│ ├── package.json
│ ├── server.js
│ └── Dockerfile
├── deploy.yaml
└── docker-compose.ymlFrontend Dockerfile:
FROM node:18-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80Backend Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3001
CMD ["npm", "start"]deploy.yaml:
service: fullstack-app
image: fullstack-app
server: 127.0.0.1
app_ports: "8080:80"
host: false
builder:
arch: amd64
local: true
dockerfile: frontend/Dockerfile
build_args:
NODE_ENV: production
accessories:
backend:
service: fullstack-app-backend
image: backend
ports: "3001:3001"
env:
NODE_ENV: production
PORT: 3001
network: fullstack-network
builder:
arch: amd64
local: true
dockerfile: backend/DockerfilePython Flask Application with PostgreSQL
Deploy a Python Flask application with PostgreSQL database.
Project Structure:
flask-app/
├── app.py
├── requirements.txt
├── Dockerfile
└── deploy.yamlapp.py:
from flask import Flask, jsonify
import psycopg2
import os
app = Flask(__name__)
def get_db_connection():
conn = psycopg2.connect(
host=os.environ.get('DB_HOST', 'postgres'),
database=os.environ.get('DB_NAME', 'myapp'),
user=os.environ.get('DB_USER', 'user'),
password=os.environ.get('DB_PASSWORD', 'password')
)
return conn
@app.route('/')
def index():
return jsonify({'message': 'Hello from Flask!'})
@app.route('/health')
def health():
try:
conn = get_db_connection()
conn.close()
return jsonify({'status': 'healthy', 'database': 'connected'})
except Exception as e:
return jsonify({'status': 'unhealthy', 'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)requirements.txt:
Flask==2.3.3
psycopg2-binary==2.9.7Dockerfile:
FROM python:3.11-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]deploy.yaml:
service: flask-app
image: flask-app
server: 127.0.0.1
app_ports: "8080:5000"
host: false
builder:
arch: amd64
local: true
build_args:
FLASK_ENV: production
accessories:
postgres:
service: flask-app-postgres
image: postgres:15-alpine
ports: "5432:5432"
env:
POSTGRES_DB: myapp
POSTGRES_USER: user
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
network: flask-network
options:
restart: alwaysNeed help with a specific use case? Check out the Troubleshooting Guide or join our community discussions.
Last updated on