From 2636c58d37b3cadc4b9b3cce5c159a99b551ad36 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 30 Nov 2025 01:13:31 +0800 Subject: [PATCH] :hammer: Add dockerfile and github actions --- .dockerignore | 1 + .github/workflows/publish.yml | 41 +++++++++++++++++++++++++++++++++++ Dockerfile | 32 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7ee5d88 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,41 @@ +name: Docker Publish + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/floating-island + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..94448f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Stage 1: Build the application +FROM oven/bun:1 as builder +WORKDIR /app + +# Copy dependency definition files +COPY package.json ./ + +# Install dependencies +RUN bun install + +# Copy the rest of the application code +COPY . . + +# Build the Nuxt application +RUN bun run build + +# Stage 2: Create the production image +FROM node:20-slim as runner +WORKDIR /app + +# Copy the built output from the builder stage +COPY --from=builder /app/.output ./.output + +# Set environment variables for the Nuxt server +ENV HOST=0.0.0.0 +ENV PORT=3000 + +# Expose the port the app runs on +EXPOSE 3000 + +# The command to run the application +CMD ["node", ".output/server/index.mjs"]