diff --git a/deploy.yaml b/deploy.yaml deleted file mode 100644 index 76d008c..0000000 --- a/deploy.yaml +++ /dev/null @@ -1,102 +0,0 @@ -name: Codepet deploy - -on: - push: - branches: [ 'main', 'develop' ] - -jobs: - build_and_push_to_docker_hub_backend: - name: Push Docker image to DockerHub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Docker - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Push to DockerHub - uses: docker/build-push-action@v4 - with: - context: ./ - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend:latest - - build_and_push_to_docker_hub_nginx: - name: Push gateway Docker image to DockerHub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Docker - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Push to DockerHub - uses: docker/build-push-action@v4 - with: - context: ./infra/nginx/ - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_nginx:latest - - deploy: - runs-on: ubuntu-latest - needs: - - build_and_push_to_docker_hub_backend - - build_and_push_to_docker_hub_nginx - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - name: Create project directory and .env-file - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USER }} - key: ${{ secrets.SSH_KEY }} - passphrase: ${{ secrets.SSH_PASSPHRASE }} - script: | - sudo rm -r ${{ secrets.PROJECT_NAME }} - sudo mkdir -p ${{ secrets.PROJECT_NAME }}/infra - sudo chmod 777 ${{ secrets.PROJECT_NAME }}/infra - sudo cat > ${{ secrets.PROJECT_NAME }}/infra/.env << _EOF_ - POSTGRES_DB=${{ secrets.POSTGRES_DB }} - POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} - POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} - POSTGRES_USER=${{ secrets.POSTGRES_USER }} - POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} - PROJECT_NAME=${{ secrets.PROJECT_NAME }} - SECRET_KEY=${{ secrets.SECRET_KEY }} - DOCKERHUB_USERNAME_FRONT=${{ secrets.DOCKERHUB_USERNAME_FRONT }} - DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} - ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} - _EOF_ - - name: Copy docker-compose-prod.yaml via ssh - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USER }} - key: ${{ secrets.SSH_KEY }} - passphrase: ${{ secrets.SSH_PASSPHRASE }} - source: "infra/docker-compose-prod.yaml" - target: "codepet" - - name: Executing remote ssh commands to deploy - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USER }} - key: ${{ secrets.SSH_KEY }} - passphrase: ${{ secrets.SSH_PASSPHRASE }} - script: | - cd codepet/infra - sudo docker compose -f docker-compose-prod.yaml pull - sudo docker compose -f docker-compose-prod.yaml down - sudo docker compose -f docker-compose-prod.yaml up -d - sudo docker compose -f docker-compose-prod.yaml exec backend python manage.py migrate - sudo docker compose -f docker-compose-prod.yaml exec backend python manage.py collectstatic --no-input - sudo docker system prune -f