Commit d0d25941 authored by Giuseppe Carboni's avatar Giuseppe Carboni
Browse files

Merge branch 'centos_7_compatibility' of https://github.com/discos/discos into fix-issue-901

parents 53cffb47 98966072
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
#!/usr/bin/env python
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
import os
import io

TOKEN_FILE = 'token.json'
VM_FILE_PATH = '/home/runner/discos_manager.ova'
ARCHIVE_FILE_PATH = '/home/runner/vagrant.tar.gz'
SCOPES = ['https://www.googleapis.com/auth/drive.readonly']

# Create the token file from the GH Secret
with open(TOKEN_FILE, 'w') as tokenfile:
    tokenfile.write(os.environ.get('GOOGLE_DRIVE_TOKEN'))

# Authenticate with the token and eventually update it
creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
if creds.expired and creds.refresh_token:
    creds.refresh(Request())

# Download the VM
creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
if creds.expired and creds.refresh_token:
    creds.refresh(Request())

service = build('drive', 'v3', credentials=creds)

downloader = MediaIoBaseDownload(
    io.FileIO(ARCHIVE_FILE_PATH, 'wb'),
    service.files().get_media(
        fileId=os.environ.get('PROVISIONED_ARCHIVE_GDRIVE_ID')
    )
)
done = False
while not done:
    _, done = downloader.next_chunk()

downloader = MediaIoBaseDownload(
    io.FileIO(VM_FILE_PATH, 'wb'),
    service.files().get_media(
        fileId=os.environ.get('PROVISIONED_VM_GDRIVE_ID'),
    ),
    chunksize=5*1024*1024
)
done = False
while not done:
    _, done = downloader.next_chunk()

# Finally update the token file
with open(TOKEN_FILE, 'w') as tokenfile:
    tokenfile.write(creds.to_json())
+0 −4
Original line number Diff line number Diff line
google-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
+36 −21
Original line number Diff line number Diff line
@@ -2,10 +2,22 @@ name: DISCOS deployment and build

on:
  push:
  workflow_dispatch:
  pull_request:

jobs:
  wait-for-download:
    name: Wait for any pending download
    runs-on: ubuntu-latest
    concurrency:
      group: download
      cancel-in-progress: false
    steps:
      - name: Go on with deployment
        run: true
  deploy-discos:
    name: Deploy DISCOS
    runs-on: ubuntu-latest
    needs: wait-for-download
    env:
      REPOSITORY_TOKEN: "${{ secrets.DEPENDENCIES_TOKEN }}"
      GH_TOKEN: "${{ secrets.GH_WORKFLOWS_TOKEN }}"
@@ -16,33 +28,37 @@ jobs:
      fail-fast: false
      matrix:
        station: ['SRT', 'Medicina', 'Noto']
    runs-on: ubuntu-22.04
    steps:
      - name: Free up space
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: true
      - name: Install Vagrant
      - name: Install Vagrant and VirtualBox
        run: |
          wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
          echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
          sudo apt update && sudo apt install vagrant
      - name: Install VirtualBox
        run: |
          wget https://download.virtualbox.org/virtualbox/7.0.14/virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
          sudo apt install ./virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
      - name: Clone the repository
        uses: actions/checkout@v4
          sudo apt install virtualbox
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3'
          check-latest: true
      - name: Download the provisioned virtual machine from Google Drive
      - name: Clone the deployment repository
        uses: actions/checkout@v4
        with:
          repository: 'discos/deployment'
      - name: Install deployment package and dependencies
        run: |
          pip install -r .github/utils/gdrive_requirements.txt
          python .github/utils/download_from_gdrive.py
          gh secret set GOOGLE_DRIVE_TOKEN --org discos --visibility selected --repos discos,deployment < token.json
          python -m pip install -r requirements.txt
          pip install .
      - name: Retrieve the VM from cache
        uses: actions/cache/restore@v4
        with:
          key: discos-manager-vm
          path: |
            /home/runner/discos_manager.ova
            /home/runner/vagrant.tar.gz
      - name: Install the virtual machine
        run: |
          vboxmanage import discos_manager.ova --vsys 0 --options keepallmacs
