diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9fb6a4e..76e12b9 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,20 +1,5 @@ -# Update the VARIANT arg in docker-compose.yml to pick a Node version: 10, 12, 14 -ARG VARIANT="16-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; \ - fi - -RUN sudo -u node npm config set unsafe-perm=true +ARG VARIANT=16-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT} # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ @@ -24,6 +9,5 @@ RUN sudo -u node npm config set unsafe-perm=true # ARG EXTRA_NODE_VERSION=10 # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" -# [Optional] Uncomment if you want to install more global node packages -# RUN sudo -u node npm install -g - +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " \ No newline at end of file diff --git a/.devcontainer/dbinit/fix.sql b/.devcontainer/dbinit/fix.sql new file mode 100755 index 0000000..adc6309 --- /dev/null +++ b/.devcontainer/dbinit/fix.sql @@ -0,0 +1,5 @@ +FLUSH PRIVILEGES ; +DROP USER ''@'localhost' ; +create database if not exists `photostestdb` ; +grant all privileges on `photostestdb`.* to 'photostestuser'@'%' identified by 'photostestpass' ; +FLUSH PRIVILEGES ; diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 97efca0..ac00fea 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,12 +9,18 @@ // Set *default* container specific settings.json values on container create. "settings": {}, // Add the IDs of extensions you want installed when the container is created. - "extensions": ["dbaeumer.vscode-eslint"], + "extensions": [ + "dbaeumer.vscode-eslint", + "mikestead.dotenv", + "esbenp.prettier-vscode", + "foxundermoon.shell-format", + "ms-azuretools.vscode-docker" + ], // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [1234, 3000], // 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", - "postCreateCommand": "cd /workspace; if [ ! -f ormconfig.json ]; then cp ormconfig.dockerdevexample.json ormconfig.json; fi; if [ ! -f ormconfig.test.json ]; then cp ormconfig.dockerdevexample.test.json ormconfig.test.json; fi;" + "postCreateCommand": "cd /workspace; if [ ! -f ormconfig.json ]; then cp ormconfig.dockerdevexample.json ormconfig.json; fi; if [ ! -f ormconfig.test.json ]; then cp ormconfig.dockerdevexample.test.json ormconfig.test.json; fi; npm i && cd frontend && npm i" } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index fa3f401..af0ecd5 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -2,54 +2,33 @@ version: '3' services: app: - build: + build: context: . dockerfile: Dockerfile - args: - # [Choice] Node.js version: 14, 12, 10 - VARIANT: 16 - # On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000. - USER_UID: 1000 - USER_GID: 1000 - volumes: - ..:/workspace:cached - + # Overrides default command so things don't shut down after the process ends. command: sleep infinity # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. network_mode: service:db - # Uncomment the next line to use a non-root user for all processes. - 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.) - db: - image: mariadb:latest + image: yobasystems/alpine-mariadb:10.6 volumes: - photosmariadb-data:/var/lib/mysql + - ./dbinit:/docker-entrypoint-initdb.d:ro environment: - MYSQL_DATABASE: photos - MYSQL_USER: photos - MYSQL_PASSWORD: photos - MYSQL_ROOT_PASSWORD: photos - - dbtest: - image: mariadb:latest - volumes: - - photosmariadbtest-data:/var/lib/mysql - environment: - MYSQL_DATABASE: photos_test - MYSQL_USER: photos - MYSQL_PASSWORD: photos - MYSQL_ROOT_PASSWORD: photos - - # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward MongoDB locally. - # (Adding the "ports" property to this file will not forward from a Codespace.) + MYSQL_DATABASE: photosdb + MYSQL_USER: photosuser + MYSQL_PASSWORD: photospass + MYSQL_ROOT_PASSWORD: photosroot + healthcheck: + test: "mysql $$MYSQL_DATABASE -u$$MYSQL_USER -p$$MYSQL_PASSWORD -e 'SELECT 1;'" + interval: 10s + timeout: 10s + retries: 10 volumes: photosmariadb-data: - photosmariadbtest-data: \ No newline at end of file diff --git a/ormconfig.dockerdevexample.json b/ormconfig.dockerdevexample.json index e51fa99..0da3391 100644 --- a/ormconfig.dockerdevexample.json +++ b/ormconfig.dockerdevexample.json @@ -2,24 +2,18 @@ "type": "mariadb", "host": "db", "port": 3306, - "username": "photos", - "password": "photos", - "database": "photos", + "username": "photosuser", + "password": "photospass", + "database": "photosdb", "synchronize": false, "logging": false, - "entities": [ - "src/entity/**/*.ts" - ], - "migrations": [ - "src/migration/**/*.ts" - ], - "subscribers": [ - "src/subscriber/**/*.ts" - ], + "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 index bcb0ba0..2e637de 100644 --- a/ormconfig.dockerdevexample.test.json +++ b/ormconfig.dockerdevexample.test.json @@ -1,25 +1,19 @@ { "type": "mariadb", - "host": "dbtest", + "host": "db", "port": 3306, - "username": "photos", - "password": "photos", - "database": "photos_test", + "username": "photostestuser", + "password": "photostestpass", + "database": "photostestdb", "synchronize": true, "logging": false, - "entities": [ - "src/entity/**/*.ts" - ], - "migrations": [ - "src/migration/**/*.ts" - ], - "subscribers": [ - "src/subscriber/**/*.ts" - ], + "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 +}