From 8bd57fcf9e888138db95138ffdc46c8f7658b752 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Fri, 16 Oct 2020 07:43:11 +0000 Subject: [PATCH] working devcontainer --- .devcontainer/Dockerfile | 10 ++++++---- .devcontainer/devcontainer.json | 5 +++-- .devcontainer/docker-compose.yml | 10 +++++----- ormconfig.dockerdevexample.json | 25 +++++++++++++++++++++++++ ormconfig.dockerdevexample.test.json | 25 +++++++++++++++++++++++++ src/entity/User.ts | 2 +- 6 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 ormconfig.dockerdevexample.json create mode 100644 ormconfig.dockerdevexample.test.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a3f52cd..bcdf44a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,14 +2,16 @@ ARG VARIANT="14-buster" FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} +ENV DOCKERDEV=true + # Update args in docker-compose.yaml to set the UID/GID of the "node" user. ARG USER_UID=1000 ARG USER_GID=$USER_UID RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \ - groupmod --gid $USER_GID node \ - && usermod --uid $USER_UID --gid $USER_GID node \ - && chmod -R $USER_UID:$USER_GID /home/node \ - && chmod -R $USER_UID:root /usr/local/share/nvm /usr/local/share/npm-global; \ + groupmod --gid $USER_GID node \ + && usermod --uid $USER_UID --gid $USER_GID node \ + && chmod -R $USER_UID:$USER_GID /home/node \ + && chmod -R $USER_UID:root /usr/local/share/nvm /usr/local/share/npm-global; \ fi RUN sudo -u node npm config set unsafe-perm=true diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 708c0ef..633fdf9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -39,7 +39,8 @@ "dbaeumer.vscode-eslint", "mtxr.sqltools", "mtxr.sqltools-driver-mysql", - "ms-vscode.vscode-typescript-tslint-plugin" + "visualstudioexptteam.vscodeintellicode", + "rvest.vs-code-prettier-eslint", ], // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ @@ -49,5 +50,5 @@ // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "npm config set unsafe-perm=true && npm i && cd frontend && npm i", // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. - // "remoteUser": "node" + "remoteUser": "node" } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 4e45026..283e723 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -22,7 +22,7 @@ services: network_mode: service:db # Uncomment the next line to use a non-root user for all processes. - # user: node + user: node # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) @@ -31,7 +31,7 @@ services: image: mariadb:latest restart: unless-stopped volumes: - - mariadb-data:/var/lib/mysql + - photosmariadb-data:/var/lib/mysql environment: MYSQL_DATABASE: photos MYSQL_USER: photos @@ -42,7 +42,7 @@ services: image: mariadb:latest restart: unless-stopped volumes: - - mariadbtest-data:/var/lib/mysql + - photosmariadbtest-data:/var/lib/mysql environment: MYSQL_DATABASE: photos_test MYSQL_USER: photos @@ -53,5 +53,5 @@ services: # (Adding the "ports" property to this file will not forward from a Codespace.) volumes: - mariadb-data: - mariadbtest-data: \ No newline at end of file + photosmariadb-data: + photosmariadbtest-data: \ No newline at end of file diff --git a/ormconfig.dockerdevexample.json b/ormconfig.dockerdevexample.json new file mode 100644 index 0000000..a95d227 --- /dev/null +++ b/ormconfig.dockerdevexample.json @@ -0,0 +1,25 @@ +{ + "type": "mariadb", + "host": "db", + "port": 3306, + "username": "photos", + "password": "photos", + "database": "photos", + "synchronize": true, + "logging": false, + "entities": [ + "src/entity/**/*.ts" + ], + "migrations": [ + "src/migration/**/*.ts" + ], + "subscribers": [ + "src/subscriber/**/*.ts" + ], + "cli": { + "entitiesDir": "src/entity", + "migrationsDir": "src/migration", + "subscribersDir": "src/subscriber" + }, + "charset": "utf8mb4" +} \ No newline at end of file diff --git a/ormconfig.dockerdevexample.test.json b/ormconfig.dockerdevexample.test.json new file mode 100644 index 0000000..bcb0ba0 --- /dev/null +++ b/ormconfig.dockerdevexample.test.json @@ -0,0 +1,25 @@ +{ + "type": "mariadb", + "host": "dbtest", + "port": 3306, + "username": "photos", + "password": "photos", + "database": "photos_test", + "synchronize": true, + "logging": false, + "entities": [ + "src/entity/**/*.ts" + ], + "migrations": [ + "src/migration/**/*.ts" + ], + "subscribers": [ + "src/subscriber/**/*.ts" + ], + "cli": { + "entitiesDir": "src/entity", + "migrationsDir": "src/migration", + "subscribersDir": "src/subscriber" + }, + "charset": "utf8mb4" +} \ No newline at end of file diff --git a/src/entity/User.ts b/src/entity/User.ts index f4ab5dc..db3b962 100644 --- a/src/entity/User.ts +++ b/src/entity/User.ts @@ -78,7 +78,7 @@ export class User extends BaseEntity { @AfterInsert() async createDataDir(): Promise { - await fs.mkdir(this.getDataPath()); + await fs.mkdir(this.getDataPath(), { recursive: true }); } @BeforeRemove()