diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..aa68807 --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -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." diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7154ed --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file