Skip to content

Commit

Permalink
integrate deploy-packer and refactor full-system template.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjfchen committed Jul 31, 2022
1 parent 2eae601 commit cf9dbf6
Show file tree
Hide file tree
Showing 33 changed files with 15,468 additions and 8,801 deletions.
3 changes: 2 additions & 1 deletion cook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ case $3 in

"${SCRIPT_ABS_PATH}"/fix-up/do.sh "$1" "$2"
# for executables, we need to copy to override them after applying tempalte(Why?)
cp "${SCRIPT_ABS_PATH}"/deployment-framework/arion "$1/$2/cd/" && chmod +x "$1/$2/cd/arion"
[[ -d "$1/$2/cd" ]] && cp "${SCRIPT_ABS_PATH}"/deployment-framework/arion "$1/$2/cd/" && chmod +x "$1/$2/cd/arion"
[[ -d "$1/$2/$2/cd" ]] && cp "${SCRIPT_ABS_PATH}"/deployment-framework/arion "$1/$2/$2/cd/" && chmod +x "$1/$2/$2/cd/arion"
;;
*)
;;
Expand Down
57 changes: 32 additions & 25 deletions fix-up/do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,68 @@ begin_banner "Top level" "fix up"
# define a function to fix-up the paths based on different template name
function fix_up_paths_based_on_template_name () {
local PROJECT_NAME_REAL_PATH
PROJECT_NAME_REAL_PATH=${3//$1/$2}
#PROJECT_NAME_REAL_PATH=$(echo "$3" | sed "s/$1/$2/g")
PROJECT_NAME_REAL_PATH=${3//$1/$COMPPATH}
#PROJECT_NAME_REAL_PATH=$(echo "$3" | sed "s/$1/$COMPPATH/g")
mv "$3" "${PROJECT_NAME_REAL_PATH}"
}
export -f fix_up_paths_based_on_template_name

PROJECT_PASCAL_NAME=$(cat "$1/$2/.project.pascal.name")
PROJECT_SNAKE_NAME=$(cat "$1/$2/.project.snake.name")
if [ -d "$1/$2/project.orig.name" ]; then
mv "$1/$2/project.orig.name" "$1/$2/$2"
COMPPATH="$2/$2"
else
COMPPATH="$2"
fi

PROJECT_PASCAL_NAME=$(cat "$1/$COMPPATH/.project.pascal.name")
PROJECT_SNAKE_NAME=$(cat "$1/$COMPPATH/.project.snake.name")
while read -r PROJECT_ORIG_NAME_PATH; do
#[[ -n "${PROJECT_ORIG_NAME_PATH}" ]] && mv "${PROJECT_ORIG_NAME_PATH}" $(echo "${PROJECT_ORIG_NAME_PATH}" | sed "s/project.orig.name/$2/g")
#[[ -n "${PROJECT_ORIG_NAME_PATH}" ]] && mv "${PROJECT_ORIG_NAME_PATH}" $(echo "${PROJECT_ORIG_NAME_PATH}" | sed "s/project.orig.name/$COMPPATH/g")
[[ -n "${PROJECT_ORIG_NAME_PATH}" ]] && mv "${PROJECT_ORIG_NAME_PATH}" "${PROJECT_ORIG_NAME_PATH//project.orig.name/$2}"
done <<< "$(find "$1/$2" -name "*project.orig.name*" ! -wholename "$1/$2/.project.orig.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"
done <<< "$(find "$1/$COMPPATH" -name "*project.orig.name*" ! -wholename "$1/$COMPPATH/.project.orig.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"
while read -r PROJECT_SNAKE_NAME_PATH; do
#[[ -n "${PROJECT_SNAKE_NAME_PATH}" ]] && mv "${PROJECT_SNAKE_NAME_PATH}" $(echo "${PROJECT_SNAKE_NAME_PATH}" | sed "s/project.snake.name/${PROJECT_SNAKE_NAME}/g")
[[ -n "${PROJECT_SNAKE_NAME_PATH}" ]] && mv "${PROJECT_SNAKE_NAME_PATH}" "${PROJECT_SNAKE_NAME_PATH//project.snake.name/${PROJECT_SNAKE_NAME}}"
done <<< "$(find "$1/$2" -name "*project.snake.name*" ! -wholename "$1/$2/.project.snake.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"
done <<< "$(find "$1/$COMPPATH" -name "*project.snake.name*" ! -wholename "$1/$COMPPATH/.project.snake.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"
while read -r PROJECT_PASCAL_NAME_PATH; do
#[[ -n "${PROJECT_PASCAL_NAME_PATH}" ]] && mv "${PROJECT_PASCAL_NAME_PATH}" $(echo "${PROJECT_PASCAL_NAME_PATH}" | sed "s/project.pascal.name/${PROJECT_PASCAL_NAME}/g")
[[ -n "${PROJECT_PASCAL_NAME_PATH}" ]] && mv "${PROJECT_PASCAL_NAME_PATH}" "${PROJECT_PASCAL_NAME_PATH//project.pascal.name/${PROJECT_PASCAL_NAME}}"
done <<< "$(find "$1/$2" -name "*project.pascal.name*" ! -wholename "$1/$2/.project.pascal.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"
done <<< "$(find "$1/$COMPPATH" -name "*project.pascal.name*" ! -wholename "$1/$COMPPATH/.project.pascal.name" | awk '{ print length() "|" $0 | "sort -nr | cut -f2 -d\"|\""}')"

[[ -f "$1/$2/develop" ]] && chmod +x "$1/$2/develop"
[[ -f "$1/$2/build" ]] && chmod +x "$1/$2/build"
[[ -f "$1/$2/deploy" ]] && chmod +x "$1/$2/deploy"
[[ -f "$1/$2/deploy-to-local-docker-compose" ]] && chmod +x "$1/$2/deploy-to-local-docker-compose"
[[ -f "$1/$2/deploy-to-test-vm" ]] && chmod +x "$1/$2/deploy-to-test-vm"
[[ -f "$1/$2/deploy-to-production-vm" ]] && chmod +x "$1/$2/deploy-to-production-vm"
[[ -f "$1/$2/arion" ]] && chmod +x "$1/$2/arion"
find "$1/$2" -name "*.sh" -exec chmod +x {} \;
find "$1/$2" -name "*.bash" -exec chmod +x {} \;
find "$1/$2" -type d -name bin -exec chmod -R +x {} \;
[[ -f "$1/$COMPPATH/develop" ]] && chmod +x "$1/$COMPPATH/develop"
[[ -f "$1/$COMPPATH/build" ]] && chmod +x "$1/$COMPPATH/build"
[[ -f "$1/$COMPPATH/deploy" ]] && chmod +x "$1/$COMPPATH/deploy"
[[ -f "$1/$COMPPATH/deploy-to-local-docker-compose" ]] && chmod +x "$1/$COMPPATH/deploy-to-local-docker-compose"
[[ -f "$1/$COMPPATH/deploy-to-test-vm" ]] && chmod +x "$1/$COMPPATH/deploy-to-test-vm"
[[ -f "$1/$COMPPATH/deploy-to-production-vm" ]] && chmod +x "$1/$COMPPATH/deploy-to-production-vm"
[[ -f "$1/$COMPPATH/arion" ]] && chmod +x "$1/$COMPPATH/arion"
find "$1/$COMPPATH" -name "*.sh" -exec chmod +x {} \;
find "$1/$COMPPATH" -name "*.bash" -exec chmod +x {} \;
find "$1/$COMPPATH" -type d -name bin -exec chmod -R +x {} \;

# run the fixup for the specific template
if [[ -f "$1/$2/fixup" ]]; then
if [[ -f "$1/$COMPPATH/fixup" ]]; then
MY_PWD_FOR_FIXUP="$(pwd)"
cd "$1/$2"
cd "$1/$COMPPATH"
bash ./fixup
cd "${MY_PWD_FOR_FIXUP}"
fi
[[ -f "$1/$2/project.yml.orig" ]] && rm -fr "$1/$2/project.yml.orig"
[[ -f "$1/$2/project.yml" ]] && rm -fr "$1/$2/project.yml"
[[ -f "$1/$2/fixup" ]] && rm -fr "$1/$2/fixup"
[[ -f "$1/$COMPPATH/project.yml.orig" ]] && rm -fr "$1/$COMPPATH/project.yml.orig"
[[ -f "$1/$COMPPATH/project.yml" ]] && rm -fr "$1/$COMPPATH/project.yml"
[[ -f "$1/$COMPPATH/fixup" ]] && rm -fr "$1/$COMPPATH/fixup"

# define a function to handle paths which are provided by a find command
function reverse_project_info_for_rob () {
local TEMPLATE_NAME
TEMPLATE_NAME=$(basename "$3")
cp "$3/project.yml.orig" "$3/project.yml"
#sed -i "s/MY_PROJECT_NAME/$2/g" "${TEMPLATE_PATH}/project.yml"
#sed -i "s/MY_PROJECT_NAME/$COMPPATH/g" "${TEMPLATE_PATH}/project.yml"
#"${SCRIPT_ABS_PATH}"/../project-scaffold-template/rob remove
}
# export the above function so that can be used by other command or subshell
export -f reverse_project_info_for_rob

# reverse the project.yml back to orig
find "${SCRIPT_ABS_PATH}/../project-scaffold-template" -maxdepth 1 -type d ! -name . ! -wholename "${SCRIPT_ABS_PATH}/../project-scaffold-template" -exec bash -c 'reverse_project_info_for_rob "$0" "$1" "$2"' "${SCRIPT_ABS_PATH}" "$2" {} \;
find "${SCRIPT_ABS_PATH}/../project-scaffold-template" -maxdepth 1 -type d ! -name . ! -wholename "${SCRIPT_ABS_PATH}/../project-scaffold-template" -exec bash -c 'reverse_project_info_for_rob "$0" "$1" "$2"' "${SCRIPT_ABS_PATH}" "$COMPPATH" {} \;

done_banner "Top level" "fix up"
34 changes: 30 additions & 4 deletions project-scaffold-template/do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,26 @@ case ${THE_DISTRIBUTION_ID} in
cd "$1/$2"
find "${SCRIPT_ABS_PATH}" -maxdepth 1 -type d ! -name . ! -wholename "${SCRIPT_ABS_PATH}" -exec bash -c 'prepare_project_info_for_rob "$0" "$1" "$2"' "${SCRIPT_ABS_PATH}" "$2" {} \;
"${SCRIPT_ABS_PATH}"/rob new
"${SCRIPT_ABS_PATH}"/niv update
if [ -f "./nix/sources.json" ]; then
"${SCRIPT_ABS_PATH}"/niv update
else
NIVSRCDIR=$(dirname "$(find . -name "sources.json"|head -1)")
if [ "X$NIVSRCDIR" != "X" ] && [ -f "$NIVSRCDIR/sources.nix" ]; then
NIVSRCTMP=$(mktemp -d)
mkdir -p "$NIVSRCTMP/nix"
cp "$NIVSRCDIR/sources.json" "$NIVSRCTMP/nix/sources.json"
cp "$NIVSRCDIR/sources.nix" "$NIVSRCTMP/nix/sources.nix"
ln -sf "$NIVSRCTMP/nix" ./nix
"${SCRIPT_ABS_PATH}"/niv update
for COMP_DIR in $(dirname $(find "." -name "sources.json"))
do
cp "$NIVSRCTMP/nix/sources.json" "$COMP_DIR"
cp "$NIVSRCTMP/nix/sources.nix" "$COMP_DIR"
done
rm -fr ./nix
rm -fr "$NIVSRCTMP"
fi
fi
cd - > /dev/null
;;
*)
Expand All @@ -44,13 +63,20 @@ esac

