diff --git a/.dockerignore b/.dockerignore index 7ac1359f..8c4c4a93 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,6 +9,8 @@ !package.json !package-lock.json !tsconfig.json +!migrations +!init.sh # Ignore unnecessary files inside allowed directories **/*~ diff --git a/Dockerfile b/Dockerfile index f0042580..311959f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,10 @@ COPY --from=builder /app/dist ./dist COPY package.json package-lock.json ./ RUN npm install COPY ./app-config.yaml . +COPY ./migrations ./migrations +COPY ./init.sh . USER node ENV NODE_ENV="production" -CMD ["node", "dist/index.js"] \ No newline at end of file + +CMD ["/bin/sh", "init.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 89f1b7d6..cfe88cdd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: postgres: image: postgres environment: + POSTGRES_DB: codex-notes POSTGRES_PASSWORD: example ports: - 127.0.0.1:5432:5432 diff --git a/init.sh b/init.sh new file mode 100644 index 00000000..c8c2c7b9 --- /dev/null +++ b/init.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e +npm run migrate +node dist/index.js \ No newline at end of file diff --git a/package.json b/package.json index b468fe29..33e09d15 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dev": "nodemon --watch './src/**/*.ts' --ext ts --exec 'npm run start:dev'", "start": "node dist/index.js -c app-config.yaml -c app-config.local.yaml", "start:dev": "npm run build && node dist/index.js -c app-config.yaml -c app-config.local.yaml", - "migrate": "node --loader ts-node/esm ./src/repository/storage/postgres/migrations/index.ts -c app-config.local.yaml", + "migrate": "node --loader ts-node/esm dist/repository/storage/postgres/migrations/index.js -c app-config.yaml -c app-config.yaml", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "test": "vitest",