Skip to content

update dockerfile

update dockerfile #33

Workflow file for this run

name: Deploy
on:
push:
branches:
- feat-add-admin-panel
permissions:
contents: write
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SHADOW_DATABASE_URL: ${{ secrets.SHADOW_DATABASE_URL }}
DATABASE_SCHEMA: ${{ secrets.DATABASE_SCHEMA }}
NUXT_PUBLIC_GITHUB_OWNER: ${{ secrets.NUXT_PUBLIC_GITHUB_OWNER }}
NUXT_PUBLIC_GITHUB_ADMIN_TOKEN: ${{ secrets.NUXT_PUBLIC_GITHUB_ADMIN_TOKEN }}
NUXT_PUBLIC_GITHUB_REPO: ${{ secrets.NUXT_PUBLIC_GITHUB_REPO }}
ADMIN_USER: ${{ secrets.ADMIN_USER }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
jobs:
deploy:
runs-on: ubuntu-latest
container:
image: node:20-bullseye # 指定带有 OpenSSL 3.0.x 的镜像
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: npm install
- name: Generate Prisma Client
run: npx prisma generate
- name: Run migrations
run: npx prisma migrate deploy
- name: Build application
run: npm run build
- name: Create deployment package
run: |
tar czf deploy.tar.gz .output
- name: Copy files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: "deploy.tar.gz"
target: "/www/wwwroot/aipan-netdisk-search"
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /www/wwwroot/aipan-netdisk-search
# Extract files
echo "Extracting files..."
tar xzf deploy.tar.gz
rm deploy.tar.gz
# Create PM2 configuration
echo "Creating ecosystem.config.cjs..."
cat > ecosystem.config.cjs << EOL
module.exports = {
apps: [
{
name: "aipan-netdisk-search",
port: "3000",
exec_mode: "cluster",
instances: "max",
script: "./.output/server/index.mjs",
watch: false,
max_memory_restart: "1G",
env_production: {
NODE_ENV: "production",
DATABASE_URL: "${{ secrets.DATABASE_URL }}",
SHADOW_DATABASE_URL: "${{ secrets.SHADOW_DATABASE_URL }}",
DATABASE_SCHEMA: "${{ secrets.DATABASE_SCHEMA }}",
NUXT_PUBLIC_GITHUB_OWNER: "${{ secrets.NUXT_PUBLIC_GITHUB_OWNER }}",
NUXT_PUBLIC_GITHUB_ADMIN_TOKEN: "${{ secrets.NUXT_PUBLIC_GITHUB_ADMIN_TOKEN }}",
NUXT_PUBLIC_GITHUB_REPO: "${{ secrets.NUXT_PUBLIC_GITHUB_REPO }}",
ADMIN_USER: "${{ secrets.ADMIN_USER }}",
ADMIN_PASSWORD: "${{ secrets.ADMIN_PASSWORD }}",
ADMIN_EMAIL: "${{ secrets.ADMIN_EMAIL }}",
JWT_SECRET: "${{ secrets.JWT_SECRET }}"
}
}
]
};
EOL
# Start/Reload application with health check
echo "Starting application with PM2..."
if pm2 list | grep -q "aipan-netdisk-search"; then
echo "Reloading existing PM2 process..."
pm2 reload ecosystem.config.cjs --env production
else
echo "Starting new PM2 process..."
pm2 start ecosystem.config.cjs --env production
fi
# Wait for application to start and perform health check
echo "Performing health check..."
sleep 5
if curl -s http://localhost:3000 > /dev/null; then
echo "Application started successfully!"
else
echo "Application failed to start. Checking logs..."
pm2 logs aipan-netdisk-search --lines 50
exit 1
fi