Skip to content

Commit

Permalink
fix: ensure docker images can be built
Browse files Browse the repository at this point in the history
  • Loading branch information
yurenju committed Sep 27, 2023
1 parent 33fff73 commit 48ea4b6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions apps/docker/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"targets": {
"build": {
"dependsOn": [
{
"target": "copy-env-file",
"projects": ["server"]
},
{
"target": "build",
"projects": ["web", "server"]
Expand Down
7 changes: 7 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MONGO_INITDB_ROOT_USERNAME=initdbrootusername
MONGO_INITDB_ROOT_PASSWORD=initdbrootpassword
MONGO_DATABASE=dpassport
MONGO_DATABASE_USERNAME=dpassportusername
MONGO_DATABASE_PASSWORD=dpassportpassword
MONGO_HOST=localhost
MONGO_CONTAINER_NAME=dpassport-mongo
12 changes: 9 additions & 3 deletions apps/server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@
}
}
},
"docker-build": {
"dependsOn": ["build"],
"command": "docker build -f apps/server/Dockerfile . -t server"
"setup-db": {
"command": "node apps/server/scripts/setup-db.js"
},
"start-db": {
"command": "node apps/server/scripts/start-db.js"
},
"copy-env-file": {
"dependsOn": ["setup-db"],
"command": "node apps/server/scripts/copy-env-file.js"
}
},
"tags": []
Expand Down
19 changes: 19 additions & 0 deletions apps/server/scripts/copy-env-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { existsSync, copyFileSync } = require('fs');
const { join } = require('path');

function copyEnvFile() {
const serverPath = join(__dirname, '..');
const targetPath = join(serverPath, '.env.local');
const examplePath = join(serverPath, '.env.example');

if (!existsSync(targetPath)) {
console.log('.env.local not exists, copy from .env.example');
copyFileSync(examplePath, targetPath);
} else {
console.log('.env.local does exist, do nothing.');
}
}

if (require.main === module) {
copyEnvFile();
}
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
"license": "MIT",
"scripts": {
"start": "nx serve web",
"acceptance": "nx acceptance acceptance",
"setup:db": "node apps/server/scripts/setup-db.js",
"start:db": "node apps/server/scripts/start-db.js",
"predocker-compose:up": "nx build server && npm run setup:db",
"docker-compose:up": "docker-compose --env-file=./apps/server/.env.local up --build --detach",
"docker-compose:down": "docker-compose down"
"acceptance": "nx acceptance acceptance"
},
"private": true,
"devDependencies": {
Expand Down

0 comments on commit 48ea4b6

Please sign in to comment.