Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Created August 3, 2022 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UltiRequiem/f1d2454492508980f0d7ec6c6a8b34aa to your computer and use it in GitHub Desktop.
Save UltiRequiem/f1d2454492508980f0d7ec6c6a8b34aa to your computer and use it in GitHub Desktop.
shipsigma-apps
#!make
MAKEFLAGS += --silent --jobs=10
##################################################################
## WARNING: assumes that .zsh_config is sourced!
##################################################################
###
### Environment
###
environment ?= development
$(shell cp .config/environment/.$(environment).env .env)
include .env
export $(shell sed 's/=.*//' .env)
###
### Globals
###
GitRepo = shipsigma-apps
DirEcosystemEdge = apps/edge/
DirEcosystemCore = apps/core/
DirEcosystemData = apps/data/
EcosystemEdgeServices = api-rest
EcosystemEdgeMfeShells = platform
EcosystemEdgeMfeMicros = admin client internal login reseller
EcosystemEdgeUiOthers = website platform
EcosystemCoreServices = common reporting
EcosystemCoreFunctions = dash reseller
EcosystemCoreCrons = common
EcosystemDataServices = etl-bus
EcosystemEdgeServicesNx = $(foreach project,$(EcosystemEdgeServices),edge-ms-$(project))
EcosystemEdgeMfeShellsNx = $(foreach project,$(EcosystemEdgeMfeShells),edge-mfe-shell-$(project))
EcosystemEdgeMfeMicrosNx = $(foreach project,$(EcosystemEdgeMfeMicros),edge-mfe-micro-$(project))
EcosystemEdgeUiOthersNx = $(foreach project,$(EcosystemEdgeUiOthers),edge-$(project))
EcosystemCoreServicesNx = $(foreach project,$(EcosystemCoreServices),core-ms-$(project))
EcosystemCoreFunctionsNx = $(foreach project,$(EcosystemCoreFunctions),core-fn-$(project))
EcosystemCoreCronsNx = $(foreach project,$(EcosystemCoreCrons),core-cron-$(project))
EcosystemDataServicesNx = $(foreach project,$(EcosystemDataServices),data-ms-$(project))
AllAppsNx = ${EcosystemEdgeMfeShellsNx} ${EcosystemEdgeMfeMicrosNx} ${EcosystemEdgeUiOthersNx}
# we leave out EcosystemDataServicesNx as python does not compile
AllServicesNx = ${EcosystemEdgeServicesNx} ${EcosystemCoreServicesNx} ${EcosystemCoreFunctionsNx} ${EcosystemCoreCronsNx}
# trick variables
noop =
comma := ,
space = $(noop) $(noop)
###
### Targets
###
install: FORCE
# ifeq (,$(shell which deno))
# echo Please install Deno. https://deno.land/manual/getting_started/installation
# endif
ifeq (,$(shell which vr))
deno install -f -qAn vr https://deno.land/x/velociraptor@1.4.0/cli.ts
echo installed: vr
endif
ifeq (,$(shell which dx))
deno install -q -A --unstable --no-check -r -f -n dx https://deno.land/x/deno_dx/cli.ts
echo installed: dx
endif
ifeq (,$(shell which dotenv-linter))
bash -c "curl -sSfL https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s -- -b ./bin"
echo installed: dotenv-linter
endif
echo $(shell dx hello)
# install git hooks for VR
#$(shell vr)
# trick to PHONY all code under apps and libs
#SUBDIR_TARGETS = all.subdir clean.subdir
#.PHONY: all clean $(SUBDIR_TARGETS)
#$(SUBDIR_TARGETS): %.subdir:
# $(MAKE) -C apps $*
# $(MAKE) -C libs $*
#
#all: all.subdir
#clean: clean.subdir
# env.set
build: linter.env.fix env.set.services
$(MAKE) build.services
$(MAKE) build.apps
$(MAKE) env.set.services
env.set.services:
# copy to both "./apps/*" and "./dist/apps/*" for every service
for service in $(EcosystemEdgeServices) ; do \
mkdir -p ./dist/${DirEcosystemEdge}ms/$$service/ >/dev/null 2>&1 ; \
cp .env ./${DirEcosystemEdge}ms/$$service/.env ; \
cp .env ./dist/${DirEcosystemEdge}ms/$$service/.env ; \
done
for service in $(EcosystemCoreServices) ; do \
mkdir -p ./dist/${DirEcosystemCore}ms/$$service/ >/dev/null 2>&1 ; \
cp .env ./${DirEcosystemCore}ms/$$service/.env ; \
cp .env ./dist/${DirEcosystemCore}ms/$$service/.env ; \
done
for service in $(EcosystemCoreFunctions) ; do \
mkdir -p ./dist/${DirEcosystemCore}fn/$$service/ >/dev/null 2>&1 ; \
cp .env ./${DirEcosystemCore}fn/$$service/.env ; \
cp .env ./dist/${DirEcosystemCore}fn/$$service/.env ; \
done
for service in $(EcosystemCoreCrons) ; do \
mkdir -p ./dist/${DirEcosystemCore}cron/$$service/ >/dev/null 2>&1 ; \
cp .env ./${DirEcosystemCore}cron/$$service/.env ; \
cp .env ./dist/${DirEcosystemCore}cron/$$service/.env ; \
done
@echo environment variables for services are set
build.affected:
nx affected:build --parallel --configuration=$(environment)
build.apps:
# build Angular apps, and then Storybook
nx run-many --target=build --projects=$(subst $(space),$(comma),$(AllAppsNx)) --parallel=3 --configuration=$(environment)
build.services:
nx run-many --target=build --projects=$(subst $(space),$(comma),$(AllServicesNx)) --parallel=3 --configuration=$(environment)
build.storybook:
# no storybook yet
docker.build:
$(MAKE) docker.build.services
$(MAKE) docker.build.portals
docker.build.services:
nx run-many --target=local-docker-$(environment) --projects=$(subst $(space),$(comma),$(ShipSigmaServicesProjects)) --parallel
docker.build.portals:
nx run-many --target=local-docker-$(environment) --projects=$(subst $(space),$(comma),$(ShipSigmaPortalsProjects)) --parallel
docker.start:
docker-compose up -d
linter.env:
linter.env.fix:
echo $(shell dx lintEnv)
###
### Combinations of what to server
###
# by default, just serve the new stuff
dev: dev-new
# there is no reason you would want to, but if you do, serve all new and old together
dev-all:
$(MAKE) dev-new & \
$(MAKE) dev-old
# serve all the new projects
dev-new:
$(MAKE) dev.services.snyder & \
$(MAKE) dev.apps.snyder
dev.kill: dev.kill.windows
dev.kill.windows:
# works in Windows and WSL
pwsh.exe -File .devops\\scripts\\dev-kill.ps1
@echo killed the dev processes of dapr
dev.kill.osx:
bash -c 'pkill -f dapr'
bash -c 'pkill -f shipsigma-apps'
dev-storybook:
# nx run shared-controls-nnrusa-controls:storybook --projectBuildConfig=shared-controls-nnrusa-controls
###
### Serve services by aggregate
###
dev.services-all: dev.services.snyder
dev.services-edge: dev.services.edge.ms.api-rest
dev.services-data: dev.services.data.ms.edt-bus
dev.services-core: dev.services.core.ms.common dev.services.core.ms.reporting
dev.services-core: dev.services.core.fn.dash dev.services.core.fn.reseller
dev.services-core: dev.services.core.cron.common
dev.services.snyder: dev.services-edge dev.services-core dev.services-data
###
### Snyder Tech
###
dev.apps.snyder: dev.apps.edge.platform dev.apps.edge.mfe
#dev.apps.edge.mfe.shell.platform
#dev.apps.edge.mfe.micro.admin
#dev.apps.edge.mfe.micro.client
#dev.apps.edge.mfe.micro.internal
#dev.apps.edge.mfe.micro.login
#dev.apps.edge.mfe.micro.reseller
###
### Dapr magic
###
# edge ecosystem apps
dev.apps.edge.platform:
#dapr run --app-id sigma-apps-edge-platform --app-port ${SIGMA_APP_PORT_EDGE_PLATFORM} -- nx run edge-platform:serve
nx run edge-platform:serve
dev.apps.edge.website:
#dapr run --app-id sigma-apps-website --app-port ${SIGMA_APP_PORT_EDGE_WEBSITE_V2} -- nx run edge-website:serve
nx run edge-website:serve
dev.apps.edge.mfe:
# serve from nx directly
nx run-many --target=serve --projects=edge-mfe-shell-platform,edge-mfe-micro-admin,edge-mfe-micro-client,edge-mfe-micro-internal,edge-mfe-micro-login,edge-mfe-micro-reseller --parallel=8
#dev.apps.edge.mfe.shell.platform:
# dapr run --app-id sigma-apps-edge-mfe-shell-platform --app-port ${SIGMA_APP_PORT_EDGE_MFE_SHELL_PLATFORM} -- nx run edge-mfe-shell-platform:serve
#dev.apps.edge.mfe.micro.admin:
# dapr run --app-id sigma-apps-edge-mfe-micro-admin --app-port ${SIGMA_APP_PORT_EDGE_MFE_MICRO_ADMIN} -- nx run edge-mfe-micro-admin:serve
#dev.apps.edge.mfe.micro.client:
# dapr run --app-id sigma-apps-edge-mfe-micro-client --app-port ${SIGMA_APP_PORT_EDGE_MFE_MICRO_CLIENT} -- nx run edge-mfe-micro-client:serve
#dev.apps.edge.mfe.micro.internal:
# dapr run --app-id sigma-apps-edge-mfe-micro-internal --app-port ${SIGMA_APP_PORT_EDGE_MFE_MICRO_INTERNAL} -- nx run edge-mfe-micro-internal:serve
#dev.apps.edge.mfe.micro.login:
# dapr run --app-id sigma-apps-edge-mfe-micro-login --app-port ${SIGMA_APP_PORT_EDGE_MFE_MICRO_LOGIN} -- nx run edge-mfe-micro-login:serve
#dev.apps.edge.mfe.micro.reseller:
# dapr run --app-id sigma-apps-edge-mfe-micro-reseller --app-port ${SIGMA_APP_PORT_EDGE_MFE_MICRO_RESELLER} -- nx run edge-mfe-micro-reseller:serve
# edge ecosystem services
dev.services.edge.ms.api-rest:
dapr run --app-id sigma-apps-edge-ms-api-rest --app-port ${SIGMA_APP_PORT_EDGE_MS_API_REST} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_EDGE_MS_API_REST) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_EDGE_MS_API_REST) -- nx run edge-ms-api-rest:serve
# core ecosystem services
dev.services.core.ms.common:
dapr run --app-id sigma-apps-core-ms-common --app-port ${SIGMA_APP_PORT_CORE_MS_COMMON} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_MS_COMMON) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_MS_COMMON) -- nx run core-ms-common:serve
dev.services.core.ms.reporting:
dapr run --app-id sigma-apps-core-ms-reporting --app-port ${SIGMA_APP_PORT_CORE_MS_REPORTING} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_MS_REPORTING) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_MS_REPORTING) -- nx run core-ms-reporting:serve
dev.services.core.fn.dash:
dapr run --app-id sigma-apps-core-fn-dash --app-port ${SIGMA_APP_PORT_CORE_FN_DASH} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_FN_DASH) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_FN_DASH) -- nx run core-fn-dash:serve
dev.services.core.fn.reseller:
dapr run --app-id sigma-apps-core-fn-reseller --app-port ${SIGMA_APP_PORT_CORE_FN_RESELLER} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_FN_RESELLER) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_FN_RESELLER) -- nx run core-fn-reseller:serve
dev.services.core.cron.common:
dapr run --app-id sigma-apps-core-cron-common --app-port ${SIGMA_APP_PORT_CORE_MS_COMMON} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_MS_COMMON) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_MS_COMMON) -- nx run core-cron-common:serve
###
### Release magic
###
release.patch:
nx run workspace:version --skipProjectChangelog --releaseAs=patch
release.minor:
nx run workspace:version --skipProjectChangelog --releaseAs=minor
release.major:
nx run workspace:version --skipProjectChangelog --releaseAs=major
# returns a single line of process IDs such as: 1689097 1689098 1707118 1707119 1707617 1717931
# for terminal testing: ps -e -o pid,user,comm,cmd | grep 'staging/nnr' | awk '{print $1}' | paste -sd " " -
ProcessList = $(shell ps -e -o pid,user,comm,cmd | grep '$(environment)/${GitRepo}' | awk '{print $$1}' | paste -sd " " -)
###
### To be done ... Incomplete
###
# delete pm2 services by environment, if they are up
pm2.delete:
for process in $(ProcessList) ; do \
pkill $$process || true ; \
done
# for service in $(NnrServices) ; do \
# pm2 delete nnr-services-$$service-$(environment) --silent || echo no pm2: nnr-services-$$service-$(environment) ; \
# done
@echo PM2 services are deleted
pm2.start: build
# core
# pm2 start --name sigma-core-cron-common-$(environment) "dapr run --app-id sigma-core-cron-common-$(environment) --app-port ${SIGMA_APP_PORT_CORE_CRON_COMMON} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_CRON_COMMON) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_CRON_COMMON) -- env-cmd dotnet './dist/apps/core/cron/common/Shipsigma.Cron.Common.dll'"
pm2 start --name sigma-core-ms-common-$(environment) "dapr run --app-id sigma-core-ms-common-$(environment) --app-port ${SIGMA_APP_PORT_CORE_MS_COMMON} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_MS_COMMON) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_MS_COMMON) -- env-cmd dotnet './dist/apps/core/ms/common/Shipsigma.Service.Common.dll'"
pm2 start --name sigma-core-ms-reporting-$(environment) "dapr run --app-id sigma-core-ms-reporting-$(environment) --app-port ${SIGMA_APP_PORT_CORE_MS_REPORTING} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_MS_REPORTING) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_MS_REPORTING) -- env-cmd dotnet './dist/apps/core/ms/reporting/Shipsigma.Service.Reporting.dll'"
# pm2 start --name sigma-core-fn-dash-$(environment) "dapr run --app-id sigma-core-fn-dash-$(environment) --app-port ${SIGMA_APP_PORT_CORE_FN_DASH} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_FN_DASH) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_FN_DASH) -- env-cmd dotnet './dist/apps/core/fn/dash/Shipsigma.DashFunctions.dll'"
# pm2 start --name sigma-core-fn-reseller-$(environment) "dapr run --app-id sigma-core-fn-reseller-$(environment) --app-port ${SIGMA_APP_PORT_CORE_FN_RESELLER} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_CORE_FN_RESELLER) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_CORE_FN_RESELLER) -- env-cmd dotnet './dist/apps/core/fn/reseller/Shipsigma.ResellerFunctions.dll'"
# edge
pm2 start --name sigma-edge-ms-api-rest-$(environment) "dapr run --app-id sigma-edge-ms-api-rest-$(environment) --app-port ${SIGMA_APP_PORT_EDGE_MS_API_REST} --dapr-http-port $(SIGMA_DAPR_HTTP_PORT_EDGE_MS_API_REST) --dapr-grpc-port $(SIGMA_DAPR_GRPC_PORT_EDGE_MS_API_REST) -- env-cmd node './dist/apps/edge/ms/api-rest/main.js'"
# leave this at the end, and leave it blank as it will force the run of it
FORCE:
import { isWindows } from "https://raw.githubusercontent.com/denoland/deno_std/0.150.0/_util/os.ts";
export async function lintEnv() {
const binary = `./bin/dotenv-linter${isWindows ? ".exe" : ""}`;
const commands = [
`find .config/environment/ -name *.env_* -delete | true`,
`${binary} fix .config/environment/.*`,
// `${binary} compare .config/environment/.*`,
];
for (const command of commands) {
await Deno.run({cmd: command.split(' ')}).status()
}
}
export function hello(){
console.log("heey")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment