Update deployment workflow for Linux support#701
Conversation
Refactor the staging and production deployment processes to utilize Linux commands and file structures. Replace Windows service management with `systemctl` commands and implement a systemd service file for installation. Adjust artifact handling paths for compatibility with Linux environments.
| runs-on: [productionserver, linux] | ||
| needs: [buildlinux, deploystaging] | ||
| environment: production | ||
| name: "Deploy to Production" | ||
|
|
||
| steps: | ||
| - name: Download the artifact | ||
| uses: actions/download-artifact@v4.1.8 | ||
| with: | ||
| name: securityservice | ||
|
|
||
| - name: Remove existing Windows service | ||
| run: | | ||
| $serviceName = "Transaction Processing - Security Service" | ||
| # Check if the service exists | ||
| if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) { | ||
| Stop-Service -Name $serviceName | ||
| sc.exe delete $serviceName | ||
| } | ||
|
|
||
| - name: Unzip the files | ||
| run: | | ||
| Expand-Archive -Path securityservice.zip -DestinationPath "C:\txnproc\transactionprocessing\securityservice" -Force | ||
|
|
||
| - name: Install as a Windows service | ||
| run: | | ||
| $serviceName = "Transaction Processing - Security Service" | ||
| $servicePath = "C:\txnproc\transactionprocessing\securityservice\SecurityService.exe" | ||
|
|
||
| New-Service -Name $serviceName -BinaryPathName $servicePath -Description "Transaction Processing - Security Service" -DisplayName "Transaction Processing - Security Service" -StartupType Automatic | ||
| Start-Service -Name $serviceName | ||
| - name: Download the artifact | ||
| uses: actions/download-artifact@v4.1.8 | ||
| with: | ||
| name: securityservice | ||
| path: /tmp/securityservice # Download to a temporary directory | ||
|
|
||
| - name: Remove existing service (if applicable) | ||
| run: | | ||
| SERVICE_NAME="securityservice" # Or whatever your service will be called | ||
| if systemctl is-active --quiet "$SERVICE_NAME"; then | ||
| echo "Stopping existing service..." | ||
| sudo systemctl stop "$SERVICE_NAME" | ||
| fi | ||
| if systemctl is-enabled --quiet "$SERVICE_NAME"; then | ||
| echo "Disabling existing service..." | ||
| sudo systemctl disable "$SERVICE_NAME" | ||
| fi | ||
| if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then | ||
| echo "Removing existing service unit file..." | ||
| sudo rm "/etc/systemd/system/${SERVICE_NAME}.service" | ||
| sudo systemctl daemon-reload | ||
| fi | ||
|
|
||
| - name: Unzip the files | ||
| run: | | ||
| mkdir -p /opt/txnproc/transactionprocessing/securityservice | ||
| unzip -o /tmp/securityservice/securityservice.zip -d /opt/txnproc/transactionprocessing/securityservice | ||
|
|
||
| - name: Install and Start as a Linux service | ||
| run: | | ||
| SERVICE_NAME="securityservice" | ||
| EXEC_PATH="/opt/txnproc/transactionprocessing/securityservice/SecurityService" # Assuming your executable is named SecurityService | ||
| SERVICE_DESCRIPTION="Transaction Processing - Security Service" | ||
|
|
||
| # Create a systemd service file | ||
| echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "ExecStart=${EXEC_PATH}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "User=youruser" # Consider running as a less privileged user | ||
| echo "Group=yourgroup" # Consider running as a less privileged group | ||
| echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
| echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service | ||
|
|
||
| # Reload systemd, enable, and start the service | ||
| sudo systemctl daemon-reload | ||
| sudo systemctl enable "$SERVICE_NAME" | ||
| sudo systemctl start "$SERVICE_NAME" | ||
| sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 months ago
To fix the issue, we need to add a permissions block to the workflow file. This block should specify the least privileges required for the workflow to function correctly. Since the workflow involves deploying artifacts and pushing NuGet packages, we can set contents: read for accessing repository contents and packages: write for pushing packages. Other permissions can be omitted unless explicitly required.
The permissions block can be added at the root level of the workflow to apply to all jobs or within individual jobs to tailor permissions for specific tasks.
| @@ -6,2 +6,6 @@ | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| jobs: |
Refactor the staging and production deployment processes to utilize Linux commands and file structures. Replace Windows service management with
systemctlcommands and implement a systemd service file for installation. Adjust artifact handling paths for compatibility with Linux environments.closes #700