mirror of
https://github.com/usatiuk/photos.git
synced 2025-10-28 15:27:49 +01:00
put this in docker container
This commit is contained in:
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
|
frontend/node_modules
|
||||||
|
frontend/npm-debug.log
|
||||||
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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"}'
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
RUN ["chmod", "+x", "dockerentry.sh"]
|
||||||
|
|
||||||
|
CMD [ "./dockerentry.sh" ]
|
||||||
11
dockercomposeexample/db.env
Normal file
11
dockercomposeexample/db.env
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
TYPEORM_HOST = db
|
||||||
|
TYPEORM_USERNAME = photos
|
||||||
|
TYPEORM_PASSWORD = photos
|
||||||
|
TYPEORM_DATABASE = photos
|
||||||
|
TYPEORM_PORT = 3306
|
||||||
|
MYSQL_DATABASE = photos
|
||||||
|
MYSQL_USER = photos
|
||||||
|
MYSQL_PASSWORD = photos
|
||||||
|
MYSQL_ROOT_PASSWORD = photos
|
||||||
|
|
||||||
|
|
||||||
24
dockercomposeexample/docker-compose.yml
Normal file
24
dockercomposeexample/docker-compose.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
version: "3.8"
|
||||||
|
services:
|
||||||
|
photosapp:
|
||||||
|
image: docker.io/stepanusatiuk/photos_test
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
- ./data:/usr/src/app/data
|
||||||
|
environment:
|
||||||
|
- JWT_SECRET=huegrhuigerhupoiervw
|
||||||
|
- API_ROOT=http://localhost:8080
|
||||||
|
- WEB_ROOT=http://localhost:8080
|
||||||
|
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
5
dockerentry.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
npm run typeorm -- migration:run
|
||||||
|
|
||||||
|
npm start
|
||||||
@@ -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";
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"username": "photos",
|
"username": "photos",
|
||||||
"password": "photos",
|
"password": "photos",
|
||||||
"database": "photos",
|
"database": "photos",
|
||||||
"synchronize": true,
|
"synchronize": false,
|
||||||
"logging": false,
|
"logging": false,
|
||||||
"entities": [
|
"entities": [
|
||||||
"src/entity/**/*.ts"
|
"src/entity/**/*.ts"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"username": "photos",
|
"username": "photos",
|
||||||
"password": "photos",
|
"password": "photos",
|
||||||
"database": "photos",
|
"database": "photos",
|
||||||
"synchronize": true,
|
"synchronize": false,
|
||||||
"logging": false,
|
"logging": false,
|
||||||
"entities": [
|
"entities": [
|
||||||
"src/entity/**/*.ts"
|
"src/entity/**/*.ts"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"prettier-check": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --check",
|
"prettier-check": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --check",
|
||||||
"prettify": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --write",
|
"prettify": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --write",
|
||||||
"typeorm-dev": "cross-env NODE_ENV=development ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
|
"typeorm-dev": "cross-env NODE_ENV=development ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
|
||||||
"typeorm": "ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
|
"typeorm": "cross-env NODE_ENV=development ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -89,4 +89,4 @@
|
|||||||
"pre-commit": "npm run lint-all && npm run prettier-check"
|
"pre-commit": "npm run lint-all && npm run prettier-check"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ app.use(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (config.env === EnvType.production) {
|
if (config.https) {
|
||||||
app.use(sslify({ resolver: xForwardedProtoResolver }));
|
app.use(sslify({ resolver: xForwardedProtoResolver }));
|
||||||
}
|
}
|
||||||
app.use(
|
app.use(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface IConfig {
|
|||||||
port: number;
|
port: number;
|
||||||
jwtSecret: string;
|
jwtSecret: string;
|
||||||
dataDir: string;
|
dataDir: string;
|
||||||
|
https: boolean;
|
||||||
dbConnectionOptions: ConnectionOptions | null;
|
dbConnectionOptions: ConnectionOptions | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ function getDataDir(): string {
|
|||||||
const production: IConfig = {
|
const production: IConfig = {
|
||||||
env: EnvType.production,
|
env: EnvType.production,
|
||||||
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 3000,
|
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 3000,
|
||||||
|
https: process.env.HTTPS ? process.env.HTTPS === "yes" : false,
|
||||||
jwtSecret: getJwtSecret(),
|
jwtSecret: getJwtSecret(),
|
||||||
dataDir: getDataDir(),
|
dataDir: getDataDir(),
|
||||||
dbConnectionOptions: null,
|
dbConnectionOptions: null,
|
||||||
|
|||||||
22
src/migration/1603126879697-init.ts
Normal file
22
src/migration/1603126879697-init.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||||
|
|
||||||
|
export class init1603126879697 implements MigrationInterface {
|
||||||
|
name = 'init1603126879697'
|
||||||
|
|
||||||
|
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 `photo` (`id` int NOT NULL AUTO_INCREMENT, `hash` varchar(190) NOT NULL, `size` varchar(190) NOT NULL, `format` varchar(190) NOT NULL, `uploaded` tinyint NOT NULL DEFAULT 0, `generatedThumbs` set ('512', '1024', '2048') NOT NULL DEFAULT '', `accessToken` varchar(500) NOT NULL, `accessTokenExpiry` timestamp NULL DEFAULT NULL, `shotAt` timestamp NULL DEFAULT NULL, `createdAt` timestamp NULL DEFAULT NULL, `editedAt` timestamp NULL DEFAULT NULL, `userId` int NULL, INDEX `IDX_43d1a6df29f544bdc57ab4cdc6` (`hash`), UNIQUE INDEX `IDX_491fe52f7ce0f0696fc0b70e7f` (`hash`, `size`, `userId`), PRIMARY KEY (`id`)) ENGINE=InnoDB");
|
||||||
|
await queryRunner.query("ALTER TABLE `photo` ADD CONSTRAINT `FK_4494006ff358f754d07df5ccc87` 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 `photo` DROP FOREIGN KEY `FK_4494006ff358f754d07df5ccc87`");
|
||||||
|
await queryRunner.query("DROP INDEX `IDX_491fe52f7ce0f0696fc0b70e7f` ON `photo`");
|
||||||
|
await queryRunner.query("DROP INDEX `IDX_43d1a6df29f544bdc57ab4cdc6` ON `photo`");
|
||||||
|
await queryRunner.query("DROP TABLE `photo`");
|
||||||
|
await queryRunner.query("DROP INDEX `IDX_e12875dfb3b1d92d7d7c5377e2` ON `user`");
|
||||||
|
await queryRunner.query("DROP INDEX `IDX_78a916df40e02a9deb1c4b75ed` ON `user`");
|
||||||
|
await queryRunner.query("DROP TABLE `user`");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user