-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mazgi/simplify-startup-process
Simplify startup process
- Loading branch information
Showing
18 changed files
with
506 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
name: use-one-platform | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
provisioning: | ||
timeout-minutes: 10 | ||
runs-on: ${{ matrix.runs-on }} | ||
strategy: | ||
matrix: | ||
platform: | ||
- aws | ||
- azure | ||
- google-cloud | ||
runs-on: | ||
- ubuntu-latest | ||
# - macos-latest | ||
# - windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Export UIDs as environment variables | ||
run: | | ||
cat<<EOE > .env | ||
# Todo https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-githubs-ip-addresses | ||
TF_VAR_allowed_ipaddr_list=["0.0.0.0/0"] | ||
EOE | ||
echo "UID=$(id -u)" >> .env | ||
echo "GID=$(id -g)" >> .env | ||
echo "DOCKER_GID=$(getent group docker | cut -d : -f 3)" >> .env | ||
- name: Generate and export Project ID as the environment variable | ||
run: | | ||
export _P=${{ matrix.platform }} | ||
export _R=${{ matrix.runs-on }} | ||
echo "PROJECT_UNIQUE_ID=${PROJECT_UNIQUE_ID}-1${_P:0:2}${_R:0:1}" >> .env | ||
env: | ||
PROJECT_UNIQUE_ID: ${{ secrets.PROJECT_UNIQUE_ID }} | ||
- name: Export credentials for AWS | ||
if: matrix.platform == 'aws' | ||
run: | | ||
echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> .env | ||
echo "AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID}" >> .env | ||
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> .env | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
- name: Export credentials for Azure | ||
if: matrix.platform == 'azure' | ||
run: | | ||
echo "ARM_CLIENT_ID=${ARM_CLIENT_ID}" >> .env | ||
echo "ARM_CLIENT_SECRET=${ARM_CLIENT_SECRET}" >> .env | ||
echo "ARM_SUBSCRIPTION_ID=${ARM_SUBSCRIPTION_ID}" >> .env | ||
echo "ARM_TENANT_ID=${ARM_TENANT_ID}" >> .env | ||
env: | ||
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} | ||
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | ||
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} | ||
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} | ||
- name: Export credentials for Google Cloud | ||
if: matrix.platform == 'google-cloud' | ||
run: | | ||
echo "CLOUDSDK_CORE_PROJECT=${CLOUDSDK_CORE_PROJECT}" >> .env | ||
env: | ||
CLOUDSDK_CORE_PROJECT: ${{ secrets.CLOUDSDK_CORE_PROJECT }} | ||
- name: Export GOOGLE_SA_KEY | ||
if: matrix.platform == 'google-cloud' | ||
run: | | ||
echo ${GOOGLE_SA_KEY} > config/credentials/google-cloud-keyfile.provisioning-owner.json | ||
jq -e '. | select(.type=="service_account")' config/credentials/google-cloud-keyfile.provisioning-owner.json > /dev/null | ||
env: | ||
GOOGLE_SA_KEY: ${{ secrets.GOOGLE_SA_KEY }} | ||
- name: (debug)Check services | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} config provisioning-use-only-${{ matrix.platform }} | ||
- name: Build containers | ||
timeout-minutes: 4 | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} build provisioning-use-only-${{ matrix.platform }} | ||
- name: Start the service | ||
timeout-minutes: 4 | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} up provisioning-use-only-${{ matrix.platform }} --detach | ||
while : | ||
do | ||
docker compose --profile=use-only-${{ matrix.platform }} ps --format=json provisioning-use-only-${{ matrix.platform }}\ | ||
| jq -e '.[] | select(.Health=="healthy")' 2> /dev/null\ | ||
&& break | ||
sleep 1 | ||
done | ||
- name: Show service logs | ||
timeout-minutes: 1 | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} logs provisioning-use-only-${{ matrix.platform }} | ||
- name: Exec Terraform - check the format for each tf file | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} exec provisioning-use-only-${{ matrix.platform }} terraform fmt -check -recursive | ||
- name: Exec Terraform - validate | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} exec provisioning-use-only-${{ matrix.platform }} terraform validate | ||
- name: Exec Terraform - dry-run | ||
timeout-minutes: 1 | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} exec provisioning-use-only-${{ matrix.platform }} terraform plan | ||
- name: Exec Terraform - apply | ||
timeout-minutes: 1 | ||
if: github.ref == 'refs/heads/main' | ||
run: | | ||
docker compose --profile=use-only-${{ matrix.platform }} exec provisioning-use-only-${{ matrix.platform }} terraform apply -auto-approve | ||
- name: Stop the service | ||
timeout-minutes: 1 | ||
run: | | ||
rm -rf tmp/run/container-*/ || true | ||
sleep 2 | ||
docker compose --profile=use-only-${{ matrix.platform }} down --remove-orphans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.env | ||
.terraform-version | ||
.terraform.lock.hcl | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"[terraform]": { | ||
"editor.defaultFormatter": "hashicorp.terraform", | ||
"editor.formatOnSave": true, | ||
"editor.formatOnSaveMode": "file" | ||
}, | ||
"[terraform-vars]": { | ||
"editor.defaultFormatter": "hashicorp.terraform", | ||
"editor.formatOnSave": true, | ||
"editor.formatOnSaveMode": "file" | ||
}, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true, | ||
"terraform.experimentalFeatures.validateOnSave": true, | ||
"terraform.languageServer.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[defaults] | ||
host_key_checking = False | ||
|
||
[ssh_connection] | ||
ssh_args = -o UserKnownHostsFile=/dev/null |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
autoload -U bashcompinit; bashcompinit | ||
autoload -Uz compinit; compinit | ||
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html#cli-command-completion-linux | ||
if (( $+commands[aws_completer] )); then | ||
complete -C aws_completer aws | ||
fi | ||
if [[ -f /etc/bash_completion.d/azure-cli ]]; then | ||
source /etc/bash_completion.d/azure-cli | ||
fi | ||
if [[ -f /usr/share/google-cloud-sdk/completion.zsh.inc ]]; then | ||
source /usr/share/google-cloud-sdk/completion.zsh.inc | ||
fi | ||
# https://www.terraform.io/cli/commands#shell-tab-completion | ||
if (( $+commands[terraform] )); then | ||
complete -C terraform terraform | ||
fi | ||
eval "$(starship init zsh)" |
2 changes: 0 additions & 2 deletions
2
Dockerfile.d/provisioning/rootfs/usr/local/bin/docker-entrypoint.start-services.zsh
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
Dockerfile.d/provisioning/rootfs/usr/local/bin/docker-util.keep-running.zsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env -S zsh -eu | ||
|
||
readonly local SCRIPT_NAME=$(basename $0) | ||
readonly local STATUS_FILE=/var/run/container-stat-myself/status.json | ||
getStatusFilePath () { | ||
echo ${STATUS_FILE:?} | ||
} | ||
resetStatus () { | ||
echoDebug "Reset the status." | ||
readonly local _dir=$(dirname ${STATUS_FILE:?}) | ||
sudo mkdir -p ${_dir:?}/ | ||
sudo chmod 777 ${_dir:?}/ | ||
echo '{}' > ${STATUS_FILE:?} | ||
} | ||
updateStatusToSucceeded () { | ||
echoDebug "Update the status to succeeded." | ||
readonly local _tmpfile=${STATUS_FILE:?}.tmp | ||
cp ${STATUS_FILE:?} ${_tmpfile:?} | ||
jq '. + {succeeded:true}' ${_tmpfile:?} | tee ${STATUS_FILE:?} | ||
rm -rf ${_tmpfile:?} | ||
} | ||
updateStatusToFailed () { | ||
echoDebug "Update the status to succeeded." | ||
readonly local _tmpfile=${STATUS_FILE:?}.tmp | ||
cp ${STATUS_FILE:?} ${_tmpfile:?} | ||
jq '. + {succeeded:false}' ${_tmpfile:?} | tee ${STATUS_FILE:?} | ||
rm -rf ${_tmpfile:?} | ||
} | ||
|
||
showHelp() { | ||
echo "Usage: ${SCRIPT_NAME} [OPTIONS]" | ||
echo "Options:" | ||
echo "\t-h, --help\t\tShow this help message." | ||
echo "\t-p, --print-status-file-path\t\t(TBD)." | ||
echo "\t-f, --record-failure\t\t(TBD)." | ||
echo "\t-r, --reset-status\t\t(TBD)." | ||
echo "\t-s, --record-success\t\t(TBD)." | ||
echo "\t-w, --wait-signals\t\t(TBD)." | ||
} | ||
|
||
args=$(getopt -o hpfrsw -l help,print-status-file-path,record-failure,reset-status,record-success,wait-signals -- "$@") || exit 1 | ||
eval "set -- $args" | ||
while [ $# -gt 0 ]; do | ||
case $1 in | ||
-h | --help) | ||
showHelp | ||
shift; exit 1;; | ||
-p | --print-status-file-path) | ||
getStatusFilePath | ||
shift; exit 0;; | ||
-f | --record-failure) | ||
updateStatusToFailed | ||
shift; exit 0;; | ||
-r | --reset-status) | ||
resetStatus | ||
shift; exit 0;; | ||
-s | --record-success) | ||
updateStatusToSucceeded | ||
shift; exit 0;; | ||
-w | --wait-signals) | ||
# Nothing todo. | ||
shift; break;; | ||
--) | ||
shift; break;; | ||
esac | ||
done | ||
|
||
trapSigTerm () { | ||
echoDebug "Exit by SIGTERM." | ||
trap SIGTERM | ||
exit 0 | ||
} | ||
trap 'trapSigTerm' SIGTERM | ||
|
||
echoInfo '✅ You are all set!' | ||
# http:https://patorjk.com/software/taag/#p=display&f=Calvin%20S&t=you're%20all%20set | ||
echoDebug '┬ ┬┌─┐┬ ┬┬─┐┌─┐ ┌─┐┬ ┬ ┌─┐┌─┐┌┬┐' | ||
echoDebug '└┬┘│ ││ │├┬┘├┤ ├─┤│ │ └─┐├┤ │ ' | ||
echoDebug ' ┴ └─┘└─┘┴└─└─┘ ┴ ┴┴─┘┴─┘ └─┘└─┘ ┴ ' | ||
echoDebug "Turn in infinity sleep..." | ||
sleep infinity &; readonly local SLEEP_PID=$! | ||
wait ${SLEEP_PID} | ||
exit $? |
Oops, something went wrong.