diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..38d99da --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,91 @@ +name: Build Docker Package + +on: + push: + branches: + - master + tags: + - "v*" + workflow_dispatch: + +jobs: + docker-package: + runs-on: ubuntu-latest + env: + REGISTRY: git.hanhan.ltd + NODE_IMAGE: m.daocloud.io/docker.io/library/node:22 + NPM_REGISTRY: https://registry.npmmirror.com + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare image metadata + id: meta + shell: bash + run: | + repository="${GITHUB_REPOSITORY:-${{ gitea.repository }}}" + repository="$(printf '%s' "$repository" | tr '[:upper:]' '[:lower:]')" + image="${REGISTRY}/${repository}" + + sha="${GITHUB_SHA:-${{ gitea.sha }}}" + short_sha="${sha:0:12}" + ref="${GITHUB_REF:-${{ gitea.ref }}}" + + { + echo "image=${image}" + echo "tags<> "${GITHUB_OUTPUT}" + + - name: Login to Gitea container registry + env: + PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }} + PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} + GITEA_ACTOR: ${{ gitea.actor }} + shell: bash + run: | + username="${PACKAGE_USERNAME:-${GITEA_ACTOR}}" + + if [[ -z "${PACKAGE_TOKEN}" ]]; then + echo "PACKAGE_TOKEN secret is required to publish container packages." >&2 + echo "Create a Gitea personal access token with package write permission and save it as PACKAGE_TOKEN." >&2 + exit 1 + fi + + echo "${PACKAGE_TOKEN}" | docker login "${REGISTRY}" -u "${username}" --password-stdin + + - name: Build image + shell: bash + run: | + mapfile -t tags <<< "${{ steps.meta.outputs.tags }}" + + args=() + for tag in "${tags[@]}"; do + args+=(--tag "$tag") + done + + docker build \ + --build-arg "NODE_IMAGE=${NODE_IMAGE}" \ + --build-arg "NPM_REGISTRY=${NPM_REGISTRY}" \ + "${args[@]}" \ + . + + - name: Push image + shell: bash + run: | + mapfile -t tags <<< "${{ steps.meta.outputs.tags }}" + + for tag in "${tags[@]}"; do + docker push "$tag" + done diff --git a/Dockerfile b/Dockerfile index 6a99bd0..4f28559 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,10 @@ ARG NPM_REGISTRY=https://registry.npmmirror.com FROM ${NODE_IMAGE} AS deps WORKDIR /app -COPY package.json package-lock.json ./ -RUN npm config set registry ${NPM_REGISTRY} && npm ci +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ +RUN corepack enable \ + && pnpm config set registry ${NPM_REGISTRY} \ + && pnpm install --frozen-lockfile FROM ${NODE_IMAGE} AS builder WORKDIR /app @@ -26,8 +28,11 @@ ENV HOSTNAME=0.0.0.0 ENV PORT=3000 ENV AUDIO_DIRECTORY=/app/public/audio -COPY package.json package-lock.json ./ -RUN npm config set registry ${NPM_REGISTRY} && npm ci --omit=dev && npm cache clean --force +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ +RUN corepack enable \ + && pnpm config set registry ${NPM_REGISTRY} \ + && pnpm install --prod --frozen-lockfile \ + && pnpm store prune COPY --from=builder /app/.next ./.next COPY --from=builder /app/public ./public @@ -37,4 +42,4 @@ RUN mkdir -p /app/data /app/public/audio EXPOSE 3000 -CMD ["npm", "run", "start"] +CMD ["pnpm", "start"] diff --git a/package.json b/package.json index 90553cd..f89250d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.2.0", "private": true, "type": "module", + "packageManager": "pnpm@11.7.0", "scripts": { "dev": "next dev", "build": "next build",