Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MYSQL_HOST=mysql
MYSQL_USERNAME=root
MYSQL_PASSWORD=example
MYSQL_DATABASE=boilerplate_db
MYSQL_PORT=3306
EVENT_STORE_HOSTNAME=eventstore
EVENT_STORE_CREDENTIALS_USERNAME=admin
EVENT_STORE_CREDENTIALS_PASSWORD=changeit
EVENT_STORE_PROTOCOL=http
EVENT_STORE_TCP_PORT=1113
EVENT_STORE_HTTP_PORT=2113
EVENT_STORE_POOLOPTIONS_MIN=1
EVENT_STORE_POOLOPTIONS_MAX=10
PORT=3000
HOST=0.0.0.0
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ Temporary Items

=======
# Local
docker-compose.yml
*.env
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.env files should not be pushed to git.

we prepared an .env.example to clone from locally 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that env file is loaded by docker-compose in build phase, it evals the docker compose and change the ${VARS} by its equivalent.

dist
logs
data/
.config/
.npm/
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
FROM node:lts-alpine3.9 AS base
RUN apk add --no-cache git
WORKDIR /app
RUN mkdir src templates
RUN chown -R node:node /app
USER node

Expand All @@ -14,7 +13,6 @@ RUN npm install -d
# ---- Build ----
FROM dependencies AS build
WORKDIR /app
COPY ./templates /app/templates
COPY ./src /app/src
COPY ./ts*.json ./
COPY ormconfig.js ./
Expand All @@ -25,14 +23,11 @@ FROM base AS polishing
COPY ./package*.json ./
RUN npm install --production -d

# --- Release with Alpine ----
FROM node:lts-alpine3.9 AS release
# --- Release with distroless ----
FROM gcr.io/distroless/nodejs:12 AS release
WORKDIR /app
RUN mkdir dist templates node_modules
RUN chown -R node:node /app
USER node
COPY --from=polishing app/node_modules node_modules/
COPY --from=build app/dist dist/
COPY --from=build app/templates templates/
COPY --from=build app/ormconfig.js ./
CMD ["node","dist/src/main.js"]
USER nonroot
CMD ["dist/src/main.js"]
149 changes: 149 additions & 0 deletions boiler-ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/bin/sh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, we need to update README accoding to this? for better experience using the new CLI 🤔

