Initial Implementation of Refresh Cluster

This commit is contained in:
2024-10-18 01:37:52 -03:00
parent 4d69fedc81
commit 6eb74bbdb7
3 changed files with 43 additions and 33 deletions

View File

@@ -9,7 +9,7 @@ on:
- staging - staging
jobs: jobs:
build: deploy:
name: Deploy to Cluster name: Deploy to Cluster
environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }} environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@@ -5,40 +5,32 @@ on:
types: [refresh-deployments] types: [refresh-deployments]
jobs: jobs:
refresh-deployments: refresh_deployment:
name: Refresh deployments name: Refresh Kubernetes Deployments
environment: prod environment: prod
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 30
env:
deployments: ${{ github.event.client_payload.deployments }}
steps: steps:
- name: Checkout - uses: actions/checkout@v4
uses: actions/checkout@v3 - name: Writing Env File
run: |
echo "${{ secrets.ENV_FILE }}" | base64 -d > .env
- name: Executing Remote Commands - Refresh All Deployments - name: Set Kubernetes Context
env: uses: azure/k8s-set-context@v1
deployments: ${{ github.event.client_payload.deployments }} with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Refresh Deployments
if: ${{ env.deployments == '' }} if: ${{ env.deployments == '' }}
uses: appleboy/ssh-action@master run: |
with: ./deploy.sh -f .env -r
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
script: |
[[ -d infra-hideyoshi.com ]] && \
cd infra-hideyoshi.com && \
./refresh.sh
- name: Executing Remote Commands - Refresh Specific Deployments - name: Refresh Specific Deployments
env:
deployments: ${{ github.event.client_payload.deployments }}
if: ${{ env.deployments != '' }} if: ${{ env.deployments != '' }}
uses: appleboy/ssh-action@master run: |
with: ./deploy.sh -f .env -r ${{ env.deployments }}
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
script: |
[[ -d infra-hideyoshi.com ]] && \
cd infra-hideyoshi.com && \
./refresh.sh ${{ env.deployments }}

View File

@@ -150,6 +150,18 @@ main() {
refresh() { refresh() {
deployments=$1
if [[ -z $1 ]]; then
deployments=(
"redis-deployment"
"storage-deployment"
"backend-deployment"
"frontend-deployment"
)
fi
for deployment in ${deployments[@]}; do
kubectl rollout restart deployment/${deployment} -n ${KUBE_NAMESPACE}
done
} }
@@ -157,7 +169,7 @@ environment="remote"
setup_minikube="false" setup_minikube="false"
execution_mode="deploy" execution_mode="deploy"
while getopts ":f:e:mh" opt; do while getopts ":f:e:mrh" opt; do
case ${opt} in case ${opt} in
f ) f )
echo "Reading env file: ${OPTARG}" echo "Reading env file: ${OPTARG}"
@@ -178,6 +190,12 @@ while getopts ":f:e:mh" opt; do
r ) r )
echo "Executing Refresh" echo "Executing Refresh"
execution_mode="refresh" execution_mode="refresh"
eval nextopt=\${$OPTIND}
if [[ -n $nextopt && $nextopt != -* ]]; then
OPTIND=$((OPTIND + 1))
refresh_deployments=($nextopt)
fi
;; ;;
*) *)
echo "Invalid option: $OPTARG" echo "Invalid option: $OPTARG"
@@ -189,7 +207,7 @@ done
if [[ $execution_mode == "deploy" ]]; then if [[ $execution_mode == "deploy" ]]; then
main main
elif [[ $execution_mode == "refresh" ]]; then elif [[ $execution_mode == "refresh" ]]; then
refresh [[ -z $refresh_deployments ]] && refresh || refresh $refresh_deployments
else else
echo "Invalid execution mode: $execution_mode" echo "Invalid execution mode: $execution_mode"
exit 1 exit 1