feat: add Docker support and enhance environment configuration

- Introduce .dockerignore for Docker build optimization
- Add Dockerfile for containerization setup
- Update .env.example to clear Sentry variables and rename HOST to TELEGRAM_HOST
- Modify astro.config.mjs to conditionally exclude SSR dependencies in Docker builds
- Adjust postinstall script to safely handle missing .git directory
- Refactor telegram host retrieval for clarity and consistency
This commit is contained in:
ccbikai
2024-08-31 13:41:16 +08:00
parent a7dd0cd486
commit 2b9807bd89
7 changed files with 49 additions and 15 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.DS_Store
node_modules
dist
.git
.gitignore
*.md

View File

@@ -17,9 +17,9 @@ HEADER_INJECT=HEADER_INJECT
NO_FOLLOW=false
NO_INDEX=false
SENTRY_AUTH_TOKEN=SENTRY_AUTH_TOKEN
SENTRY_DSN=SENTRY_DSN
SENTRY_PROJECT=SENTRY_PROJECT
SENTRY_AUTH_TOKEN=
SENTRY_DSN=
SENTRY_PROJECT=
HOST=telegram.dog
TELEGRAM_HOST=telegram.dog
STATIC_PROXY=""

27
Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
FROM node:lts-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
# FROM base AS prod-deps
# RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base AS build-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM build-deps AS build
COPY . .
RUN export $(cat .env.example) && export DOCKER=true && pnpm run build
FROM base AS runtime
# COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD node ./dist/server/entry.mjs

View File

@@ -48,6 +48,7 @@ export default defineConfig({
],
vite: {
ssr: {
noExternal: process.env.DOCKER ? !!process.env.DOCKER : undefined,
external: [
...adapterProvider === 'cloudflare_pages'
? [

View File

@@ -12,13 +12,11 @@
"astro": "astro",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postinstall": "simple-git-hooks"
"postinstall": "test -d .git && simple-git-hooks || true"
},
"dependencies": {
"@astrojs/rss": "^4.0.7",
"@sentry/astro": "^8.26.0",
"astro": "^4.14.5",
"astro-seo": "^0.8.4",
"cheerio": "1.0.0-rc.12",
"dayjs": "^1.11.13",
"flourite": "^1.3.0",
@@ -35,7 +33,9 @@
"@astrojs/node": "^8.3.3",
"@astrojs/vercel": "^7.8.0",
"@types/prismjs": "^1.26.4",
"astro": "^4.14.5",
"astro-eslint-parser": "^1.0.2",
"astro-seo": "^0.8.4",
"autoprefixer": "^10.4.20",
"cssnano": "^7.0.5",
"eslint": "9.5.0",

14
pnpm-lock.yaml generated
View File

@@ -14,12 +14,6 @@ importers:
'@sentry/astro':
specifier: ^8.26.0
version: 8.26.0(astro@4.14.5(@types/node@22.0.0)(rollup@4.21.0)(typescript@5.5.4))
astro:
specifier: ^4.14.5
version: 4.14.5(@types/node@22.0.0)(rollup@4.21.0)(typescript@5.5.4)
astro-seo:
specifier: ^0.8.4
version: 0.8.4(prettier-plugin-astro@0.14.1)(prettier@3.3.3)(typescript@5.5.4)
cheerio:
specifier: 1.0.0-rc.12
version: 1.0.0-rc.12
@@ -63,9 +57,15 @@ importers:
'@types/prismjs':
specifier: ^1.26.4
version: 1.26.4
astro:
specifier: ^4.14.5
version: 4.14.5(@types/node@22.0.0)(rollup@4.21.0)(typescript@5.5.4)
astro-eslint-parser:
specifier: ^1.0.2
version: 1.0.2(typescript@5.5.4)
astro-seo:
specifier: ^0.8.4
version: 0.8.4(prettier-plugin-astro@0.14.1)(prettier@3.3.3)(typescript@5.5.4)
autoprefixer:
specifier: ^10.4.20
version: 10.4.20(postcss@8.4.41)
@@ -3251,7 +3251,7 @@ packages:
hasBin: true
mime@3.0.0:
resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==}
resolution: {integrity: sha1-s3RVDco6DBhEOwyVCmpY8ZMc96c=}
engines: {node: '>=10.0.0'}
hasBin: true

View File

@@ -183,7 +183,7 @@ export async function getChannelInfo(Astro, { before = '', after = '', q = '', t
}
// Where t.me can also be telegram.me, telegram.dog
const host = getEnv(import.meta.env, Astro, 'HOST') ?? 't.me'
const host = getEnv(import.meta.env, Astro, 'TELEGRAM_HOST') ?? 't.me'
const channel = getEnv(import.meta.env, Astro, 'CHANNEL')
const staticProxy = getEnv(import.meta.env, Astro, 'STATIC_PROXY') ?? '/static/'