diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0a40e7d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,30 @@ +name: Build Docker images + +on: + push: + branches: ["main"] + +jobs: + build-and-push-dockerfile-image: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} # Make sure to add the secrets in your repository in -> Settings -> Secrets (Actions) -> New repository secret + password: ${{ secrets.DOCKERHUB_TOKEN }} # Make sure to add the secrets in your repository in -> Settings -> Secrets (Actions) -> New repository secret + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + # Make sure to replace with your own namespace and repository + tags: | + namespace/example:latest + platforms: linux/amd64 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0e0d48d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +# Use the official Bun image +FROM oven/bun:1 AS base + +# Set the working directory inside the container +WORKDIR /usr/src/app + +# Create a non-root user for security +RUN addgroup --system --gid 1001 sveltekit +RUN adduser --system --uid 1001 sveltekit + +# Copy package.json and bun.lockb (if available) +COPY package.json bun.lockb* ./ + +# Install dependencies (including dev dependencies for build) +RUN bun install --frozen-lockfile + +# Copy the source code +COPY . . + +# Prepare SvelteKit and build the application +RUN bun run prepare +RUN bun run build +RUN bun run db:migrate + +# Production stage +FROM oven/bun:1-slim AS production + +# Set working directory +WORKDIR /usr/src/app + +# Create non-root user +RUN addgroup --system --gid 1001 sveltekit +RUN adduser --system --uid 1001 sveltekit + +# Copy built application from base stage +COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/build ./build +COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/package.json ./package.json +COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/node_modules ./node_modules + +# Copy any additional files needed for runtime +COPY --from=base --chown=sveltekit:sveltekit /usr/src/app/static ./static + +# Switch to non-root user +USER sveltekit + +# Expose the port that the app runs on +EXPOSE 5173 + +# Set environment variables +ENV NODE_ENV=production +ENV PORT=5173 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD bun --version || exit 1 + +# Start the application +CMD ["bun", "./build/index.js"] diff --git a/packages/backend/convex/flows.ts b/packages/backend/convex/flows.ts index 6a8e8cd..0749140 100644 --- a/packages/backend/convex/flows.ts +++ b/packages/backend/convex/flows.ts @@ -891,6 +891,9 @@ export const getInstanceWithSteps = query({ startedAt: number | undefined; finishedAt: number | undefined; notes: string | undefined; + notesUpdatedBy: Id<'usuarios'> | undefined; + notesUpdatedByName: string | undefined; + notesUpdatedAt: number | undefined; dueDate: number | undefined; position: number; expectedDuration: number; @@ -929,6 +932,7 @@ export const getInstanceWithSteps = query({ }); } + const notesUpdater = step.notesUpdatedBy ? await ctx.db.get(step.notesUpdatedBy) : null; stepsWithDetails.push({ _id: step._id, _creationTime: step._creationTime, @@ -945,7 +949,7 @@ export const getInstanceWithSteps = query({ finishedAt: step.finishedAt, notes: step.notes, notesUpdatedBy: step.notesUpdatedBy, - notesUpdatedByName: step.notesUpdatedBy ? (await ctx.db.get(step.notesUpdatedBy))?.nome : undefined, + notesUpdatedByName: notesUpdater?.nome, notesUpdatedAt: step.notesUpdatedAt, dueDate: step.dueDate, position: flowStep?.position ?? 0,