Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GitHub Workflow User don't exist

with Workflow GitHub Actions, I want to set up a script to automatically trigger the deployment from github of a python django application on an ubuntu-server with apache2 wsgi, the script must allow to be able to initiate a new installation or if the installation already exists update the application.

Error on STEP : Set Project – Env path

USER_RUN: www-datas
chown: invalid user: ‘www-datas:www-datas’
Error: Process completed with exit code 1.
name: Django-wsgi

env:
  PROJECT_NAME: 'myproject'
  PROJECT_DOMAIN: 'myproject.tld'
  PROJECT_ENV: 'venv_myproject'
  PROJECT_PATH: '/var/www/vhosts'
  PROJECT_GIT_REPO: 'github.com/xxxx/plop.git'
  PYTHON_VERSION: '3.10'
  USER_RUN: 'www-datas'

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      max-parallel: 4

    steps:
      - uses: actions/checkout@v3

      - name: 'Set Project - Env path'
        run: |
          sudo mkdir -p '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs'
          chown -R ${{ env.USER_RUN }}:${{ env.USER_RUN }} '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs'
          cd '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs'

      - name: 'Set Project - Prerequisites'
        run: |
          sudo apt-get update
          sudo apt-get install python3-pip -y
          sudo apt-get install apache2 libapache2-mod-wsgi-py3 -y
          sudo apt-get install libpq-dev python-is-python3 python3-dev -y

      - name: Configure Apache2 WSGI
        run: |
          if [ -f ${{ env.PROJECT_ENV }}.conf ]; then cp ${{ env.PROJECT_ENV }}.conf /etc/apache2/sites-available/${{ env.PROJECT_ENV }}.conf; fi

      - name: 'Set up Python version'
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}
          check-latest: true
          cache : 'pip'

      - name: 'Create and start virtual environment'
        run: |
          cd '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs'
          python -m venv ${{ env.PROJECT_ENV }}
          source ${{ env.PROJECT_ENV }}/bin/activate

      - name: 'Install Dependencies'
        run: |
          cd '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs'
          python -m pip install --upgrade --force pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

      - name: Run migrations
        run: |
          python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' makemigrations
          python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' migrate
          python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' migrate --run-syncdb
          python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' check

  deploy:
      permissions:
        contents: none

      runs-on: ubuntu-latest

      needs: build

      environment:
        name: 'Development'
        url: ${{ env.PROJECT_DOMAIN }}

      steps:
        - name: 'Deploy Web App'
          id: deploy-to-webapp
          run: if [ -d .git ]; then git pull; else; git clone 'https://${{secrets.GIT_USR}}:${{secrets.GIT_PWD}}@${{ env.PROJECT_GIT_REPO }}' ; fi

        - name: Run migrations
          run: |
            python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' makemigrations
            python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' migrate
            python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' migrate --run-syncdb
            python '${{ env.PROJECT_PATH }}/${{ env.PROJECT_ENV }}/${{ env.PROJECT_DOMAIN }}/httpdocs/manage.py' check

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re running on the ubuntu-latest GitHub Hosted runner. That code doesn’t run on your ubuntu Django server, but it runs on a VM hosted by Github somewhere in Azure. That user that you’re trying to assign rights to does not exist on the GitHub Hosted Runners.

If you have a self-hosted runner installed on the target server, then change the runs-on to something like:

  runs-on: [self-hosted, djangoserver]

Note: the exact labels are the ones that were assigned to the self-hosted runner on installation.

See:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading