From 50846c91c29844b68e090ea9a5483c06234af23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Fri, 9 May 2025 22:49:45 +0800 Subject: [PATCH] feat: add Docker configuration files and self-deployment workflow --- .dockerignore | 7 +++++++ .github/workflows/self_deploy.yml | 34 +++++++++++++++++++++++++++++++ Dockerfile | 28 +++++++++++++++++++++++++ docker-compose.yml | 15 ++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/self_deploy.yml create mode 100755 Dockerfile create mode 100755 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8936bf2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.nuxt +.output +.next +dist +.git +.env \ No newline at end of file diff --git a/.github/workflows/self_deploy.yml b/.github/workflows/self_deploy.yml new file mode 100644 index 0000000..0e36b70 --- /dev/null +++ b/.github/workflows/self_deploy.yml @@ -0,0 +1,34 @@ +name: Server Deployment Request +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + + env: + DEPLOY_URL: ${{ secrets.DEPLOY_URL }} + + steps: + - name: Send deployment request + id: deploy-request + run: | + echo "Sending deployment request to server..." + RESPONSE=$(curl -X POST \ + -H "Content-Type: application/json" \ + --http1.1 \ + --fail \ + --silent \ + --show-error \ + "${{ secrets.DEPLOY_URL }}" || echo "Failed to send request") + + if [ $? -eq 0 ]; then + echo "Deployment request sent successfully" + echo "Response: $RESPONSE" + else + echo "Error sending deployment request" + exit 1 + fi \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..0a7981e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Building process +FROM oven/bun:latest as builder +WORKDIR /app +# Copy dependency files +COPY package.json bun.lockb ./ +RUN bun install --frozen-lockfile +# Copy source files +COPY . . +# Framework-specific build command +RUN bun run build + +# Production image +FROM oven/bun:latest +WORKDIR /app +# Copy built assets and dependencies +COPY --from=builder /app/.output /app/.output +COPY --from=builder /app/dist /app/dist +COPY --from=builder /app/build /app/build +COPY --from=builder /app/package.json /app/package.json +COPY --from=builder /app/bun.lockb /app/bun.lockb +# If you have customized your output directory, please add your custom one here, or just remove it. :) + +# Install production dependencies only +RUN bun install --production --frozen-lockfile + +EXPOSE 3000 +# Map the prod command to start via editing your package.json like in the example.package.json +CMD ["bun", "run", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 0000000..49f5c13 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3.8' + +services: + app: + build: . + ports: + - "3000:3000" + environment: + - NODE_ENV=production + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000"] + interval: 30s + timeout: 10s + retries: 3 \ No newline at end of file