Hanzo Dev commited on
Commit ·
2296a3e
1
Parent(s): 1876440
Switch to Docker SDK for Next.js deployment on HF Spaces
Browse files- .dockerignore +15 -0
- Dockerfile +38 -0
- README.md +2 -3
- app.py +0 -39
- package.json +1 -1
- requirements.txt +0 -1
.dockerignore
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
.next
|
| 3 |
+
.git
|
| 4 |
+
.gitignore
|
| 5 |
+
.env*
|
| 6 |
+
README.md
|
| 7 |
+
.DS_Store
|
| 8 |
+
npm-debug.log*
|
| 9 |
+
yarn-debug.log*
|
| 10 |
+
yarn-error.log*
|
| 11 |
+
.vercel
|
| 12 |
+
*.tsbuildinfo
|
| 13 |
+
next-env.d.ts
|
| 14 |
+
app.py
|
| 15 |
+
requirements.txt
|
Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build stage
|
| 2 |
+
FROM node:20-alpine AS builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Copy package files
|
| 7 |
+
COPY package*.json ./
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
+
RUN npm ci
|
| 11 |
+
|
| 12 |
+
# Copy all files
|
| 13 |
+
COPY . .
|
| 14 |
+
|
| 15 |
+
# Build the Next.js application
|
| 16 |
+
RUN npm run build
|
| 17 |
+
|
| 18 |
+
# Production stage
|
| 19 |
+
FROM node:20-alpine AS runner
|
| 20 |
+
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy necessary files from builder
|
| 24 |
+
COPY --from=builder /app/package*.json ./
|
| 25 |
+
COPY --from=builder /app/.next ./.next
|
| 26 |
+
COPY --from=builder /app/public ./public
|
| 27 |
+
COPY --from=builder /app/node_modules ./node_modules
|
| 28 |
+
|
| 29 |
+
# Expose port 7860 for Hugging Face Spaces
|
| 30 |
+
EXPOSE 7860
|
| 31 |
+
|
| 32 |
+
# Set environment variables
|
| 33 |
+
ENV NODE_ENV=production
|
| 34 |
+
ENV PORT=7860
|
| 35 |
+
ENV HOSTNAME=0.0.0.0
|
| 36 |
+
|
| 37 |
+
# Start the application
|
| 38 |
+
CMD ["npm", "start"]
|
README.md
CHANGED
|
@@ -3,9 +3,8 @@ title: Hanzo Template Gallery
|
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: gray
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
---
|
| 11 |
|
|
|
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
|
|
|
| 8 |
pinned: true
|
| 9 |
---
|
| 10 |
|
app.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
def start_next_app():
|
| 6 |
-
"""Start the Next.js application"""
|
| 7 |
-
try:
|
| 8 |
-
# Install dependencies if needed
|
| 9 |
-
if not os.path.exists('node_modules'):
|
| 10 |
-
subprocess.run(['npm', 'install'], check=True)
|
| 11 |
-
|
| 12 |
-
# Build the Next.js app
|
| 13 |
-
subprocess.run(['npm', 'run', 'build'], check=True)
|
| 14 |
-
|
| 15 |
-
# Start the app
|
| 16 |
-
process = subprocess.Popen(['npm', 'start'])
|
| 17 |
-
return "Hanzo Template Gallery is running!"
|
| 18 |
-
except Exception as e:
|
| 19 |
-
return f"Error starting application: {str(e)}"
|
| 20 |
-
|
| 21 |
-
# Create a simple Gradio interface that redirects to the Next.js app
|
| 22 |
-
iface = gr.Interface(
|
| 23 |
-
fn=start_next_app,
|
| 24 |
-
inputs=None,
|
| 25 |
-
outputs="text",
|
| 26 |
-
title="Hanzo Template Gallery",
|
| 27 |
-
description="Professional web templates built with @hanzo/ui components",
|
| 28 |
-
article="""
|
| 29 |
-
<p>Visit the gallery at <a href="http://localhost:3000" target="_blank">http://localhost:3000</a></p>
|
| 30 |
-
<p>Built with Next.js, @hanzo/ui, and Tailwind CSS</p>
|
| 31 |
-
"""
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
# Start the Next.js app in the background
|
| 36 |
-
start_next_app()
|
| 37 |
-
|
| 38 |
-
# Launch Gradio interface
|
| 39 |
-
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
"scripts": {
|
| 6 |
"dev": "next dev",
|
| 7 |
"build": "next build",
|
| 8 |
-
"start": "next start",
|
| 9 |
"lint": "next lint"
|
| 10 |
},
|
| 11 |
"dependencies": {
|
|
|
|
| 5 |
"scripts": {
|
| 6 |
"dev": "next dev",
|
| 7 |
"build": "next build",
|
| 8 |
+
"start": "next start -H 0.0.0.0 -p ${PORT:-7860}",
|
| 9 |
"lint": "next lint"
|
| 10 |
},
|
| 11 |
"dependencies": {
|
requirements.txt
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
gradio>=4.0.0
|
|
|
|
|
|