diff --git a/.github/workflows/cd_stage.yml b/.github/workflows/cd_stage.yml new file mode 100644 index 0000000..0c22755 --- /dev/null +++ b/.github/workflows/cd_stage.yml @@ -0,0 +1,36 @@ +name: Deploy to staging Server +on: + push: + branches: + - "develop" + +concurrency: + group: staging + cancel-in-progress: true + +jobs: + deploy-staging: + runs-on: ubuntu-latest + steps: + - name: Checkout to source code + uses: actions/checkout@v3 + - name: Install SSH Key + uses: shimataro/ssh-key-action@v2 + with: + key: ${{ secrets.KEY }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Stop docker swarm and cleanup services + run: | + ssh -J ${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST1 }},${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST2 }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd /virtual_instrument_museum && sudo docker compose stop" + - name: Log git branch we're on + run: | + ssh -J ${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST1 }},${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST2 }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd /virtual_instrument_museum && sudo git branch --all -v" + - name: Fetch on dev branch + run: | + ssh -J ${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST1 }},${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST2 }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd /virtual_instrument_museum && sudo git fetch origin develop && sudo git merge origin/develop" + - name: Build docker images + run: | + ssh -J ${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST1 }},${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST2 }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd /virtual_instrument_museum && sudo docker compose build" + - name: Start the service + run: | + ssh -J ${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST1 }},${{ secrets.PROXY_USERNAME }}@${{ secrets.PROXY_HOST2 }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "cd /virtual_instrument_museum && sudo docker compose up -d" \ No newline at end of file