docker thing

This commit is contained in:
2020-11-13 20:52:24 +03:00
parent 10c16f78ff
commit aaebe63e6d
13 changed files with 155 additions and 19 deletions

View File

@@ -2,6 +2,8 @@
ARG VARIANT="14-buster" ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} 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. # Update args in docker-compose.yaml to set the UID/GID of the "node" user.
ARG USER_UID=1000 ARG USER_UID=1000
ARG USER_GID=$USER_UID ARG USER_GID=$USER_UID

View File

@@ -39,12 +39,16 @@
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"mtxr.sqltools", "mtxr.sqltools",
"mtxr.sqltools-driver-mysql", "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. // Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [1234, 3000], "forwardPorts": [
1234,
3000
],
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm config set unsafe-perm=true && npm i && cd frontend && npm i", "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. // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "node" "remoteUser": "node"
} }

View File

@@ -22,7 +22,7 @@ services:
network_mode: service:db network_mode: service:db
# Uncomment the next line to use a non-root user for all processes. # 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. # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.) # (Adding the "ports" property to this file will not forward from a Codespace.)
@@ -31,7 +31,7 @@ services:
image: mariadb:latest image: mariadb:latest
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- mariadb-data:/var/lib/mysql - writermariadb-data:/var/lib/mysql
environment: environment:
MYSQL_DATABASE: writer MYSQL_DATABASE: writer
MYSQL_USER: writer MYSQL_USER: writer
@@ -42,7 +42,7 @@ services:
image: mariadb:latest image: mariadb:latest
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- mariadbtest-data:/var/lib/mysql - writermariadbtest-data:/var/lib/mysql
environment: environment:
MYSQL_DATABASE: writer_test MYSQL_DATABASE: writer_test
MYSQL_USER: writer MYSQL_USER: writer
@@ -53,5 +53,5 @@ services:
# (Adding the "ports" property to this file will not forward from a Codespace.) # (Adding the "ports" property to this file will not forward from a Codespace.)
volumes: volumes:
mariadb-data: writermariadb-data:
mariadbtest-data: writermariadbtest-data:

5
.dockerignore Normal file
View File

@@ -0,0 +1,5 @@
node_modules
npm-debug.log
frontend/node_modules
frontend/npm-debug.log

43
Dockerfile Normal file
View File

@@ -0,0 +1,43 @@
FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --only=production
RUN mkdir frontend
WORKDIR frontend
COPY ./frontend/package*.json ./
RUN npm ci --only=production
WORKDIR ../
COPY . .
WORKDIR frontend
RUN npm run build
WORKDIR ../
ENV PORT=8080
ENV DATA_DIR=data
ENV TYPEORM_CONNECTION=mariadb
#ENV TYPEORM_HOST=localhost
#ENV TYPEORM_USERNAME=root
#ENV TYPEORM_PASSWORD=admin
#ENV TYPEORM_DATABASE=test
#ENV TYPEORM_PORT=3000
ENV TYPEORM_SYNCHRONIZE=false
ENV TYPEORM_LOGGING=false
ENV TYPEORM_ENTITIES=src/entity/**/*.ts
ENV TYPEORM_ENTITIES_DIR=src/entity
ENV TYPEORM_MIGRATIONS=src/migration/**/*.ts
ENV TYPEORM_MIGRATIONS_DIR=src/migration
ENV TYPEORM_SUBSCRIBERS=src/subscriber/**/*.ts
ENV TYPEORM_SUBSCRIBERS_DIR=src/subscriber
ENV TYPEORM_DRIVER_EXTRA='{"charset": "utf8mb4"}'
ENV NODE_ENV=production
EXPOSE 8080
RUN ["chmod", "+x", "dockerentry.sh"]
CMD [ "./dockerentry.sh" ]

View File

@@ -0,0 +1,11 @@
TYPEORM_HOST = db
TYPEORM_USERNAME = writer
TYPEORM_PASSWORD = writer
TYPEORM_DATABASE = writer
TYPEORM_PORT = 3306
MYSQL_DATABASE = writer
MYSQL_USER = writer
MYSQL_PASSWORD = writer
MYSQL_ROOT_PASSWORD = writer

View File

