Commit 041b5cd7 authored by Giuseppe Carboni's avatar Giuseppe Carboni
Browse files

Merge branch 'master' of https://github.com/discos/discos into fix-issue-885

parents 279b8f82 28d9cbdc
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
+43 −0
Original line number Diff line number Diff line
name: Download the DISCOS VM

on:
  workflow_dispatch:
  repository_dispatch:
    types: [update-vm]

concurrency:
  group: download
  cancel-in-progress: false

jobs:
  download-vm:
    name: Download the latest virtual machine
    runs-on: ubuntu-latest
    env:
      REPOSITORY_TOKEN: "${{ secrets.DEPENDENCIES_TOKEN }}"
      GH_TOKEN: "${{ secrets.GH_WORKFLOWS_TOKEN }}"
      GOOGLE_DRIVE_TOKEN: "${{ secrets.GOOGLE_DRIVE_TOKEN }}"
      PROVISIONED_VM_GDRIVE_ID: "${{ secrets.PROVISIONED_VM_GDRIVE_ID }}"
      PROVISIONED_ARCHIVE_GDRIVE_ID: "${{ secrets.PROVISIONED_ARCHIVE_GDRIVE_ID }}"
    steps:
      - name: Clone the deployment repository
        uses: actions/checkout@v4
        with:
          repository: 'discos/deployment'
      - 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
        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
      - name: Save the downloaded VM to cache
        uses: actions/cache/save@v4
        with:
          key: discos-manager-vm
          path: |
            /home/runner/discos_manager.ova
            /home/runner/vagrant.tar.gz
+9 −0
Original line number Diff line number Diff line
@@ -6,11 +6,13 @@ object/
*~
*.swp
*.pyc
.project*

# Ignore the SliLibrary directory
Common/Libraries/SlaLibrary

# Files generated by the building process
Common/Interfaces/build.log
Common/Clients/CaltoolClient/src/calibrationtool_ui.py
Common/Clients/CaltoolClient/src/calibrationtool_ui.pye
Common/Errors/AntennaErrors/idl/AntennaErrors.idl
@@ -26,12 +28,16 @@ Common/Errors/ParserErrors/idl/ParserErrors.idl
Common/Errors/ReceiversErrors/idl/DerotatorErrors.idl
Common/Errors/ReceiversErrors/idl/ReceiversErrors.idl
Common/Errors/XBackendErrors/idl/XBackendsErrors.idl
Common/Errors/ActiveSurfaceErrors/idl/ASErrors.idl
Common/Interfaces/ActiveSurfaceInterface/idl/ActiveSurfaceCommon.idl
Common/Interfaces/AntennaInterface/idl/SolarSystemBody.idl
Common/Interfaces/AntennaInterface/idl/AntennaBoss.idl
Common/Interfaces/AntennaInterface/idl/Moon.idl
Common/Interfaces/AntennaInterface/idl/Mount.idl
Common/Interfaces/AntennaInterface/idl/OTF.idl
Common/Interfaces/AntennaInterface/idl/Observatory.idl
Common/Interfaces/AntennaInterface/idl/SkySource.idl
Common/Interfaces/AntennaInterface/idl/SolarSystemBody.idl
Common/Interfaces/ActiveSurfaceInterface/idl/ActiveSurfaceCommon.idl
Common/Interfaces/CommonInterface/idl/AntennaDefinitions.idl
Common/Interfaces/CommonInterface/idl/BackendsDefinitions.idl
@@ -50,4 +56,7 @@ SRT/Clients/SRTActiveSurfaceGUIClient/include/SRTActiveSurfaceGUI.h
SRT/Clients/SRTActiveSurfaceGUIClient/src/moc_SRTActiveSurfaceCore.cpp
SRT/Clients/SRTActiveSurfaceGUIClient/src/moc_SRTActiveSurfaceGUIui.cpp
SRT/Interfaces/SRTActiveSurfaceInterface/idl/SRTActiveSurfaceBoss.idl
Common/Libraries/build.log
SRT/Interfaces/SRTActiveSurfaceInterface/idl/SRTActiveSurfaceCommon.idl
.DS_Store
.vscode/settings.json
Loading