Skip to content

Update deployment workflow for Linux support#701

Merged
StuartFerguson merged 3 commits intomasterfrom
task/#700_linux_release_workflow
Jul 3, 2025
Merged

Update deployment workflow for Linux support#701
StuartFerguson merged 3 commits intomasterfrom
task/#700_linux_release_workflow

Conversation

@StuartFerguson
Copy link
Member

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.

closes #700

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.
Comment on lines +137 to +195
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

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

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.

Suggested changeset 1
.github/workflows/createrelease.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml
--- a/.github/workflows/createrelease.yml
+++ b/.github/workflows/createrelease.yml
@@ -6,2 +6,6 @@
 
+permissions:
+  contents: read
+  packages: write
+
 jobs:
EOF
@@ -6,2 +6,6 @@

permissions:
contents: read
packages: write

jobs:
Copilot is powered by AI and may make mistakes. Always verify output.
@StuartFerguson StuartFerguson merged commit b6985f2 into master Jul 3, 2025
14 of 16 checks passed
@github-actions github-actions bot deleted the task/#700_linux_release_workflow branch September 2, 2025 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Linux Install workflow

1 participant