From 7075e86a26590723033523ccff65998d827d575d Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Wed, 16 Oct 2024 23:19:04 -0300 Subject: [PATCH] Inicia Implementacao de Refresh --- .github/workflows/deploy-cluster.yml | 30 ++++++++++++++ .github/workflows/deploy-prod.yml | 58 ---------------------------- .github/workflows/deploy-staging.yml | 56 --------------------------- deploy.sh | 18 ++++++++- 4 files changed, 47 insertions(+), 115 deletions(-) create mode 100644 .github/workflows/deploy-cluster.yml delete mode 100644 .github/workflows/deploy-prod.yml delete mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-cluster.yml b/.github/workflows/deploy-cluster.yml new file mode 100644 index 0000000..647e6c2 --- /dev/null +++ b/.github/workflows/deploy-cluster.yml @@ -0,0 +1,30 @@ +name: remote ssh command + +on: + repository_dispatch: + types: [deploy-prod] + push: + branches: + - main + - staging + +jobs: + build: + name: Deploy to Cluster + environment: ${{ github.ref_name == 'main' && 'prod' || 'staging' }} + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - 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: Execute deploy + run: | + ./deploy.sh -f .env \ No newline at end of file diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml deleted file mode 100644 index d1a7e2a..0000000 --- a/.github/workflows/deploy-prod.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: remote ssh command - -on: - repository_dispatch: - types: [deploy-prod] - push: - branches: - - main - -jobs: - build: - name: Build - environment: prod - runs-on: ubuntu-latest - timeout-minutes: 30 - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.8 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - - name: Create Config Json File - run: | - echo "${{ secrets.CONFIG_JSON }}" | base64 -d > config.json - - - name: Inserts Prod Enviromental Variables - run: | - python -m pip install --upgrade pip pipenv - pipenv install - pipenv run python setup.py -e prod -f config.json - - - name: copy file via ssh - uses: appleboy/scp-action@master - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USER }} - port: ${{ secrets.SSH_PORT }} - key: ${{ secrets.SSH_KEY }} - source: "." - target: "infra-hideyoshi.com" - - - name: executing remote ssh commands - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USER }} - port: ${{ secrets.SSH_PORT }} - key: ${{ secrets.SSH_KEY }} - command_timeout: 30m - script: | - sudo apt update && sudo apt install -y jq - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - source ~/.profile - cd infra-hideyoshi.com - ./deploy.sh --prod - ./refresh.sh \ No newline at end of file diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml deleted file mode 100644 index 520ab1e..0000000 --- a/.github/workflows/deploy-staging.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: remote ssh command - -on: - push: - branches: - - staging - -jobs: - build: - name: Build - environment: staging - runs-on: ubuntu-latest - timeout-minutes: 30 - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.8 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - - name: Create Config Json File - run: | - echo "${{ secrets.CONFIG_JSON }}" | base64 -d > config.json - - - name: Inserts Prod Enviromental Variables - run: | - python -m pip install --upgrade pip pipenv - pipenv install - pipenv run python setup.py -e staging -f config.json - - - name: copy file via ssh - uses: appleboy/scp-action@master - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USER }} - port: ${{ secrets.SSH_PORT }} - key: ${{ secrets.SSH_KEY }} - source: "." - target: "infra-hideyoshi.com" - - - name: executing remote ssh commands - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USER }} - port: ${{ secrets.SSH_PORT }} - key: ${{ secrets.SSH_KEY }} - command_timeout: 30m - script: | - sudo apt update && sudo apt install -y jq - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - source ~/.profile - cd infra-hideyoshi.com - ./deploy.sh --staging - ./refresh.sh diff --git a/deploy.sh b/deploy.sh index 0f0df8e..e1b9eab 100755 --- a/deploy.sh +++ b/deploy.sh @@ -149,8 +149,13 @@ main() { } +refresh() { +} + + environment="remote" setup_minikube="false" +execution_mode="deploy" while getopts ":f:e:mh" opt; do case ${opt} in @@ -170,6 +175,10 @@ while getopts ":f:e:mh" opt; do echo "Usage: deploy.sh [-f ] [-e ] [-m ]" exit 0 ;; + r ) + echo "Executing Refresh" + execution_mode="refresh" + ;; *) echo "Invalid option: $OPTARG" exit 1 @@ -177,4 +186,11 @@ while getopts ":f:e:mh" opt; do esac done -main \ No newline at end of file +if [[ $execution_mode == "deploy" ]]; then + main +elif [[ $execution_mode == "refresh" ]]; then + refresh +else + echo "Invalid execution mode: $execution_mode" + exit 1 +fi \ No newline at end of file