working on develop_for_35 fix #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Django CI | |
| on: [push] | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install flake8 | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 | |
| - name: Run flake8 | |
| run: flake8 --config .flake8 . | |
| test: | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:13 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: test_db | |
| POSTGRES_HOST: localhost | |
| POSTGRES_PORT: 5432 | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| env: | |
| SECRET_KEY: ${{secrets.SECRET_KEY}} | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: test_db | |
| POSTGRES_HOST: localhost | |
| POSTGRES_PORT: 5432 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Check PostgreSQL connection | |
| run: pg_isready -h localhost -p 5432 -U postgres | |
| - name: Run tests | |
| run: python manage.py test | |
| build: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v3 | |
| - name: Log in in Docker hub | |
| env: | |
| DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| run: echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
| - name: Build Docker image | |
| run: docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:${{ github.sha }} . | |
| - name: Push Docker image to Docker Hub | |
| run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:${{ github.sha }} | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up SSH | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: | | |
| ${{ secrets.SSH_KEY }} | |
| ssh-public-key: ${{ secrets.SSH_PUB_KEY }} | |
| - name: Deploy to server | |
| run: | | |
| ssh -T -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} << 'EOF' | |
| cd /var/www/HomeWork_30.1/ | |
| sudo git checkout feature/Docker_init | |
| sudo git pull | |
| if [ -d "static" ]; then | |
| echo "Static folder exists." | |
| else | |
| echo "Static folder does not exist. Creating it now." | |
| mkdir static | |
| fi | |
| sudo sysctl vm.overcommit_memory=1 | |
| sudo docker compose down || True | |
| sudo docker compose up -d --build | |
| EOF |