diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d862f96 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c859b10 --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +# API key used by the CLI and the SDK +# Make sure your framework/tooling loads this file on startup to have it available for the SDK +XATA_API_KEY= +# Xata branch that will be used if there's not a xata branch with the same name as your git branch +XATA_BRANCH=main +XATA_FALLBACK_BRANCH=main +ENABLE_TRACK=false +NEXT_PUBLIC_ENABLE_CN_DOMAIN=false +NEXT_PUBLIC_REGION=GLOBAL +CN_STATIC_URL=www.furrycons.cn +SENTRY_DSN= +SENTRY_AUTH_TOKEN= +NEXT_PUBLIC_SENTRY_DSN= \ No newline at end of file diff --git a/.github/workflows/deploy-self-host.yml b/.github/workflows/deploy-self-host.yml new file mode 100644 index 0000000..60ddb4f --- /dev/null +++ b/.github/workflows/deploy-self-host.yml @@ -0,0 +1,86 @@ +# +name: Deploy To Selfhost Machine + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + branches: main + +jobs: + global-image-release: + runs-on: ubuntu-latest + environment: Prod + env: + XATA_API_KEY: ${{ secrets.XATA_API_KEY }} + XATA_FALLBACK_BRANCH: ${{ vars.XATA_FALLBACK_BRANCH }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + ENABLE_TRACK: ${{ vars.ENABLE_TRACK }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Create Env + run: | + touch .env + echo NEXT_PUBLIC_REGION="GLOBAL" >>.env + echo XATA_API_KEY="$XATA_API_KEY" >> .env + echo XATA_FALLBACK_BRANCH="$XATA_FALLBACK_BRANCH" >> .env + echo SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" >> .env + echo ENABLE_TRACK="$ENABLE_TRACK" >> .env + + - name: Login to ACR + uses: aliyun/acr-login@v1 + with: + login-server: https://registry.cn-hongkong.aliyuncs.com + username: "${{ secrets.REGISTRY_USERNAME }}" + password: "${{ secrets.REGISTRY_PASSWORD }}" + + - name: Build and push image + env: + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t registry.cn-hongkong.aliyuncs.com/fec/web:$IMAGE_TAG -t registry.cn-hongkong.aliyuncs.com/fec/web:latest . + docker push registry.cn-hongkong.aliyuncs.com/fec/web:$IMAGE_TAG + docker push registry.cn-hongkong.aliyuncs.com/fec/web:latest + + cn-image-release: + runs-on: ubuntu-latest + environment: Prod-CN + env: + XATA_API_KEY: ${{ secrets.XATA_API_KEY }} + XATA_FALLBACK_BRANCH: ${{ vars.XATA_FALLBACK_BRANCH }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + ENABLE_TRACK: ${{ vars.ENABLE_TRACK }} + NEXT_PUBLIC_ENABLE_CN_DOMAIN: true + CN_STATIC_URL: ${{vars.CN_STATIC_URL}} + SENTRY_DSN: ${{vars.SENTRY_DSN}} + NEXT_PUBLIC_SENTRY_DSN: ${{vars.SENTRY_DSN}} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Create Env + run: | + touch .env + echo NEXT_PUBLIC_REGION="CN" >>.env + echo XATA_API_KEY="$XATA_API_KEY" >> .env + echo XATA_FALLBACK_BRANCH="$XATA_FALLBACK_BRANCH" >> .env + echo SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" >> .env + echo ENABLE_TRACK="$ENABLE_TRACK" >> .env + echo NEXT_PUBLIC_ENABLE_CN_DOMAIN="true" >>.env + echo CN_STATIC_URL="$CN_STATIC_URL" >>.env + echo SENTRY_DSN="$SENTRY_DSN" >>.env + echo NEXT_PUBLIC_SENTRY_DSN="$NEXT_PUBLIC_SENTRY_DSN" >>.env + + - name: Login to ACR + uses: aliyun/acr-login@v1 + with: + login-server: https://registry.cn-hongkong.aliyuncs.com + username: "${{ secrets.REGISTRY_USERNAME }}" + password: "${{ secrets.REGISTRY_PASSWORD }}" + + - name: Build and push image + env: + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t registry.cn-hongkong.aliyuncs.com/fec/cn-web:$IMAGE_TAG -t registry.cn-hongkong.aliyuncs.com/fec/cn-web:latest . + docker push registry.cn-hongkong.aliyuncs.com/fec/cn-web:$IMAGE_TAG + docker push registry.cn-hongkong.aliyuncs.com/fec/cn-web:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d92976b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,68 @@ +FROM node:18-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* .yarnrc.yml package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then corepack enable&&yarn --immutable; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi + + +# Rebuild the source code only when needed +FROM base AS builder +RUN apk add --no-cache git +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN corepack enable&&yarn build + +# If using npm comment out above and use below instead +# RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/next-config-js/output +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..089cade --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3" +services: + global-web: + image: registry-vpc.cn-hongkong.aliyuncs.com/fec/web:latest + restart: always + environment: + - NODE_ENV=production + env_file: + - stack.env + networks: + static-network: + ipv4_address: 10.0.0.9 + cn-web: + image: registry-vpc.cn-hongkong.aliyuncs.com/fec/cn-web:latest + restart: always + environment: + - NODE_ENV=production + env_file: + - stack.env + networks: + static-network: + ipv4_address: 10.0.0.10 +networks: + static-network: + external: true \ No newline at end of file diff --git a/next-sitemap.config.js b/next-sitemap.config.js index b05ebf1..c98988c 100644 --- a/next-sitemap.config.js +++ b/next-sitemap.config.js @@ -1,17 +1,5 @@ /** @type {import('next-sitemap').IConfig} */ module.exports = { siteUrl: "https://www.furryeventchina.com", - generateRobotsTxt: true, // (optional) - outDir: "./out", - alternateRefs: [ - { - href: "https://www.furrycons.cn", - hreflang: "zh-cn", - }, - { - href: "https://cn.furryeventchina.com", - hreflang: "zh", - }, - ], - // ...other options + generateRobotsTxt: true, }; diff --git a/next.config.js b/next.config.js index 47ae53d..052647e 100644 --- a/next.config.js +++ b/next.config.js @@ -16,7 +16,7 @@ const gitRevisionPlugin = new GitRevisionPlugin(); /** @type {import('next').NextConfig} */ const nextConfig = { - output: "export", + output: "standalone", reactStrictMode: true, images: { unoptimized: false, diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 9bfd58a..649ba7c 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -2,6 +2,11 @@ import { Html, Head, Main, NextScript } from "next/document"; import Script from "next/script"; const isEnableTrack = process.env.ENABLE_TRACK === "true"; +console.log( + "ENABLE_TRACK", + process.env.ENABLE_TRACK, + typeof process.env.ENABLE_TRACK +); export default function Document() { return (