From 846d777cfaace85d142effeec5383c4a62ab602b Mon Sep 17 00:00:00 2001 From: Nikolay Kiryanov Date: Fri, 23 Jul 2021 00:28:22 +0300 Subject: [PATCH] staging ci/cd --- ...deploy.yaml => prod_build_and_deploy.yaml} | 4 +- .../workflows/staging_build_and_deploy.yaml | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) rename .github/workflows/{build_and_deploy.yaml => prod_build_and_deploy.yaml} (97%) create mode 100644 .github/workflows/staging_build_and_deploy.yaml diff --git a/.github/workflows/build_and_deploy.yaml b/.github/workflows/prod_build_and_deploy.yaml similarity index 97% rename from .github/workflows/build_and_deploy.yaml rename to .github/workflows/prod_build_and_deploy.yaml index ad941f3..d276736 100644 --- a/.github/workflows/build_and_deploy.yaml +++ b/.github/workflows/prod_build_and_deploy.yaml @@ -1,9 +1,9 @@ -name: build and deploy +name: prod CI/CD on: push: branches: - - dev + - main jobs: build_and_push_to_docker_hub: name: Push Docker image to Docker Hub diff --git a/.github/workflows/staging_build_and_deploy.yaml b/.github/workflows/staging_build_and_deploy.yaml new file mode 100644 index 0000000..10e7a7c --- /dev/null +++ b/.github/workflows/staging_build_and_deploy.yaml @@ -0,0 +1,49 @@ +name: staging CI/CD + +on: + push: + branches: + - staging +jobs: + build_and_push_to_docker_hub: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + environment: staging_environment + steps: + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to Docker + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Push to Docker Hub + uses: docker/build-push-action@v2 + with: + file: ./Dockerfile + build-args: | + REACT_APP_API_URL=${{ secrets.REACT_APP_API_URL }} + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/staging-bbbs-frontend:latest + deploy: + runs-on: ubuntu-latest + needs: build_and_push_to_docker_hub + environment: staging_environment + steps: + - + name: execute remote ssh commands to deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.SSH_KEY }} + script: | + cd ${{ secrets.SERVER_FOLDER }} + git checkout ${{ secrets.BRANCH }} + export COMPOSE_FILE=${{ secrets.COMPOSE_FILE }} + docker pull ${{ secrets.DOCKER_USERNAME }}/staging-bbbs-frontend:latest + docker-compose down + docker-compose up -d --build