diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index bd87625..d868c18 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,9 +2,7 @@ name: CI/CD on: push: - branches: - - "main" - - "feat-user-manage" + branches: ["main", "feat-user-manage"] workflow_dispatch: jobs: @@ -21,8 +19,8 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Build and push id: docker_build uses: docker/build-push-action@v4 @@ -31,7 +29,7 @@ jobs: push: true platforms: linux/amd64 tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} cache-from: type=gha cache-to: type=gha,mode=max @@ -44,19 +42,19 @@ jobs: - name: Login to ACR uses: aliyun/acr-login@v1 with: - login-server: https://registry.cn-guangzhou.aliyuncs.com - username: "${{ secrets.REGISTRY_USERNAME }}" + login-server: https://${{ vars.REGISTRY_ADDRESS }} + username: "${{ vars.REGISTRY_USERNAME }}" password: "${{ secrets.REGISTRY_PASSWORD }}" - name: Build and push image run: | - docker build -t registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} . - docker push registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} + docker build -t ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest . + docker push ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest deploy: name: Deploy needs: [build_docker, build_docker_acr] runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' # Only run deploy if on main branch + if: github.ref == 'refs/heads/main' steps: - name: SSH To Host uses: appleboy/ssh-action@v1.0.1 @@ -66,5 +64,5 @@ jobs: key: ${{ secrets.SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | - cd ${{ secrets.PROJ_PATH }} + cd ${{ secrets.PROJECT_PATH }} sudo bash ./deploy.sh diff --git a/LICENCE b/LICENSE old mode 100755 new mode 100644 similarity index 100% rename from LICENCE rename to LICENSE diff --git a/README.md b/README.md index b695207..2cd9a06 100755 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ In order to make it easier and faster for KLPBBS users to fill out survey, KLPBB Using this system, KLPBBS users can quickly log in using their KLPBBS account without having to repeatedly register or create a new account, greatly optimizing the user experience -## Licence +## License -This project is licensed under the MIT license, please refer to [LICENCE](./LICENSE) for details +This project is licensed under the MIT license, please refer to [LICENSE](./LICENSE) for details ## Contribute diff --git a/dockerfile b/dockerfile index 553457a..932ab5c 100644 --- a/dockerfile +++ b/dockerfile @@ -1,10 +1,46 @@ -FROM node:21-alpine3.18 +FROM node:18-alpine AS base +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app -ADD . . +COPY package.json yarn.lock ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi -RUN yarn install && \ - yarn build +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + else echo "Lockfile not found." && exit 1; \ + fi + +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + +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 -CMD [ "yarn", "start" ] \ No newline at end of file +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] \ No newline at end of file