From 9bfe565da37815d4b0588d8d7701e8a54e348a20 Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Fri, 5 Jan 2024 14:33:44 +0330 Subject: [PATCH] Bugs fixed + docker added --- .dockerignore | 7 ++++ .github/workflows/build.yml | 49 +++++++++++++++++++++++++ Dockerfile | 59 ++++++++++++++++++++++++++++++ app/layout.tsx | 2 +- app/page.tsx | 1 - components/AdminCategories.tsx | 9 ++--- components/AdminOrganizations.tsx | 6 +-- components/ComplainsDetails.tsx | 13 ++++--- components/ControllerDashboard.tsx | 14 +++++-- components/Footer.tsx | 20 +++++----- components/InspectorOperations.tsx | 13 +++++-- components/LineChart.tsx | 2 +- components/Login.tsx | 9 ++++- components/NavbarPanel.tsx | 2 +- components/Reports.tsx | 15 +++++--- components/ReportsController.tsx | 8 ---- components/TableController.tsx | 11 +++++- components/Verify.tsx | 1 - components/VerticalChart.tsx | 8 ++-- constants/index.tsx | 41 +++++++++++++-------- docker-compose.yml | 8 ++++ utils/adminApi.ts | 2 +- 22 files changed, 230 insertions(+), 70 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c550055 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b25cb03 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: build + +on: + push: + tags: + - "v*.*.*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + ${{ secrets.DOCKER_REGISTRY }}oyoon-admin + + # generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ secrets.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + context: "{{defaultContext}}" + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b6a0e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +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* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + 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 +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 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 + +# 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 6679 + +ENV PORT 6679 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 6803ed2..cc47d0b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -9,7 +9,7 @@ import { Toaster as SonnerToaster } from "@/components/ui/sonner"; const inter = Inter({ subsets: ["latin"] }); export const metadata: Metadata = { - title: "سوت زنی", + title: "عیون", description: "Generated by create next app", }; diff --git a/app/page.tsx b/app/page.tsx index 1c971d5..fe33cda 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,5 +1,4 @@ import Image from "next/image"; -import CitizenLogin from "../components/CitizenLogin"; import Login from "@/components/Login"; export default function Home() { diff --git a/components/AdminCategories.tsx b/components/AdminCategories.tsx index 367e2fc..27110e0 100644 --- a/components/AdminCategories.tsx +++ b/components/AdminCategories.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useState, useRef, useEffect } from "react"; -import { useMutation, useQuery, RefetchOptions } from "@tanstack/react-query"; +import { useMutation, useQuery } from "@tanstack/react-query"; import { GetAllCategories, GetSingleCategory, @@ -11,7 +11,6 @@ import { } from "@/utils/adminApi"; import { FaRegEdit } from "react-icons/fa"; import { IoMdClose } from "react-icons/io"; -import { RiDeleteBin6Line } from "react-icons/ri"; import { useRouter } from "next/navigation"; import { ThreeDots } from "react-loader-spinner"; import { Button } from "@/components/ui/button"; @@ -232,7 +231,7 @@ export default function AdminCategories() { console.log(data); } return ( -
+
{/* 1 */} @@ -418,7 +417,7 @@ export default function AdminCategories() { return (

@@ -435,7 +434,7 @@ export default function AdminCategories() {

{ DeleteCatMutation.mutate({ id: item.id, diff --git a/components/AdminOrganizations.tsx b/components/AdminOrganizations.tsx index 8449204..6b0d1ac 100644 --- a/components/AdminOrganizations.tsx +++ b/components/AdminOrganizations.tsx @@ -234,7 +234,7 @@ export default function AdminOrganizations() { console.log(data); } return ( -
+
{/* 1 */} @@ -421,7 +421,7 @@ export default function AdminOrganizations() { return (

@@ -438,7 +438,7 @@ export default function AdminOrganizations() {

{ DeleteOrgMutation.mutate({ id: item.id, diff --git a/components/ComplainsDetails.tsx b/components/ComplainsDetails.tsx index 05f5bd0..f2a9b4a 100644 --- a/components/ComplainsDetails.tsx +++ b/components/ComplainsDetails.tsx @@ -110,7 +110,7 @@ export default function ComplainsDetails({ } }; - const downloadFile = (base64Data, fileName, fileType) => { + const downloadFile = (base64Data: any, fileName: any, fileType: any) => { const blob = b64toBlob(base64Data, fileType); const blobUrl = URL.createObjectURL(blob); @@ -122,7 +122,7 @@ export default function ComplainsDetails({ URL.revokeObjectURL(blobUrl); }; - const b64toBlob = (b64Data, contentType = "", sliceSize = 512) => { + const b64toBlob = (b64Data: any, contentType = "", sliceSize = 512) => { const byteCharacters = atob(b64Data); const byteArrays = []; @@ -318,9 +318,12 @@ export default function ComplainsDetails({ )}
- {item?.media.map((item: any) => { + {item?.media.map((item: any, index: number) => { return ( -
+ {/* Left */} diff --git a/components/ControllerDashboard.tsx b/components/ControllerDashboard.tsx index a75946a..3e2ecdf 100644 --- a/components/ControllerDashboard.tsx +++ b/components/ControllerDashboard.tsx @@ -24,15 +24,21 @@ export default function ControllerDashboard() { {/* Lg Show */}
- {data?.singletons.map((item: any) => { - return ; + {data?.singletons.map((item: any, index: number) => { + return ( + + ); })}
- {data?.charts.map((item: any) => { + {data?.charts.map((item: any, index: number) => { return ( - + ); })}
diff --git a/components/Footer.tsx b/components/Footer.tsx index 722ae5f..73276c6 100644 --- a/components/Footer.tsx +++ b/components/Footer.tsx @@ -11,20 +11,20 @@ export default function Footer() { //