A Go API application using TORM (TypeORM-inspired ORM) with PostgreSQL database.
- Docker
- Kubernetes cluster (local or remote)
- kubectl configured to access your cluster
- Go 1.23+ (for local development)
cd tf-api-TORM# Make deployment script executable
chmod +x deploy.sh
# Run deployment
./deploy.shThe service is exposed via a LoadBalancer. After running ./deploy.sh, it may take a minute for the external IP to be available.
You can check the status and find the EXTERNAL-IP by running:
kubectl get svc tf-api-torm -n tf-api-tormOnce the EXTERNAL-IP is assigned (for Docker Desktop, this will typically be localhost), you can access the API on port 80. For example:
# Visit the API (replace localhost if your EXTERNAL-IP is different)
curl http://localhost/v1/The deployment includes:
- PostgreSQL Database: Persistent storage with ConfigMap and Secret management
- tf-api-TORM Application: Go API with TORM ORM integration
- Kubernetes Resources: Namespace, Deployments, Services, and Ingress
All Kubernetes resources are defined in a single file (k8s/deployment.yaml):
- Namespace:
tf-api-tormnamespace for isolation - ConfigMaps: Database and application configuration
- Secrets: Database password and sensitive data
- PostgreSQL: Database deployment with persistent storage
- tf-api-TORM API: Application deployment with init containers
- Services: Internal communication between components
- Ingress: External access (commented out by default)
The application requires the following environment variables:
DATABASE_URL: PostgreSQL connection stringPRIVATE_KEY: JWT private keyPUBLIC_KEY: JWT public keyGMAIL_CLIENT_ID: Gmail OAuth client IDGMAIL_CLIENT_SECRET: Gmail OAuth client secretGMAIL_REFRESH_TOKEN: Gmail OAuth refresh token
Default database settings:
- Database:
tfapi - User:
tfapi_user - Password:
tfapi_password
- Start PostgreSQL:
docker run -d \
--name postgres-tfapi \
-e POSTGRES_DB=tfapi \
-e POSTGRES_USER=tfapi_user \
-e POSTGRES_PASSWORD=tfapi_password \
-p 5432:5432 \
postgres:15-alpine- Set environment variables:
export DATABASE_URL="postgresql://tfapi_user:tfapi_password@localhost:5432/tfapi?sslmode=disable"- Generate TORM models and run migrations:
chmod +x build.sh
./build.sh- Run the application:
go run main.godocker build -t tf-api-torm:latest .If you prefer to deploy manually:
# Build the Docker image
docker build -t tf-api-torm:latest .
# Apply the Kubernetes configuration
kubectl apply -f k8s/deployment.yaml
# Check the deployment status
kubectl get pods -n tf-api-tormThe API provides the following endpoints:
GET /v1/get/projects- Get all projectsGET /v1/get/project/{id}- Get specific projectGET /v1/get/projects/{category}- Get projects by categoryPOST /v1/post/vote- Submit a votePUT /v1/update/verify_vote- Verify a vote
# Application logs
kubectl logs -f deployment/tf-api-torm -n tf-api-torm
# Database logs
kubectl logs -f deployment/postgres -n tf-api-tormkubectl get pods -n tf-api-tormkubectl get svc -n tf-api-torm-
Database Connection Issues
- Check if PostgreSQL pod is running:
kubectl get pods -n tf-api-torm - Check database logs:
kubectl logs deployment/postgres -n tf-api-torm
- Check if PostgreSQL pod is running:
-
TORM Generation Issues
- Ensure DATABASE_URL is correctly set
- Check if TORM CLI is installed in the container
- Verify database is accessible from the application pod
-
Application Startup Issues
- Check application logs:
kubectl logs deployment/tf-api-torm -n tf-api-torm - Verify all environment variables are set
- Check if the application can connect to the database
- Check application logs:
To remove the entire deployment:
kubectl delete namespace tf-api-torm- Update the default database password in production
- Store sensitive environment variables in Kubernetes Secrets
- Configure proper ingress rules for production use
- Enable SSL/TLS for database connections in production
- Fork the repository
- Create a feature branch
- Make your changes
- Test the deployment
- Submit a pull request