M
M
MFT2022-04-09 12:52:20
PHP
MFT, 2022-04-09 12:52:20

How to set up a test server so that you can test several versions of the project at the same time?

I am a programmer, I used to use git only in simpler cases. Now it was necessary to organize joint work of a small team of developers on a remote server. We are developing a web application. I would like each programmer to have his own branch, it is even desirable that each subtask has its own branches. But the difficulty is that these branches also need to be tested at the same time. That is, its own version of the application must be launched on the same development server for debugging and testing (it does not matter what the application URL will be). Preferably, but not necessarily, each branch should work with its own copy of the database.
In one of my projects, I saw that this is how you can organize work. But I don't know how to do it. Please at least point me to where to read about it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2022-04-09
@firedragon

Here is an example of jenkins
jenkins-development
The rule is there are 3 branches prod, stage, dev
in jenkins there are 3 tasks each pulls the corresponding branch from the git, then I will comment in the code

// @Library('jenkins-shared-libs') _



pipeline {
  agent any
  environment {
    projectKeyFront = 'kvn-yanotes-front'
    projectKeyBack = 'kvn-yanotes-back'
                // переменные для сборки спа приложения см. vue env files
    VUE_APP_STS_SERVER= 'https://auth.yanotes-dev.loc'
    VUE_APP_REDIRECT_BASE = 'https://yanotes-dev.loc'
    VUE_APP_CLIENT_NAME = 'yanotes_dev'
  }

    stages {

    stage('build client app') {
      agent { 
        dockerfile { 
                                        // контейнер для ноды что бы не мусорить
          filename 'Dockerfile-node'
          //additionalBuildArgs  '--build-arg version=1.0.2'
          //args '-u 1001:1001'
        }
      }
            steps {
                // просто команды для сборки
                sh 'cd ./YANotesServer/App/ && npm install --verbose'
        sh 'cd ./YANotesServer/App/ && npm run build'
        stash includes: 'YANotesServer/App/**/*', name: 'client-app'
        sh 'rm -rf ./YANotesServer/App'
            }
      
        }
    
    stage('build server app') {
      agent { 
        dockerfile { 
                                         // сборка дотнета 
          filename 'Dockerfile-dotnet-microsoft6'
        }
      }
            steps {
        unstash 'client-app'
        
        
          sh '''
            
            dotnet publish --framework net6.0 --configuration Release --runtime centos-x64 ./YANotes.sln
            
          '''
        
        
        stash includes: 'StsServer/bin/Release/net6.0/centos-x64/publish/**/*', name: 'auth'
        stash includes: 'YANotesServer/bin/Release/net6.0/centos-x64/publish/**/*', name: 'app'
            }
        }
                // устанавливаем демоны и перезапускаем их, ssh по ключам должен быть настроен
    stage('install systemd unit file') {
      agent any
      steps {
        sshagent(['jenkins-ci-yanotes-dev']) {
        
          sh 'scp SystemdUnitFiles/yanotes.service-Dev [email protected]:/etc/systemd/system/yanotes.dev.service'
          sh 'scp SystemdUnitFiles/yanotes.auth.service-Dev [email protected]:/etc/systemd/system/yanotes.auth.dev.service'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] systemctl daemon-reload'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] systemctl enable yanotes.dev'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] systemctl enable yanotes.auth.dev'
          
        }
      }
    }

    stage('deployment web application') {
      agent any
      steps {
        sshagent(['jenkins-ci-yanotes-dev']) {
          unstash 'app'
          
          sh 'ssh -o StrictHostKeyChecking=no [email protected] systemctl stop yanotes.dev'
          // sh 'ssh -o StrictHostKeyChecking=no [email protected] rm -rf /var/yanotes'
          sh 'ssh -o StrictHostKeyChecking=no [email protected]  mkdir -p /var/yanotes'
          
          sh 'scp -r ./YANotesServer/bin/Release/net6.0/centos-x64/publish/* [email protected]:/var/yanotes'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] systemctl start yanotes.dev'
        }
      }
    }

    stage('deployment auth application') {
      agent any
      steps {
        sshagent(['jenkins-ci-yanotes-dev']) {
          unstash 'auth'

          sh 'ssh -o StrictHostKeyChecking=no [email protected]  systemctl stop yanotes.auth.dev'
          // sh 'ssh -o StrictHostKeyChecking=no [email protected]  rm -rf /var/yanotesauth'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] mkdir -p /var/yanotesauth'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] mkdir -p /var/yanotesauth/logs'
          sh 'ssh -o StrictHostKeyChecking=no [email protected] chmod 777 /var/yanotesauth/logs'
          
          sh 'scp -r ./StsServer/bin/Release/net6.0/centos-x64/publish/* [email protected]:/var/yanotesauth'
          sh 'ssh -o StrictHostKeyChecking=no [email protected]  systemctl start yanotes.auth.dev'
                  
        }
      }
    }

    }
}

yanotes.auth.service-Dev
[Unit]
Description=YANotes auth service

[Service]
WorkingDirectory=/var/yanotesauth
SyslogIdentifier=yanotes.auth.dev
ExecStart=/usr/share/dotnet/dotnet /var/yanotesauth/StsServerIdentity.dll --urls="https://localhost:44356"
Restart=always
# Restart service after 10 seconds if dotnet service crashes
RestartSec=10
User=yanotes
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

S
Saboteur, 2022-04-10
@saboteur_kiev

In your case, it would be most convenient to work with docker.
At the same time, all tests must be automatic and run on localhost. With
any CI tool, set up a trigger for a commit or a pull request in order to build the project, build the docker image, run it and run autotests inside.
For manual tests, the configuration will be much, much more complicated, this is no longer a question for a toaster, but a large-scale work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question