From 32772117feccfb154bf0c5487da5c6818a1f355a Mon Sep 17 00:00:00 2001 From: brianling <1745087927@qq.com> Date: Fri, 12 Apr 2024 22:07:50 +0800 Subject: [PATCH] docker run test --- .env.docker | 1 + docker-compose.yaml | 20 ++++++++++++++++++++ dockerfile | 5 +++++ init.sql | 31 +++++++++++++++++++++++++++++++ run | 6 ++++++ 5 files changed, 63 insertions(+) create mode 100644 .env.docker create mode 100644 docker-compose.yaml create mode 100644 dockerfile create mode 100644 init.sql create mode 100644 run diff --git a/.env.docker b/.env.docker new file mode 100644 index 0000000..910ee7f --- /dev/null +++ b/.env.docker @@ -0,0 +1 @@ +DATABASE_URL="postgresql://pjob:pjob@db:5432/pjob?schema=public" diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..3d09f49 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,20 @@ +version: "3.8" + +services: + pjob: + build: ./pjob/ + restart: always + ports: + - 80:3000 + depends_on: + - db + db: + image: postgres + restart: always + volumes: + - /etc/localtime:/etc/localtime + - ./init.sql:/docker-entrypoint-initdb.d/init.sql + environment: + - POSTGRES_USER=pjob + - POSTGRES_DB=pjob + - POSTGRES_PASSWORD=pjob diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..c0a516d --- /dev/null +++ b/dockerfile @@ -0,0 +1,5 @@ +FROM node +WORKDIR / +COPY . /www/ +CMD node /www/server/index.mjs +EXPOSE 3000 \ No newline at end of file diff --git a/init.sql b/init.sql new file mode 100644 index 0000000..6697066 --- /dev/null +++ b/init.sql @@ -0,0 +1,31 @@ +-- CreateTable +CREATE TABLE "Data" ( + "id" SERIAL NOT NULL, + "desc" VARCHAR NOT NULL DEFAULT '', + "img" VARCHAR NOT NULL DEFAULT '/Pjob.jpb', + "time" VARCHAR NOT NULL DEFAULT '', + "pay" INTEGER NOT NULL DEFAULT 1, + + CONSTRAINT "Data_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Job" ( + "id" SERIAL NOT NULL, + "name" VARCHAR NOT NULL, + "worktime" VARCHAR NOT NULL, + "createTime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateTime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "pin" BOOLEAN NOT NULL DEFAULT true, + "dataId" INTEGER, + "place" VARCHAR NOT NULL DEFAULT 'in', + "area" VARCHAR NOT NULL DEFAULT 'in', + + CONSTRAINT "Job_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Job_dataId_key" ON "Job"("dataId"); + +-- AddForeignKey +ALTER TABLE "Job" ADD CONSTRAINT "Job_dataId_fkey" FOREIGN KEY ("dataId") REFERENCES "Data"("id") ON DELETE NO ACTION ON UPDATE NO ACTION; diff --git a/run b/run new file mode 100644 index 0000000..ceb790f --- /dev/null +++ b/run @@ -0,0 +1,6 @@ +#!/bin/bash +yarn +yarn build +cp dockerfile ./output/ +cp .env.docker ./output/server/.env +docker-compose up -d