From 9fe39272e1bbb43a41b3bc312282b6e395e0a22e Mon Sep 17 00:00:00 2001 From: Chengming-Li <115936688+Chengming-Li@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:12:55 -0700 Subject: [PATCH] Update and rename cd-master.yml to cd-prod.yml --- .github/workflows/cd-master.yml | 36 ------------------------------- .github/workflows/cd-prod.yml | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/cd-master.yml create mode 100644 .github/workflows/cd-prod.yml diff --git a/.github/workflows/cd-master.yml b/.github/workflows/cd-master.yml deleted file mode 100644 index 8619d4a61..000000000 --- a/.github/workflows/cd-master.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: - Deploy to Staging - -on: - push: - branches: [ master ] - workflow_run: - workflows: - - "Build Frontend" - - "Build Backend" - types: - - completed - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: SSH - run: | - mkdir -p ~/.ssh - echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh -i ~/.ssh/id_rsa root@hozer-51.ocf.berkeley.edu << EOF - cd /berkeleytime - git checkout master - git pull - docker compose up --build -d - docker tag berkeleytime-backend octoberkeleytime/bt-backend:latest - docker tag berkeleytime-frontend octoberkeleytime/bt-frontend:latest - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker push octoberkeleytime/bt-backend:latest - docker push octoberkeleytime/bt-frontend:latest - kubectl rollout restart deployment bt-staging-app-backend - kubectl rollout restart deployment bt-staging-app-frontend - EOF diff --git a/.github/workflows/cd-prod.yml b/.github/workflows/cd-prod.yml new file mode 100644 index 000000000..ccef726ed --- /dev/null +++ b/.github/workflows/cd-prod.yml @@ -0,0 +1,38 @@ +name: + Deploy to Staging + +on: + repository_dispatch: + types: [trigger-workflow] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build Docker Image + run: docker build -t berkeleytime-backend ./backend/ + - name: Tag Docker Image + run: docker tag berkeleytime-backend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:${{ github.sha }} + - name: Push Docker Image + run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:${{ github.sha }} + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@v1.0.3 + with: + host: hozer-51.ocf.berkeley.edu + username: root + key: ${{ secrets.SSH_KEY }} + port: 22 + script: | + helm install bt-prod-app-${{ github.sha }} ./app --namespace=bt \ + --set host=prod.stanfurdtime.com \ + --set mongoUri=mongodb://bt-prod-mongo-mongodb.bt.svc.cluster.local:27017/bt \ + --set redisUri=redis://bt-prod-redis-master.bt.svc.cluster.local:6379 \ + --set nodeEnv=development