Compare commits
9
Commits
89012c215f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
646d6d326d | ||
|
|
cb8d4aeed3 | ||
|
|
04da7c325b | ||
|
|
8eefce6534 | ||
|
|
e4f0d5bca1 | ||
|
|
746e6e57be | ||
|
|
2a85485de4 | ||
|
|
db97576fc5 | ||
|
|
669c2027b9 |
-80
@@ -1,80 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: lint frontend
|
||||
image: node:20-alpine
|
||||
commands:
|
||||
- npm install
|
||||
- npm run lint
|
||||
|
||||
- name: build and push frontend
|
||||
image: docker:24
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
path: /opt/app
|
||||
commands:
|
||||
- docker build
|
||||
-t 172.17.0.1:5000/eu:latest
|
||||
-f ./Dockerfile
|
||||
.
|
||||
- docker push 172.17.0.1:5000/eu:latest
|
||||
|
||||
- name: deploy
|
||||
image: docker:24
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
path: /opt/app
|
||||
environment:
|
||||
PUBLIC_URL:
|
||||
from_secret: PUBLIC_URL
|
||||
DATABASE_URL:
|
||||
from_secret: DATABASE_URL
|
||||
KOTOSOFT_ID_API_PUBLIC_URL:
|
||||
from_secret: KOTOSOFT_ID_API_PUBLIC_URL
|
||||
KOTOSOFT_ID_API_URL:
|
||||
from_secret: KOTOSOFT_ID_API_URL
|
||||
KOTOSOFT_CLIENT_ID:
|
||||
from_secret: KOTOSOFT_CLIENT_ID
|
||||
KOTOSOFT_CLIENT_SECRET:
|
||||
from_secret: KOTOSOFT_CLIENT_SECRET
|
||||
JWT_SECRET:
|
||||
from_secret: JWT_SECRET
|
||||
MINIO_ACCESS_KEY:
|
||||
from_secret: MINIO_ACCESS_KEY
|
||||
MINIO_SECRET_KEY:
|
||||
from_secret: MINIO_SECRET_KEY
|
||||
MINIO_PUBLIC_URL:
|
||||
from_secret: MINIO_PUBLIC_URL
|
||||
VIRTUAL_HOST:
|
||||
from_secret: API_DOMAIN
|
||||
LETSENCRYPT_HOST:
|
||||
from_secret: API_DOMAIN
|
||||
LETSENCRYPT_EMAIL:
|
||||
from_secret: LETSENCRYPT_EMAIL
|
||||
DOMAIN:
|
||||
from_secret: DOMAIN
|
||||
commands:
|
||||
- apk add --no-cache docker-cli-compose
|
||||
- mkdir -p /opt/app
|
||||
- cp docker-compose.yml /opt/app/docker-compose.yml
|
||||
- cd /opt/app
|
||||
- docker compose -p eu pull
|
||||
- docker compose -p eu up -d --remove-orphans
|
||||
|
||||
volumes:
|
||||
- name: dockersock
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
host:
|
||||
path: /opt/drone/eu
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
@@ -45,3 +45,5 @@ next-env.d.ts
|
||||
|
||||
/lib/generated/prisma
|
||||
.prisma/
|
||||
|
||||
docker-compose.yml
|
||||
+2
-1
@@ -17,7 +17,8 @@ COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
COPY --from=builder /app/next.config.ts ./next.config.ts
|
||||
RUN npm prune --omit=dev
|
||||
EXPOSE 80
|
||||
USER node
|
||||
EXPOSE 3000
|
||||
CMD ["npm", "start", "--", "-p", "3000", "-H", "0.0.0.0"]
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget -q --spider http://localhost:3000/ || exit 1
|
||||
@@ -0,0 +1,5 @@
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
services:
|
||||
eu:
|
||||
image: 172.17.0.1:5000/eu:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PUBLIC_URL: ${PUBLIC_URL}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
|
||||
KOTOSOFT_ID_API_PUBLIC_URL: ${KOTOSOFT_ID_API_PUBLIC_URL}
|
||||
KOTOSOFT_ID_API_URL: ${KOTOSOFT_ID_API_URL}
|
||||
KOTOSOFT_CLIENT_ID: ${KOTOSOFT_CLIENT_ID}
|
||||
KOTOSOFT_CLIENT_SECRET: ${KOTOSOFT_CLIENT_SECRET}
|
||||
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
SESSION_MAX_AGE: 604800
|
||||
|
||||
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
|
||||
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
|
||||
MINIO_PUBLIC_URL: ${MINIO_PUBLIC_URL}
|
||||
|
||||
VIRTUAL_HOST: ${DOMAIN}
|
||||
VIRTUAL_PORT: 3000
|
||||
LETSENCRYPT_HOST: ${DOMAIN}
|
||||
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
|
||||
expose:
|
||||
- "3000"
|
||||
networks:
|
||||
- proxy
|
||||
- eu_net
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
eu_net:
|
||||
external: true
|
||||
+37
-12
@@ -1,29 +1,42 @@
|
||||
import crypto from "crypto";
|
||||
import sharp from "sharp";
|
||||
import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
|
||||
import { AppError } from "@/lib/action-result";
|
||||
import { getMinioClient } from "@/lib/minio";
|
||||
import { BUCKET, getInternalClient, getPublicClient } from "@/lib/storage";
|
||||
|
||||
const BUCKET = "uploads";
|
||||
const MAX_FILE_SIZE = 5 * 1024 * 1024;
|
||||
const ALLOWED_INPUT_FORMATS = new Set(["jpeg", "png", "webp"]);
|
||||
|
||||
export async function uploadImage(file: File, directory: string, options: { maxWidth?: number; maxHeight?: number; fit?: "inside" | "cover" }): Promise<string> {
|
||||
const DIRECTORY_RE = /^[a-z0-9][a-z0-9_-]*(\/[a-z0-9][a-z0-9_-]*)*$/;
|
||||
const KEY_RE = /^[a-z0-9][a-z0-9_-]*(\/[a-z0-9][a-z0-9_-]*)*\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.webp$/;
|
||||
|
||||
const URL_WINDOW_SEC = 60 * 60;
|
||||
const URL_EXPIRES_SEC = URL_WINDOW_SEC * 2;
|
||||
|
||||
export async function uploadImage(
|
||||
file: File,
|
||||
directory: string,
|
||||
options: { maxWidth?: number; maxHeight?: number; fit?: "inside" | "cover" } = {},
|
||||
): Promise<string> {
|
||||
if (!DIRECTORY_RE.test(directory)) throw new Error("Invalid upload directory");
|
||||
if (file.size === 0) throw new AppError("A file is required");
|
||||
if (file.size > MAX_FILE_SIZE) throw new AppError("Image must be smaller than 5MB");
|
||||
|
||||
const input = Buffer.from(await file.arrayBuffer());
|
||||
if (input.length > MAX_FILE_SIZE) throw new AppError("Image must be smaller than 5MB");
|
||||
|
||||
const image = sharp(input, {
|
||||
failOn: "error",
|
||||
limitInputPixels: 30_000_000,
|
||||
sequentialRead: true,
|
||||
});
|
||||
|
||||
const metadata = await image.metadata();
|
||||
if (!metadata.format || !ALLOWED_INPUT_FORMATS.has(metadata.format)) {
|
||||
throw new AppError("Only JPEG, PNG, or WEBP images are allowed");
|
||||
}
|
||||
|
||||
if (!metadata.width || !metadata.height || metadata.width < 100 || metadata.height < 100) {
|
||||
throw new AppError("Image is too small");
|
||||
}
|
||||
@@ -41,19 +54,31 @@ export async function uploadImage(file: File, directory: string, options: { maxW
|
||||
.webp({ quality: 80, effort: 4 })
|
||||
.toBuffer();
|
||||
|
||||
const key = `${directory}/${crypto.randomUUID()}.webp`;
|
||||
await getMinioClient().putObject(BUCKET, key, output, output.length, { "Content-Type": "image/webp" });
|
||||
const key = `${directory}/${crypto.randomUUID()}.webp`;
|
||||
await getInternalClient().send(
|
||||
new PutObjectCommand({
|
||||
Bucket: BUCKET,
|
||||
Key: key,
|
||||
Body: output,
|
||||
ContentLength: output.length,
|
||||
ContentType: "image/webp",
|
||||
CacheControl: "public, max-age=31536000, immutable",
|
||||
}),
|
||||
);
|
||||
return key;
|
||||
}
|
||||
|
||||
export async function removeImage(key: string) {
|
||||
await getMinioClient().removeObject(BUCKET, key)
|
||||
if (!KEY_RE.test(key)) throw new Error("Invalid image key");
|
||||
await getInternalClient().send(new DeleteObjectCommand({ Bucket: BUCKET, Key: key }));
|
||||
}
|
||||
|
||||
export async function getImageUrl(key: string): Promise<string> {
|
||||
return getMinioClient().presignedGetObject(
|
||||
BUCKET,
|
||||
key,
|
||||
60 * 5
|
||||
);
|
||||
if (!KEY_RE.test(key)) throw new Error("Invalid image key");
|
||||
const windowMs = URL_WINDOW_SEC * 1000;
|
||||
const signingDate = new Date(Math.floor(Date.now() / windowMs) * windowMs);
|
||||
return getSignedUrl(getPublicClient(), new GetObjectCommand({ Bucket: BUCKET, Key: key }), {
|
||||
expiresIn: URL_EXPIRES_SEC,
|
||||
signingDate,
|
||||
});
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Client } from "minio";
|
||||
|
||||
let _client: Client | null = null;
|
||||
|
||||
export function getMinioClient(): Client {
|
||||
if (!_client) {
|
||||
const url = new URL(process.env.MINIO_PUBLIC_URL!);
|
||||
_client = new Client({
|
||||
endPoint: url.hostname,
|
||||
port: url.port ? Number(url.port) : 443,
|
||||
useSSL: url.protocol === "https:",
|
||||
accessKey: process.env.MINIO_ACCESS_KEY!,
|
||||
secretKey: process.env.MINIO_SECRET_KEY!,
|
||||
});
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import "server-only";
|
||||
import { S3Client } from "@aws-sdk/client-s3";
|
||||
|
||||
function env(name: string): string {
|
||||
const value = process.env[name];
|
||||
if (!value) throw new Error(`Missing environment variable: ${name}`);
|
||||
return value;
|
||||
}
|
||||
|
||||
export const BUCKET = process.env.RUSTFS_BUCKET ?? "uploads";
|
||||
const REGION = process.env.RUSTFS_REGION ?? "us-east-1";
|
||||
|
||||
let internalClient: S3Client | null = null;
|
||||
let publicClient: S3Client | null = null;
|
||||
|
||||
const credentials = () => ({
|
||||
accessKeyId: env("RUSTFS_ACCESS_KEY"),
|
||||
secretAccessKey: env("RUSTFS_SECRET_KEY"),
|
||||
});
|
||||
|
||||
|
||||
export function getInternalClient(): S3Client {
|
||||
internalClient ??= new S3Client({
|
||||
endpoint: `http://${env("RUSTFS_INTERNAL_HOST")}:${process.env.RUSTFS_INTERNAL_PORT ?? 9000}`,
|
||||
region: REGION,
|
||||
credentials: credentials(),
|
||||
forcePathStyle: true,
|
||||
requestChecksumCalculation: "WHEN_REQUIRED",
|
||||
responseChecksumValidation: "WHEN_REQUIRED",
|
||||
maxAttempts: 3,
|
||||
requestHandler: { connectionTimeout: 3_000, requestTimeout: 15_000 },
|
||||
});
|
||||
return internalClient;
|
||||
}
|
||||
|
||||
export function getPublicClient(): S3Client {
|
||||
publicClient ??= new S3Client({
|
||||
endpoint: new URL(env("RUSTFS_PUBLIC_URL")).origin,
|
||||
region: REGION,
|
||||
credentials: credentials(),
|
||||
forcePathStyle: true,
|
||||
requestChecksumCalculation: "WHEN_REQUIRED",
|
||||
responseChecksumValidation: "WHEN_REQUIRED",
|
||||
});
|
||||
return publicClient;
|
||||
}
|
||||
+14
-10
@@ -1,22 +1,26 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const minioHost = process.env.MINIO_PUBLIC_URL ? new URL(process.env.MINIO_PUBLIC_URL).hostname : "localhost";
|
||||
const minioPort = process.env.MINIO_PUBLIC_URL ? new URL(process.env.MINIO_PUBLIC_URL).port : undefined;
|
||||
const publicUrl = process.env.RUSTFS_PUBLIC_URL ? new URL(process.env.RUSTFS_PUBLIC_URL) : null;
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
hostname: minioHost,
|
||||
...(minioPort ? { port: minioPort } : {}),
|
||||
},
|
||||
],
|
||||
remotePatterns: publicUrl
|
||||
? [
|
||||
{
|
||||
protocol: publicUrl.protocol === "https:" ? "https" : "http",
|
||||
hostname: publicUrl.hostname,
|
||||
...(publicUrl.port ? { port: publicUrl.port } : {}),
|
||||
pathname: `/${process.env.RUSTFS_BUCKET ?? "uploads"}/**`,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
experimental: {
|
||||
serverActions: {
|
||||
bodySizeLimit: "5mb",
|
||||
bodySizeLimit: "6mb",
|
||||
},
|
||||
},
|
||||
output: "standalone",
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
export default nextConfig;
|
||||
+34
-25
@@ -9,39 +9,41 @@
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.1169.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.1169.0",
|
||||
"@imgly/background-removal": "^1.7.0",
|
||||
"@prisma/adapter-pg": "^7.8.0",
|
||||
"@prisma/client": "^7.8.0",
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
"@prisma/client": "^7.10.1",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"jose": "^6.2.3",
|
||||
"lucide-react": "^1.20.0",
|
||||
"minio": "^8.0.7",
|
||||
"next": "16.2.9",
|
||||
"pg": "^8.21.0",
|
||||
"radix-ui": "^1.6.0",
|
||||
"jose": "^6.2.17",
|
||||
"lucide-react": "^1.73.0",
|
||||
"next": "16.4.6",
|
||||
"pg": "^8.23.1",
|
||||
"radix-ui": "^1.8.1",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4",
|
||||
"shadcn": "^4.11.0",
|
||||
"sharp": "^0.35.3",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.6.0",
|
||||
"server-only": "^0.0.1",
|
||||
"sharp": "^0.35.5",
|
||||
"sonner": "^2.0.8",
|
||||
"tailwind-merge": "^3.7.0",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"uuid": "^14.0.0",
|
||||
"zod": "^4.4.3"
|
||||
"uuid": "^14.0.3",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/pg": "^8.20.0",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.2.9",
|
||||
"prisma": "^7.8.0",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
"@tailwindcss/postcss": "^4.3.5",
|
||||
"@types/node": "^20.19.43",
|
||||
"@types/pg": "^8.23.1",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"eslint": "^9.39.5",
|
||||
"eslint-config-next": "16.4.6",
|
||||
"prisma": "^7.10.1",
|
||||
"shadcn": "^4.23.0",
|
||||
"tailwindcss": "^4.3.5",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"ignoreScripts": [
|
||||
"sharp",
|
||||
@@ -54,5 +56,12 @@
|
||||
"protobufjs",
|
||||
"sharp",
|
||||
"unrs-resolver"
|
||||
]
|
||||
],
|
||||
"overrides": {
|
||||
"fast-xml-parser": "^5.10.1",
|
||||
"source-map-js": "^1.2.2",
|
||||
"baseline-browser-mapping": "^2.11.0",
|
||||
"fast-uri": "^3.1.6",
|
||||
"zod": "^4.6.7"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user