(didn't test it intensively yet)


#script goals

# ---- HELP ----
help(){
echo "boiler-ctl command line tool to manage projetcs"
echo
echo "Syntax: boiler-ctl [init|stop|logs|install|commit|clean] [ARGS]"
echo "options"
echo "init Initiate project, creates data folders and containerized environment."
echo "stop Stop project containerized environment."
echo "logs Print and tail container logs, no args for all containers logs, or specify docker-compose service name(s)."
echo "install Install node package(s) seperated by a blank space."
echo "commit Print interactive commit menu implemnts conventional commits."
echo "clean Stops containers if up and deletes data and node_modules folder."
}

# ---- VARS ----
DEFAULT_NODE_CONTAINER_TAG="node:lts-alpine3.9"
DEFAULT_NODE_CONTAINER_PACKAGE_MANAGER="npm"

# ---- CHECK REQ ----
for cmd in git docker docker-compose;
do
command -v "${cmd}" >/dev/null || {
echo "[$(date +%D-%H:%M)][REQ]: Error! ${cmd} is required, but not found."
exit 1
};
done
[ -d ".git" ] || {
echo "[$(date)][REQ]: Error! boiler-ctl only wokrs on git repositories."
exit 1
}

# ---- CHECK NUMBER OF ARGS ----
[ "$#" != "0" ] || {
echo "[$(date +%D-%H:%M)][REQ]: Error! no args has been suplied, maybe use --help for list of options."
exit 1
}

# ---- HANDLE ARGS ----
case $1 in
init)
shift
[ "$#" != "0" ] && {
echo "[$(date +%D-%H:%M)][INIT][CONFIG]: too much arguments."
exit 1
}
[ -f ./docker-compose.yml ] && echo "[$(date +%D-%H:%M)][INIT][CONFIG]: docker-compose.yml file found" || {
echo "[$(date +%D-%H:%M)][INIT][CONFIG]: Error! docker-compose.yml file is required, but not found."
exit 1
}
docker-compose up
;;
stop)
shift
[ "$#" != "0" ] && {
echo "[$(date +%D-%H:%M)][STOP][CONFIG]: too much arguments."
exit 1
}
[ -f ./docker-compose.yml ] && echo "[$(date +%D-%H:%M)][INIT][CONFIG]: docker-compose.yml file found" || {
echo "[$(date +%D-%H:%M)][STOP][CONFIG]: Error! docker-compose.yml file is required, but not found."
exit 1
}
docker-compose down
;;
logs)
shift
docker-compose logs -t -f "$@"
;;
install)
shift
[ "$#" != "0" ] || {
echo "[$(date +%D-%H:%M)][INSTALL][CONFIG]: Error! no package name detected, please provide packages name seperated by space."
exit 1
}
[ -f ./package.json ] && echo "[$(date +%D-%H:%M)][INSTALL][CONFIG]: package.json file found" || {
echo "[$(date +%D-%H:%M)][INSTALL][CONFIG]: Error! package.json file is required, but not found."
exit 1
}
[ -n "$NODE_CONTAINER_TAG" ] && {
echo "[$(date +%D-%H:%M)][INSTALL][NODE_VERSION]: NODE_CONTAINER_TAG found. Using it instead of default"
$DEFAULT_NODE_CONTAINER_TAG="$NODE_CONTAINER_TAG"
} || {
echo "[$(date +%D-%H:%M)][INSTALL][NODE_VERSION]: Using default NODE_CONTAINER_TAG $DEFAULT_NODE_CONTAINER_TAG"
}
[ -n "$NODE_CONTAINER_PACKAGE_MANAGER" ] && {
echo "[$(date +%D-%H:%M)][INSTALL][NODE_PACKAGE_MANAGER]: NODE_CONTAINER_PACKAGE_MANAGER found. Using it instead of default"
$DEFAULT_NODE_CONTAINER_PACKAGE_MANAGER="$NODE_CONTAINER_PACKAGE_MANAGER"
} || {
echo "[$(date +%D-%H:%M)][INSTALL][NODE_VERSION]: Using default NODE_CONTAINER_PACKAGE_MANAGER $DEFAULT_NODE_CONTAINER_PACKAGE_MANAGER"
}
docker run --rm --name packge-install-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" \
"$DEFAULT_NODE_CONTAINER_TAG" "$DEFAULT_NODE_CONTAINER_PACKAGE_MANAGER" install "$@"
;;
commit)
shift
[ "$#" != "0" ] && {
echo "[$(date +%D-%H:%M)][COMMIT][CONFIG]: too much arguments."
exit 1
}
docker run --rm --name commit-citizen-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" \
-e HOME='.' -v ~/.gitconfig:/etc/gitconfig -a stdin -a stdout -a stderr -it timbru31/node-alpine-git npx git-cz --disable-emoji
;;
clean)
shift
[ "$#" != "0" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][CONFIG]: too much arguments."
exit 1
}
[ -f ./docker-compose.yml ] && echo "[$(date +%D-%H:%M)][CLEAN][CONFIG]: docker-compose.yml file found" || {
echo "[$(date +%D-%H:%M)][CLEAN][CONFIG]: Error! docker-compose.yml file is required, but not found."
exit 1
}
echo "[$(date +%D-%H:%M)][CLEAN][ENV]: stoping containers if up."
docker-compose down
[ -d "./data" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][DATA]: data directory found, deleteing it."
docker run --rm --name clean-data-dir-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" alpine:3 rm -rfv ./data
}
[ -d "./node_modules" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][DATA]: node_modules directory found, deleteing it."
docker run --rm --name clean-node_modules-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" alpine:3 rm -rfv node_modules
}
[ -d "./.npm" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][DATA]: .npm directory found, deleteing it."
docker run --rm --name clean-npm_folder-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" alpine:3 rm -rfv ./.npm
}
[ -d "./.config" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][DATA]: .config directory found, deleteing it."
docker run --rm --name clean-npm_folder-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" alpine:3 rm -rfv ./.config
}
[ -d "./dist" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][DATA]: .config directory found, deleteing it."
docker run --rm --name clean-npm_folder-job -w="/app" --mount type=bind,source="$(pwd)"/.,target="/app" alpine:3 rm -rfv ./dist
}
;;
help)
shift
[ "$#" != "0" ] && {
echo "[$(date +%D-%H:%M)][CLEAN][HELP]: too much arguments, help takes no args."
exit 1
}
help
;;
*)
echo "[$(date +%D-%H:%M)]: Error! unrecongnized arg, maybe use help for instructions."
esac
60 changes: 60 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: "3.1"
services:
app:
environment:
MYSQL_HOST: "${MYSQL_HOST}"
MYSQL_USERNAME: "${MYSQL_USERNAME}"
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: "${MYSQL_DATABASE}"
MYSQL_PORT: "${MYSQL_PORT}"
EVENT_STORE_HOSTNAME: "${EVENT_STORE_HOSTNAME}"
EVENT_STORE_CREDENTIALS_USERNAME: "${EVENT_STORE_CREDENTIALS_USERNAME}"
EVENT_STORE_CREDENTIALS_PASSWORD: "${EVENT_STORE_CREDENTIALS_PASSWORD}"
EVENT_STORE_PROTOCOL: "${EVENT_STORE_PROTOCOL}"
EVENT_STORE_TCP_PORT: "${EVENT_STORE_TCP_PORT}"
EVENT_STORE_HTTP_PORT: "${EVENT_STORE_HTTP_PORT}"
EVENT_STORE_POOLOPTIONS_MIN: "${EVENT_STORE_POOLOPTIONS_MIN}"
EVENT_STORE_POOLOPTIONS_MAX: "${EVENT_STORE_POOLOPTIONS_MAX}"
PORT: "${PORT}"
HOST: "${HOST}"
container_name: awesome_nestjs_boilerplate
image: node:lts-alpine3.9
working_dir: /app
command:
- sh
- -c
- apk add --no-cache git && /bin/su node -c 'npm -d install && npm run start:dev'
ports:
- "${PORT}:${PORT}"
volumes:
- type: "bind"
source: "./"
target: /app/
mysql:
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: "${MYSQL_DATABASE}"
image: mysql:5.7
command:
- --default-authentication-plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
container_name: "${MYSQL_HOST}"
volumes:
- ./data/mysql-data-dir:/var/lib/mysql
eventstore:
environment:
- EVENT_STORE_TCP_PORT="${EVENT_STORE_TCP_PORT}"
- EVENT_STORE_HTTP_PORT="${EVENT_STORE_HTTP_PORT}"
image: eventstore/eventstore:release-5.0.9
container_name: "${EVENT_STORE_HOSTNAME}"
ports:
- "${EVENT_STORE_HTTP_PORT}:${EVENT_STORE_HTTP_PORT}"
- "${EVENT_STORE_TCP_PORT}:${EVENT_STORE_TCP_PORT}"
volumes:
- ./data/eventstore-data-dir:/var/lib/eventstore
adminer:
image: adminer
container_name: 'adminer'
ports:
- 8080:8080
2 changes: 1 addition & 1 deletion docs/guidelines.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Guidelines

This document will introduce concepts and guidelines that constitute software development and delivery culture at box2home.
This document will introduce concepts and guidelines that constitute software development and delivery culture.

# Software Versioning and Release

Expand Down
Loading