# use haskell.nix internal index-state by default so that we sync cabal with nix
if [ -f "$1/$2/cabal.project" ]; then
H_INTERNAL_INDEX_STATE=$(nix eval --impure --expr "(import $1/$2/default.nix {}).pkgs.haskell-nix.internalHackageIndexState"|awk -F'"' '{print $2}')
if [ -f "$1/$2/project.orig.name/default.nix" ]; then
H_INTERNAL_INDEX_STATE=$(nix eval --impure --expr "(import $1/$2/project.orig.name/default.nix {}).pkgs.haskell-nix.internalHackageIndexState"|awk -F'"' '{print $2}')
[[ -f "$1/$2/project.orig.name/cabal.project" ]] && echo "index-state : $H_INTERNAL_INDEX_STATE" >> "$1/$2/project.orig.name/cabal.project"
else
H_INTERNAL_INDEX_STATE=$(nix eval --impure --expr "(import $1/$2/default.nix {}).pkgs.haskell-nix.internalHackageIndexState"|awk -F'"' '{print $2}')
fi
echo "index-state : $H_INTERNAL_INDEX_STATE" >> "$1/$2/cabal.project"
fi

# make sure .ghci could be loaded by ensuring the mode
chmod go-w "$1/$2/.ghci"
chmod go-w "$1/$2"
[[ -f "$1/$2/.ghci" ]] && chmod go-w "$1/$2/.ghci"
[[ -f "$1/$2/project.orig.name/.ghci" ]] && chmod go-w "$1/$2/project.orig.name/.ghci"
[[ -d "$1/$2" ]] && chmod go-w "$1/$2"
[[ -d "$1/$2/project.orig.name" ]] && chmod go-w "$1/$2/project.orig.name"

#[[ -f "$1/$2/cabal.project" ]] && echo "index-state : $(nix eval --quiet --raw \"(import $1/$2/default.nix {}).pkgs.haskell-nix.internalHackageIndexSate)\"" >> "$1/$2/cabal.project"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

* What

This is the mono repository for the java dump and GC analzyer application.
This is the mono repository for a haskell-based application.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
packages : ./{{name}}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ In the project directory, you can run:
### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.
The page will reload when you make changes.\
You may also see any lint errors in the console.

### `yarn test`

Expand All @@ -31,13 +31,13 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you cant go back!**
**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

Expand Down

This file was deleted.

Loading

0 comments on commit cf9dbf6

Please sign in to comment.