Skip to content

Commit 9b841e9

Browse files
committed
✨ Creatring new script for development -m Added Docker
Added Docker, example of package.json with husky, a script that runs and stops docker, a way of creating a .env.example...
1 parent afa97b6 commit 9b841e9

11 files changed

+139
-21
lines changed

.env.run_dev_exmaple

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Docker - MySQL
2+
# Possible connection problems https://community.atlassian.com/t5/Confluence-questions/MySQL-Public-Key-Retrieval-is-not-allowed/qaq-p/778956
3+
MYSQL_VERSION=latest
4+
MYSQL_HOST=project_name
5+
MYSQL_DATABASE=test
6+
MYSQL_ROOT_USER=root
7+
MYSQL_ROOT_PASSWORD=root
8+
MYSQL_USER=dev
9+
MYSQL_PASSWORD=dev
10+
# Script SQL that creates DB if need it
11+
MYSQL_SCRIPT_PATH=./sql/partner.sql
12+
13+
# Docker - node
14+
# production
15+
NODE_VERSION=latest
16+
NODE_ENV=dev
17+
NODE_PORT=5000
18+
NODE_HOST=node
19+

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3.3"
2+
services:
3+
mysqldb:
4+
image: mysql:${MYSQL_VERSION}
5+
container_name: ${MYSQL_HOST}
6+
restart: always
7+
env_file:
8+
- ".env"
9+
environment:
10+
- MYSQL_DATABASE=${MYSQL_DATABASE}
11+
- MYSQL_ROOT_USER=${MYSQL_ROOT_USER}
12+
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
13+
- MYSQL_USER=${MYSQL_USER}
14+
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
15+
ports:
16+
- "3306:3306"
17+
volumes:
18+
- "./data/db/mysql:/var/lib/mysql"

execute_sql_scripts.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
# Getting .env values to use on the script
3+
CONTAINER_ID=$(grep MYSQL_HOST .env | cut -d '=' -f2)
4+
MYSQL_ROOT_USER=$(grep MYSQL_ROOT_USER .env | cut -d '=' -f2)
5+
MYSQL_ROOT_PASSWORD=$(grep MYSQL_ROOT_PASSWORD .env | cut -d '=' -f2)
6+
MYSQL_DATABASE=$(grep MYSQL_DATABASE .env | cut -d '=' -f2)
7+
MYSQL_SCRIPT_PATH=$(grep MYSQL_SCRIPT_PATH .env | cut -d '=' -f2)
8+
9+
echo "☢ Executing SQL migration"
10+
echo "============================"
11+
echo "📑 Copying sql file ${MYSQL_SCRIPT_PATH##*/} from $MYSQL_SCRIPT_PATH"
12+
docker cp $MYSQL_SCRIPT_PATH $CONTAINER_ID:/${MYSQL_SCRIPT_PATH##*/}
13+
echo "💾 Executing sql ${MYSQL_SCRIPT_PATH##*/}"
14+
docker exec -i $CONTAINER_ID mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE < $MYSQL_SCRIPT_PATH
15+
echo "🗑 Deleting sql ${MYSQL_SCRIPT_PATH##*/}"
16+
docker exec -it $CONTAINER_ID rm ${MYSQL_SCRIPT_PATH##*/}

force_strict_types_php.sh

100644100755
File mode changed.

generate_env_example.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
sed 's/=.*/=/' .env > .env.example;
3+
return 0;

generate_token.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
echo "$(id -un)-$(ps ax | grep $$ | grep -v grep | awk '{ print $2 }')-$(id)-$(date +%s%N)-$(head /dev/urandom | LC_CTYPE=C tr -dc '[:alnum:]' | head -c 2048 ; echo '')" | base64 | md5sum | awk '{print $1}';

generate_tokens.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
TOTAL_TOKENS=$1
4+
TITLE="🔑 Generating random TOKENS 👥"
5+
# shellcheck disable=SC1046
6+
if [ -z "$1" ]
7+
then
8+
TITLE="🔑 Generating random TOKEN 👤"
9+
TOTAL_TOKENS=1
10+
fi
11+
echo $TITLE
12+
echo "================================"
13+
seq $TOTAL_TOKENS | xargs -Iz ./generate_token.sh
14+
echo "================================"

generate_tree.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
tree -I 'node_modules|data|coverage|doc'

package.example.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "Package-name",
3+
"author": "Author name <[email protected]> (Domain.com)",
4+
"version": "0.0.1",
5+
"scripts": {
6+
"development": "nodemon index.js -e js,graphql",
7+
"netstat": "sudo netstat -nptl | grep node",
8+
"start": "node src/index.js",
9+
"prettier:lint": "prettier -l \"./src/**/*.{js,jsx,css,json,scss,ts,css,sass,less}\"",
10+
"format": "npm run prettier -- --write",
11+
"lint": "./node_modules/.bin/eslint ./src; exit 0",
12+
"lint:fix": "npm run lint --fix",
13+
"validate": "npm run prettier -- && npm run lint:fix",
14+
"prettier": "prettier --write src/**/*.{js,jsx,css,json,scss,ts,css,sass,less}",
15+
"test": "./node_modules/.bin/jest --verbose --coverage --updateSnapshot",
16+
"watch": "./node_modules/.bin/jest --watch --notify --verbose --coverage --updateSnapshot",
17+
"prettier:check": "prettier -l \"src/**/*.{js,jsx,css,json,scss,ts,css,sass,less}\"",
18+
"jsinspect": "./node_modules/.bin/jsinspect src",
19+
"lint-staged": "lint-staged",
20+
"dev": "./run_dev.sh",
21+
"database_migration": "./execute_sql_scripts.sh",
22+
"token": "./generate_tokens.sh",
23+
"tree": "./generate_tree.sh"
24+
},
25+
"main": "index.js",
26+
"dependencies": {
27+
28+
},
29+
"devDependencies": {
30+
"dotenv": "^8.2.0",
31+
"eslint": "^6.8.0",
32+
"eslint-plugin-prettier": "^3.1.2",
33+
"husky": "^4.2.3",
34+
"jest": "^25.1.0",
35+
"jsinspect": "^0.12.7",
36+
"lint-staged": "^10.0.7",
37+
"nodemon": "^2.0.2",
38+
"prettier": "^1.19.1"
39+
},
40+
"keywords": [],
41+
"license": "UNLICENSED",
42+
"husky": {
43+
"hooks": {
44+
"pre-commit": "lint-staged"
45+
}
46+
},
47+
"lint-staged": {
48+
"**/*.{jsx,js,md,ts,css,sass,less,graphql,yml,yaml,scss,json,vue}": [
49+
"npm run format",
50+
"npm run lint:fix",
51+
"./generate_env_example.sh",
52+
"npm run test . ",
53+
"git add"
54+
]
55+
}
56+
}

run_dev.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
exitfn () {
3+
trap SIGINT
4+
echo;
5+
docker-compose down;
6+
exit 0;
7+
}
8+
trap "exitfn" INT
9+
docker-compose up -d && npm run database_migration && npm install && npm audit fix && npm run development

0 commit comments

Comments
 (0)