-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): added Dockerfiles (#57)
- Loading branch information
1 parent
31e0ef5
commit 23dee2b
Showing
11 changed files
with
1,806 additions
and
1,263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules | ||
.pnp | ||
.pnp.* | ||
*.log | ||
dist | ||
*.local | ||
.env | ||
.git | ||
db.sqlite | ||
local-documents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Release new versions | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
docker-release: | ||
name: Release Docker images | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get release version from tag | ||
if: ${{ github.event_name == 'push' }} | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | ||
|
||
- name: Get release version from input | ||
if: ${{ github.event_name == 'workflow_dispatch' }} | ||
run: echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV | ||
|
||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push root Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile | ||
platforms: linux/amd64,linux/arm64,linux/arm/v7 | ||
push: true | ||
tags: | | ||
corentinth/papra:latest-root | ||
corentinth/papra:${{ env.RELEASE_VERSION }}-root | ||
ghcr.io/corentinth/papra:latest-root | ||
ghcr.io/corentinth/papra:${{ env.RELEASE_VERSION }}-root | ||
- name: Build and push rootless Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile.rootless | ||
platforms: linux/amd64,linux/arm64,linux/arm/v7 | ||
push: true | ||
tags: | | ||
corentinth/papra:latest-rootless | ||
corentinth/papra:${{ env.RELEASE_VERSION }}-rootless | ||
ghcr.io/corentinth/papra:latest-rootless | ||
ghcr.io/corentinth/papra:${{ env.RELEASE_VERSION }}-rootless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/papra-server/src/modules/app/middlewares/assets.middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { ServerInstance } from '../server.types'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { serveStatic } from '@hono/node-server/serve-static'; | ||
import { memoize } from 'lodash-es'; | ||
import { getConfig } from '../../config/config.models'; | ||
|
||
const getIndexContent = memoize(async () => { | ||
const index = await readFile('public/index.html', 'utf-8'); | ||
|
||
return index; | ||
}); | ||
|
||
export function registerAssetsMiddleware({ app }: { app: ServerInstance }) { | ||
app | ||
.use( | ||
'*', | ||
async (context, next) => { | ||
const { config } = getConfig({ context }); | ||
|
||
if (!config.server.servePublicDir) { | ||
return next(); | ||
} | ||
|
||
return serveStatic({ | ||
root: './public', | ||
index: 'unexisting-file', // Disable index.html fallback to let the next middleware handle it | ||
})(context, next); | ||
}, | ||
) | ||
.use( | ||
'*', | ||
async (context, next) => { | ||
const { config } = getConfig({ context }); | ||
|
||
if (!config.server.servePublicDir) { | ||
return next(); | ||
} | ||
|
||
if (context.req.path.startsWith('/api/')) { | ||
return next(); | ||
} | ||
|
||
const indexHtmlContent = await getIndexContent(); | ||
|
||
return context.html(indexHtmlContent); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Base stage with pnpm | ||
FROM node:22-slim AS base | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable | ||
|
||
# Build stage | ||
FROM base AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY pnpm-lock.yaml ./ | ||
COPY pnpm-workspace.yaml ./ | ||
COPY apps/papra-client/package.json apps/papra-client/package.json | ||
COPY apps/papra-server/package.json apps/papra-server/package.json | ||
|
||
RUN pnpm install --frozen-lockfile --ignore-scripts | ||
|
||
COPY . . | ||
|
||
RUN pnpm --filter @papra/papra-app-client run build && \ | ||
pnpm --filter @papra/papra-app-server run build | ||
|
||
RUN pnpm deploy --filter=@papra/papra-app-server --prod /prod/papra-server | ||
|
||
FROM base | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /prod/papra-server ./ | ||
COPY --from=build /app/apps/papra-client/dist ./public | ||
|
||
EXPOSE 1221 | ||
|
||
ENV SERVER_SERVE_PUBLIC_DIR=true | ||
ENV DATABASE_URL=file:./app-data/db/db.sqlite | ||
ENV DOCUMENT_STORAGE_FILESYSTEM_ROOT=./app-data/documents | ||
|
||
RUN mkdir -p ./app-data/db ./app-data/documents | ||
|
||
CMD ["pnpm", "start:with-migrations"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Base stage with pnpm | ||
FROM node:22-slim AS base | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable | ||
|
||
# Build stage | ||
FROM base AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY pnpm-lock.yaml ./ | ||
COPY pnpm-workspace.yaml ./ | ||
COPY apps/papra-client/package.json apps/papra-client/package.json | ||
COPY apps/papra-server/package.json apps/papra-server/package.json | ||
|
||
RUN pnpm install --frozen-lockfile --ignore-scripts | ||
|
||
COPY . . | ||
|
||
RUN pnpm --filter @papra/papra-app-client run build && \ | ||
pnpm --filter @papra/papra-app-server run build | ||
|
||
RUN pnpm deploy --filter=@papra/papra-app-server --prod /prod/papra-server | ||
|
||
FROM base | ||
|
||
# Create a non-root user and group | ||
RUN groupadd -r nonroot && useradd -r -g nonroot nonroot && \ | ||
mkdir -p /home/nonroot/.cache/node/corepack && \ | ||
chown -R nonroot:nonroot /home/nonroot | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /prod/papra-server ./ | ||
COPY --from=build /app/apps/papra-client/dist ./public | ||
|
||
RUN mkdir -p ./app-data/db ./app-data/documents && chown -R nonroot:nonroot /app | ||
|
||
# Switch to nonroot user | ||
USER nonroot | ||
|
||
EXPOSE 1221 | ||
|
||
ENV SERVER_SERVE_PUBLIC_DIR=true | ||
ENV DATABASE_URL=file:./app-data/db/db.sqlite | ||
ENV DOCUMENT_STORAGE_FILESYSTEM_ROOT=./app-data/documents | ||
|
||
|
||
CMD ["pnpm", "start:with-migrations"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,9 @@ | |
"description": "", | ||
"keywords": [], | ||
"author": "", | ||
"packageManager": "[email protected]" | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"app:docker:build": "docker build -t papra -f docker/Dockerfile .", | ||
"app:docker:build:rootless": "docker build -t papra-rootless -f docker/Dockerfile.rootless ." | ||
} | ||
} |
Oops, something went wrong.