I am trying to build CI/CD environment using github action.

Below script helps me to build the docker image, but returning an error

[django.db.utils.OperationalError: could not connect to server: Operation timed out
Is the server running on host “db-postgresql-nyc1.b.db.ondigitalocean.com” (157.230.224.47) and accepting
TCP/IP connections on port 23052?](http://)

localhost can successfully migrate the database without any errors. However, when I use github action, it fails.

Maybe I should try manipulating firewalls from digital ocean or github? If you have any suggestion, please let me know.

name: Python application

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: docker login
      env:
        DOCKER_ID: ${{ secrets.DOCKER_USER }}
        DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} 
      run: |
        docker login -u $DOCKER_ID -p $DOCKER_PASSWORD
    - name: docker build
      run: |
        docker rmi --force "dummy/dummy-community:latest"
        docker build -t polls . 
    - name: docker migrate
      run: |
        docker run --env-file env polls sh -c "python manage.py makemigrations && python manage.py migrate"
    - name: docker tag image
      run: |
        docker tag polls:latest dummy/dummy-community:latest
    - name: docker push
      run: |
        docker push dummy/dummy-community:latest
    - name: kubectl deploy
      run: |
        kubectl delete pods polls-app
        kubectl get deploy polls-app
1 comment
  • The error Operation timed out error can happen when current machine or resource won’t allow to connect which was stated from the below link.

    https://www.digitalocean.com/docs/databases/postgresql/resources/troubleshoot-connections/

    Also, I have added services for postgres to wait until it starts before running the migration.

    https://docs.github.com/en/actions/guides/creating-postgresql-service-containers

    name: Python application
    
    on:
      push:
        branches: [ master ]
      pull_request:
        branches: [ master ]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        services:
          postgres:
            image: postgres:12
            env:
              POSTGRES_USER: doadmin
              POSTGRES_PASSWORD: bzxc9yuyjly1li8w
              POSTGRES_DB: defaultdb
              hostname: postgres
            ports:
                - 25060:25060
            options: >-
              --health-cmd pg_isready
              --health-interval 10s
              --health-timeout 5s
              --health-retries 5
        steps:
        - uses: actions/checkout@v2
        - name: docker login
          env:
            DOCKER_ID: ${{ secrets.DOCKER_ID }}
            DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} 
          run: |
            docker login -u $DOCKER_ID -p $DOCKER_PASSWORD
        - name: docker build
          run: |
            docker rmi --force "sweforever92/sweforever92-community:latest"
            docker build -t polls . 
        - name: docker migrate
          run: |
            docker run --env-file env polls sh -c "python manage.py makemigrations && python manage.py migrate"
        - name: docker tag image
          run: |
            docker tag polls:latest sweforever92/sweforever92-community:latest
        - name: docker push
          run: |
            docker push sweforever92/sweforever92-community:latest
        - name: kubectl deploy
          run: |
            kubectl delete deploy polls-app
            cd yaml
            kubectl apply -f polls-deployment.yaml
    
    

    I have tried opening TCP port from ssh, but still not working.

    ufw allow 25060/tcp
    

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer