From 0d4e7e246cf13ef1920a612430cce5f1c682aad5 Mon Sep 17 00:00:00 2001 From: Pattaradanai Kamsuan Date: Tue, 24 Sep 2024 20:07:15 +0700 Subject: [PATCH] This commit enables automated deployment of the worker application based on the branch being pushed to. --- .github/workflows/main.yml | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..01b3b24 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,49 @@ +name: Deploy worker + +on: + push: + branches: ["main", "dev"] + + workflow_dispatch: + +jobs: + deploy: + runs-on: ${{ github.ref == 'refs/heads/main' && 'ipca-prod' || 'ipca-test' }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up environment + run: | + # MYSQL + echo "DB_HOST"=${{ secrets.DB_HOST }} >> .env + echo "DB_PORT"=${{ secrets.DB_PORT }} >> .env + echo "DB_EXPOSE_PORT"= ${{ secrets.DB_EXPOSE_PORT }} >> .env + echo "DB_NAME"=${{ secrets.DB_NAME }} >> .env + echo "DB_USER"=${{ secrets.DB_USER }} >> .env + echo "DB_PASSWORD"=${{ secrets.DB_PASSWORD }} >> .env + echo "DB_ROOT_PASSWORD"=${{ secrets.DB_ROOT_PASSWORD }} >> .env + echo "DB_DRIVER"=${{ secrets.DB_DRIVER }} >> .env + + # REDIS + echo "REDIS_HOST"=${{ secrets.REDIS_HOST }} >> .env + echo "REDIS_PORT"=${{ secrets.REDIS_PORT }} >> .env + echo "REDIS_EXPOSE_PORT"=${{ secrets.REDIS_EXPOSE_PORT }} >> .env + echo "REDIS_USER"=${{ secrets.REDIS_USER }} >> .env + echo "REDIS_PASSWORD"=${{ secrets.REDIS_PASSWORD }} >> .env + + # RABBITMQ + echo "RABBITMQ_HOST"=${{ secrets.RABBITMQ_HOST }} >> .env + echo "RABBITMQ_PORT"=${{ secrets.RABBITMQ_PORT }} >> .env + echo "RABBITMQ_USER"=${{ secrets.RABBITMQ_USER }} >> .env + echo "RABBITMQ_PASSWORD"=${{ secrets.RABBITMQ_PASSWORD }} >> .env + echo "RABBITMQ_QUEUENAME"=${{ secrets.RABBITMQ_QUEUENAME }} >> .env + + - name: Deploy Web Application + if: github.ref == 'refs/heads/master' + run: docker compose -f docker-compose.prod.yml up -d --build --force-recreate && docker system prune -f + + - name: Deploy Web Application (Dev) + if: github.ref == 'refs/heads/dev' + run: docker compose -f docker-compose.dev.yml up -d --build --force-recreate && docker system prune -f