@@ -0,0 +1,23 @@
version: "3.8"
services:
writerapp:
image: stepanusatiuk/writer:latest
restart: always
ports:
- "8080:8080"
volumes:
- ./data:/usr/src/app/data
environment:
- JWT_SECRET=huegrhuigerhupoiervw
env_file:
- db.env
depends_on:
- db
db:
image: mariadb
restart: always
volumes:
- ./dbdata:/var/lib/mysql
env_file:
- db.env

5
dockerentry.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
npm run typeorm -- migration:run
npm start

View File

@@ -1,2 +1,12 @@
export const apiRoot = process.env.API_ROOT || "http://localhost:3000"; export const apiRoot =
export const webRoot = process.env.WEB_ROOT || "http://localhost:1234"; process.env.API_ROOT ||
process.env.NODE_ENV === "production" ||
!process.env.NODE_ENV
? window.location.origin
: "http://localhost:3000";
export const webRoot =
process.env.WEB_ROOT ||
process.env.NODE_ENV === "production" ||
!process.env.NODE_ENV
? window.location.origin
: "http://localhost:1234";

View File

@@ -5,7 +5,7 @@
"username": "writer", "username": "writer",
"password": "writer", "password": "writer",
"database": "writer", "database": "writer",
"synchronize": true, "synchronize": false,
"logging": false, "logging": false,
"entities": [ "entities": [
"src/entity/**/*.ts" "src/entity/**/*.ts"

View File

@@ -4,8 +4,8 @@
"port": 3306, "port": 3306,
"username": "writer", "username": "writer",
"password": "writer", "password": "writer",
"database": "writer_test", "database": "writer",
"synchronize": true, "synchronize": false,
"logging": false, "logging": false,
"entities": [ "entities": [
"src/entity/**/*.ts" "src/entity/**/*.ts"

View File

@@ -71,7 +71,9 @@
"frontend": "cd frontend && npm start", "frontend": "cd frontend && npm start",
"dev": "cross-env NODE_ENV=development concurrently npm:ts-node-dev npm:frontend -c 'blue,green'", "dev": "cross-env NODE_ENV=development concurrently npm:ts-node-dev npm:frontend -c 'blue,green'",
"test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register 'src/tests/**/*.ts' ", "test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register 'src/tests/**/*.ts' ",
"lint": "eslint ./src/** ./frontend/src/** --ext .js,.jsx,.ts,.tsx" "lint": "eslint ./src/** ./frontend/src/** --ext .js,.jsx,.ts,.tsx",
"typeorm-dev": "cross-env NODE_ENV=development ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"typeorm": "cross-env NODE_ENV=production ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
}, },
"husky": { "husky": {
"hooks": { "hooks": {

View File

@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class init1605289418438 implements MigrationInterface {
name = "init1605289418438";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"CREATE TABLE `user` (`id` int NOT NULL AUTO_INCREMENT, `username` varchar(190) NOT NULL, `email` varchar(190) NOT NULL, `passwordHash` varchar(190) NOT NULL, UNIQUE INDEX `IDX_78a916df40e02a9deb1c4b75ed` (`username`), UNIQUE INDEX `IDX_e12875dfb3b1d92d7d7c5377e2` (`email`), PRIMARY KEY (`id`)) ENGINE=InnoDB",
);
await queryRunner.query(
"CREATE TABLE `document` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(190) NOT NULL, `content` text NOT NULL DEFAULT '', `createdAt` timestamp NULL DEFAULT NULL, `editedAt` timestamp NULL DEFAULT NULL, `shared` tinyint NOT NULL DEFAULT 0, `userId` int NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB",
);
await queryRunner.query(
"ALTER TABLE `document` ADD CONSTRAINT `FK_7424ddcbdf1e9b067669eb0d3fd` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION",
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE `document` DROP FOREIGN KEY `FK_7424ddcbdf1e9b067669eb0d3fd`",
);
await queryRunner.query("DROP TABLE `document`");
await queryRunner.query(
"DROP INDEX `IDX_e12875dfb3b1d92d7d7c5377e2` ON `user`",
);
await queryRunner.query(
"DROP INDEX `IDX_78a916df40e02a9deb1c4b75ed` ON `user`",
);
await queryRunner.query("DROP TABLE `user`");
}
}