-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
68 lines (55 loc) · 2.2 KB
/
deploy.sh
File metadata and controls
68 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# --- RoboCoin Deployment Script ---
#
# This script automates the deployment of the RoboCoin application.
# It handles everything from installing dependencies to running database
# migrations and starting the production server.
#
# Prerequisites:
# - Node.js and npm must be installed on the server.
# - Git must be installed on the server.
# - You must have a production database (e.g., PostgreSQL) ready.
#
# How to Use:
# 1. Clone your repository to the deployment server.
# 2. Create a `.env` file by copying `.env.example` and filling
# in your production database URL and NextAuth secret.
# 3. Make this script executable by running: chmod +x deploy.sh
# 4. Run the script: ./deploy.sh
# Exit immediately if a command exits with a non-zero status.
set -e
# --- 1. Environment Setup ---
echo "Setting up environment..."
# Check if the .env.local file exists. If not, exit with an error.
if [ ! -f .env ]; then
echo "Error: .env file not found!"
echo "Please copy .env.example to .env and fill in your production values."
exit 1
fi
# --- 2. Install Dependencies ---
echo "Installing dependencies..."
# Install the exact versions of dependencies specified in package-lock.json.
# This ensures a consistent and reliable build.
npm ci
# --- 3. Database Migration ---
echo "Running database migrations..."
# Apply any pending Prisma schema changes to the production database.
# This ensures your database schema is up-to-date with your application code.
npx prisma migrate deploy
# --- 4. Build the Application ---
echo "Building the application for production..."
# Compile and optimize the Next.js application for production.
# This creates a highly optimized build in the .next directory.
npm run build
# --- 5. Start the Production Server ---
echo "Starting the production server..."
# Start the Next.js production server. It's recommended to use a process
# manager like PM2 to keep the application running continuously.
#
# Example with PM2:
# pm2 start npm --name "robocoin" -- start
#
# For this script, we will start it directly. You can stop it with Ctrl+C.
# In a real-world scenario, you would use a process manager.
npm start
echo "Deployment successful! RoboCoin is now running."