feat(ci): add automated SSH deployment workflow
Some checks failed
Deploy Flowstate to VPS / deploy (push) Failing after 9s
Some checks failed
Deploy Flowstate to VPS / deploy (push) Failing after 9s
This commit is contained in:
parent
949dde7aba
commit
83ff5852bd
2 changed files with 73 additions and 0 deletions
36
.forgejo/workflows/deploy.yml
Normal file
36
.forgejo/workflows/deploy.yml
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
name: Deploy Flowstate to VPS
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Trigger Build & Deploy via SSH
|
||||||
|
uses: https://github.com/appleboy/ssh-action@v1.0.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.VPS_HOST }}
|
||||||
|
username: ${{ secrets.VPS_USER }}
|
||||||
|
key: ${{ secrets.VPS_SSH_KEY }}
|
||||||
|
port: ${{ secrets.VPS_PORT }}
|
||||||
|
script_stop: true
|
||||||
|
script: |
|
||||||
|
echo "Starting deployment..."
|
||||||
|
cd /opt/containers/projects/flowstate
|
||||||
|
|
||||||
|
echo "Pulling latest code..."
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
echo "Applying DB migrations..."
|
||||||
|
docker compose run --rm flowstate sh -c "npx drizzle-kit push --config=drizzle.config.ts"
|
||||||
|
|
||||||
|
echo "Rebuilding Docker containers..."
|
||||||
|
docker compose up -d --build
|
||||||
|
|
||||||
|
echo "Cleaning up unused Docker images..."
|
||||||
|
docker image prune -f
|
||||||
|
|
||||||
|
echo "Deployment completed successfully."
|
||||||
37
Dockerfile
Normal file
37
Dockerfile
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# 1. Install dependencies
|
||||||
|
FROM node:20-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# 2. Build the application
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# 3. Run production image (Node.js server)
|
||||||
|
FROM node:20-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=3002
|
||||||
|
|
||||||
|
# Create a system user for enhanced security
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
# Copy public assets and standalone build output
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# Create analytics data directory and assign proper permissions
|
||||||
|
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3002
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
Loading…
Reference in a new issue