diff --git a/.github/workflows/deploy-cluster.yml b/.github/workflows/deploy-cluster.yml index 647e6c2..e295175 100644 --- a/.github/workflows/deploy-cluster.yml +++ b/.github/workflows/deploy-cluster.yml @@ -9,7 +9,7 @@ on: - staging jobs: - build: + deploy: name: Deploy to Cluster environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }} runs-on: ubuntu-latest diff --git a/.github/workflows/refresh-deployment.yml b/.github/workflows/refresh-deployment.yml index 36adfc7..3df41d6 100644 --- a/.github/workflows/refresh-deployment.yml +++ b/.github/workflows/refresh-deployment.yml @@ -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 }} \ No newline at end of file + run: | + ./deploy.sh -f .env -r ${{ env.deployments }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index e1b9eab..e61dc3f 100755 --- a/deploy.sh +++ b/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