@@ -54,17 +70,16 @@ jobs:
          sed -i "s/$(cat id)/$(vboxmanage list vms | grep 'discos_manager' | grep -oP '(?<=\{)[0-9a-fA-F-]+(?=\})')/" action_provision
          sed -i "s/$(cat id)/$(vboxmanage list vms | grep 'discos_manager' | grep -oP '(?<=\{)[0-9a-fA-F-]+(?=\})')/" id
        working-directory: /home/runner/.deployment/.vagrant/machines/manager/virtualbox/
      - name: Clone the deployment repository
        uses: actions/checkout@v4
        with:
          repository: 'discos/deployment'
      - name: Install deployment package and dependencies
      - name: Set the branch name
        run: |
          python -m pip install -r requirements.txt
          pip install .
          if [ "${{ github.event_name }}" == "push" ]; then
            echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
          elif [ "${{ github.event_name }}" == "pull_request" ]; then
            echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
          fi
      - name: Deploy DISCOS
        run: |
          discos-deploy manager:development --deploy-only -s ${{ matrix.station }} -b ${{ github.ref_name }}
          discos-deploy manager:development --deploy-only -s ${{ matrix.station }} -b ${{ env.BRANCH_NAME }}
      - name: Shutdown the virtual machine
        run: |
          discos-vms stop
+15 −2
Original line number Diff line number Diff line
@@ -354,10 +354,23 @@ public:
	 * @param start position inside the string from which to start the next token, if a new token has been found
	 *                it points to the character immediately after the localized token
	 * @param delimiter this is the character that separates the token
	 * @param it returns the next token in the string
	 * @param ret it returns the next token in the string
	 * @param stopAtFirst immediately returns (true) if the first character found is one of the delimiters, otherwise it goes further inside str
	 * @return true if a token has been found
	 */
	static bool getNextToken(const IRA::CString& str,int &start,char delimiter,IRA::CString &ret);
	static bool getNextToken(const IRA::CString& str,int &start,const char& delimiter,IRA::CString &ret, const bool& stopAtFirst=true);

	/**
	 * Use this function to divide a string into  separated tokens. Multiple token delimiters can be specified.
	 * @param str string to be divided into tokens
	 * @param start position inside the string from which to start the next token, if a new token has been found
	 *                it points to the character immediately after the localized token
	 * @param delimiters vector that contains characters that separate the token
	 * @param ret it returns the next token in the string
	 * @param stopAtFirst immediately returns (true) if the first character found is one of the delimiters, otherwise it goes further inside str
	 * @return true if a token has been found
	 */
	static bool getNextToken(const IRA::CString& str,int &start,const std::vector<char>& delimiters,IRA::CString &ret, const bool& stopAtFirst=true);
	
	/**
	 * Computes the normalized (+/-PI) difference between two angles expressed in radians(a-b). For example 359°-1°=-2°,1°-359°=2°, 179°-360°=179° and so on.
+82 −75
Original line number Diff line number Diff line
@@ -397,7 +397,12 @@ bool CIRATools::skyFrequency(const double& bf,const double& bbw,const double& rf
	}*/
}

bool CIRATools::getNextToken(const IRA::CString& str,int &start,char delimiter,IRA::CString &ret)
bool CIRATools::getNextToken(const IRA::CString& str,int &start,const char& delimiter,IRA::CString &ret, const bool& stopAtFirst)
{
		return getNextToken(str, start, std::vector<char>{ delimiter }, ret, stopAtFirst);
}

bool CIRATools::getNextToken(const IRA::CString& str,int &start,const std::vector<char>& delimiters,IRA::CString &ret, const bool& stopAtFirst)
{
		int i;
		bool ok=false;
@@ -406,22 +411,24 @@ bool CIRATools::getNextToken(const IRA::CString& str,int &start,char delimiter,I
		token=new char[i+1];
		i=0;
		while (str[start]!=0) {
			char c = str[start];
			ok=true;
			if ((str[start]==delimiter)) {
			start++;
			if (std::any_of(delimiters.begin(), delimiters.end(), [c](char d){ return c == d; })) {
				// We still have not found any meaningful character, stop if stopAtFirst or continue skipping a delimiter
				if(!stopAtFirst && i==0)
					continue;
				break;
			}
			else {
				token[i]=str[start];
				start++;
				token[i]=c;
				i++;
			}
		}
		token[i]=0;
		ret=IRA::CString(token);
		delete []token;
		if (!ok) return false;
		else return true;
		return ok;
}

double CIRATools::differenceBetweenAnglesRad(const double& a,const double& b)
Loading