2 Commits

9 changed files with 82 additions and 86 deletions

View File

@@ -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 <your-package-list-here>
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"

5
.devcontainer/dbinit/fix.sql Executable file
View File

@@ -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 ;

View File

@@ -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"
}

View File

@@ -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:

6
mocha.json Executable file
View File

@@ -0,0 +1,6 @@
{
"reporterEnabled": "spec, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile":"backend-report.xml"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

29
package-lock.json generated Normal file → Executable file
View File

@@ -70,7 +70,8 @@
"@types/prettier": "^2.7.2",
"@types/sharp": "^0.31.1",
"@types/supertest": "^2.0.12",
"mocha-junit-reporter": "^2.2.0"
"mocha-junit-reporter": "^2.2.0",
"mocha-multi-reporters": "^1.5.1"
}
},
"node_modules/@cspotcode/source-map-support": {
@@ -4322,6 +4323,22 @@
"mocha": ">=2.2.5"
}
},
"node_modules/mocha-multi-reporters": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/mocha-multi-reporters/-/mocha-multi-reporters-1.5.1.tgz",
"integrity": "sha512-Yb4QJOaGLIcmB0VY7Wif5AjvLMUFAdV57D2TWEva1Y0kU/3LjKpeRVmlMIfuO1SVbauve459kgtIizADqxMWPg==",
"dev": true,
"dependencies": {
"debug": "^4.1.1",
"lodash": "^4.17.15"
},
"engines": {
"node": ">=6.0.0"
},
"peerDependencies": {
"mocha": ">=3.1.2"
}
},
"node_modules/mocha/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
@@ -9686,6 +9703,16 @@
"xml": "^1.0.1"
}
},
"mocha-multi-reporters": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/mocha-multi-reporters/-/mocha-multi-reporters-1.5.1.tgz",
"integrity": "sha512-Yb4QJOaGLIcmB0VY7Wif5AjvLMUFAdV57D2TWEva1Y0kU/3LjKpeRVmlMIfuO1SVbauve459kgtIizADqxMWPg==",
"dev": true,
"requires": {
"debug": "^4.1.1",
"lodash": "^4.17.15"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",

5
package.json Normal file → Executable file
View File

@@ -6,7 +6,7 @@
"start": "ts-node -T -r tsconfig-paths/register src/server.ts",
"ts-node-dev": "ts-node-dev -r tsconfig-paths/register ./src/server.ts",
"dev": "cross-env NODE_ENV=development concurrently npm:ts-node-dev npm:start-frontend -c 'blue,green'",
"test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register --reporter mocha-junit-reporter --reporter-options mochaFile=backend-report.xml 'src/tests/**/*.ts' ",
"test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register --reporter mocha-multi-reporters --reporter-options configFile=mocha.json 'src/tests/**/*.ts' ",
"test-frontend": "cd frontend && npm test",
"test-all": "npm test && npm run test-frontend",
"lint": "eslint ./src/** --ext .js,.jsx,.ts,.tsx && tsc --noEmit",
@@ -83,7 +83,8 @@
"@types/prettier": "^2.7.2",
"@types/sharp": "^0.31.1",
"@types/supertest": "^2.0.12",
"mocha-junit-reporter": "^2.2.0"
"mocha-junit-reporter": "^2.2.0",
"mocha-multi-reporters": "^1.5.1"
},
"husky": {
"hooks": {