diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..fafafc4 --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -0,0 +1,21 @@ +name: Deploy SvelteKit + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Deploy with Docker + run: | + docker compose down + docker compose build + docker compose up -d + diff --git a/Dockerfile b/Dockerfile index a692c0e..b4237dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,28 @@ -# Use a Node.js Alpine image for the builder stage +# Builder stage FROM node:22-alpine AS builder WORKDIR /app -COPY package*.json ./ + +# Install deps for build +COPY package*.json . RUN npm ci + +# Copy source and build COPY . . RUN npm run build -RUN npm prune --production -# Use another Node.js Alpine image for the final stage + +# Final image FROM node:22-alpine WORKDIR /app -COPY --from=builder /app/build build/ -COPY --from=builder /app/node_modules node_modules/ -COPY package.json . + +# Copy only what's needed for runtime +COPY package.json ./ +COPY --from=builder /app/build ./build/ +COPY --from=builder /app/node_modules ./node_modules/ + +# Prune dev dependencies +RUN npm prune --production + EXPOSE 3000 ENV NODE_ENV=production -CMD [ "node", "build" ] - +CMD ["node", "build"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..281c1ff --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.8" + +services: + client: + build: . + container_name: client + restart: unless-stopped + ports: + - "3000:3000" + environment: + NODE_ENV: production