Initial Implementation of Refresh Cluster
This commit is contained in:
2
.github/workflows/deploy-cluster.yml
vendored
2
.github/workflows/deploy-cluster.yml
vendored
@@ -9,7 +9,7 @@ on:
|
||||
- staging
|
||||
|
||||
jobs:
|
||||
build:
|
||||
deploy:
|
||||
name: Deploy to Cluster
|
||||
environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
52
.github/workflows/refresh-deployment.yml
vendored
52
.github/workflows/refresh-deployment.yml
vendored
@@ -5,40 +5,32 @@ on:
|
||||
types: [refresh-deployments]
|
||||
|
||||
jobs:
|
||||
refresh-deployments:
|
||||
name: Refresh deployments
|
||||
refresh_deployment:
|
||||
name: Refresh Kubernetes Deployments
|
||||
environment: prod
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
deployments: ${{ github.event.client_payload.deployments }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Writing Env File
|
||||
run: |
|
||||
echo "${{ secrets.ENV_FILE }}" | base64 -d > .env
|
||||
|
||||
- name: Set Kubernetes Context
|
||||
uses: azure/k8s-set-context@v1
|
||||
with:
|
||||
method: kubeconfig
|
||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||
|
||||
- name: Executing Remote Commands - Refresh All Deployments
|
||||
env:
|
||||
deployments: ${{ github.event.client_payload.deployments }}
|
||||
- name: Refresh Deployments
|
||||
if: ${{ env.deployments == '' }}
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
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
|
||||
run: |
|
||||
./deploy.sh -f .env -r
|
||||
|
||||
- name: Executing Remote Commands - Refresh Specific Deployments
|
||||
env:
|
||||
deployments: ${{ github.event.client_payload.deployments }}
|
||||
- name: Refresh Specific Deployments
|
||||
if: ${{ env.deployments != '' }}
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
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 }}
|
||||
run: |
|
||||
./deploy.sh -f .env -r ${{ env.deployments }}
|
||||
22
deploy.sh
22
deploy.sh
@@ -150,6 +150,18 @@ main() {
|
||||
|
||||
|
||||
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"
|
||||
execution_mode="deploy"
|
||||
|
||||
while getopts ":f:e:mh" opt; do
|
||||
while getopts ":f:e:mrh" opt; do
|
||||
case ${opt} in
|
||||
f )
|
||||
echo "Reading env file: ${OPTARG}"
|
||||
@@ -178,6 +190,12 @@ while getopts ":f:e:mh" opt; do
|
||||
r )
|
||||
echo "Executing Refresh"
|
||||
execution_mode="refresh"
|
||||
|
||||
eval nextopt=\${$OPTIND}
|
||||
if [[ -n $nextopt && $nextopt != -* ]]; then
|
||||
OPTIND=$((OPTIND + 1))
|
||||
refresh_deployments=($nextopt)
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: $OPTARG"
|
||||
@@ -189,7 +207,7 @@ done
|
||||
if [[ $execution_mode == "deploy" ]]; then
|
||||
main
|
||||
elif [[ $execution_mode == "refresh" ]]; then
|
||||
refresh
|
||||
[[ -z $refresh_deployments ]] && refresh || refresh $refresh_deployments
|
||||
else
|
||||
echo "Invalid execution mode: $execution_mode"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user