Skip to content

Workflow file for this run

name: Baphomet Server Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Set Environment Variables
shell: powershell
run: |
Write-Output "Setting environment variables..."
$envContent = @"
ATLAS_DB_PASSWORD=${{ secrets.ATLAS_DB_PASSWORD }}
ATLAS_DB_USERNAME=${{ secrets.ATLAS_DB_USERNAME }}
ATLAS_CLUSTER=${{ secrets.ATLAS_CLUSTER }}
ATLAS_DB=${{ secrets.ATLAS_DB }}
ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }}
REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }}
SSL_CERT=${{ secrets.SSL_CERT }}
SSL_PRIVATE_KEY=${{ secrets.SSL_PRIVATE_KEY }}
SSL_CERT_INTERMEDIATE=${{ secrets.SSL_CERT_INTERMEDIATE }}
"@
$envContent | Out-File -FilePath ".env"
Write-Output "Environment variables set."
- name: Verify Working Directory and `.env` File Creation
shell: powershell
run: |
Write-Output "Current directory: $(Get-Location)"
if (Test-Path ".env") {
Write-Output ".env file exists:"
Get-Content ".env"
} else {
Write-Output ".env file does not exist."
exit 1
}
- name: Install Docker Compose (if needed)
shell: powershell
run: |
if (-not (Get-Command docker-compose -ErrorAction SilentlyContinue)) {
$installPath = "${{ runner.temp }}/docker-compose.exe"
Invoke-WebRequest -Uri "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Windows-x86_64.exe" -OutFile $installPath
Start-Process -FilePath "powershell.exe" -ArgumentList "-Command
Move-Item -Path $installPath -Destination 'C:\Program Files\Docker\Docker\resources\bin\docker-compose.exe'" -Verb RunAs
Write-Output "Docker Compose Installed"
} else {
Write-Output "Docker Compose already installed"
}
- name: Docker Login with Elevated Permissions
shell: powershell
run: |
Start-Process -FilePath "powershell.exe" -ArgumentList "-Command echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin" -Verb RunAs
- name: Verify Docker Hub Login
shell: powershell
run: Start-Process -FilePath "powershell.exe" -ArgumentList "-Command ./verify-docker-login.ps1" -Verb RunAs
- name: Build Docker Images with Elevated Privileges
shell: powershell
run: Start-Process -FilePath "powershell.exe" -ArgumentList "-Command ./build-docker-image.ps1"
- name: Tag Docker Image with Elevated Privileges
shell: powershell
run: |
Start-Process -FilePath "docker" -ArgumentList "tag baphomet-server:latest collinlucke/baphomet-server:latest" -Verb RunAs
- name: Push Docker Images with Elevated Privileges
shell: powershell
run: |
$process = Start-Process -FilePath "powershell.exe" -ArgumentList "-Command ./docker-push.ps1" -Verb RunAs -Wait -PassThru
$process.WaitForExit()
if ($process.ExitCode -ne 0) {
Write-Output "Docker push failed with exit code $($process.ExitCode)"
exit $process.ExitCode
} else {
Write-Output "Docker push completed successfully."
}
# - name: Push Docker Images with Logging
# shell: powershell
# run: |
# Start-Process -FilePath "powershell.exe" -ArgumentList "-Command docker-compose -f docker-compose.yml push" -Verb RunAs -Wait -PassThru | ForEach-Object {
# $_.StandardOutput.ReadToEnd()
# $_.StandardError.ReadToEnd()
# }
# if ($LASTEXITCODE -ne 0) {
# Write-Output "Docker push failed with exit code $LASTEXITCODE"
# exit $LASTEXITCODE
# } else {
# Write-Output "Docker push completed successfully."
# }
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Install Docker Compose (if needed)
shell: powershell
run: |
if (-not (Get-Command docker-compose -ErrorAction SilentlyContinue)) {
$installPath = "${{ runner.temp }}/docker-compose.exe"
Invoke-WebRequest -Uri "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Windows-x86_64.exe" -OutFile $installPath
Start-Process -FilePath "powershell.exe" -ArgumentList "-Command
Move-Item -Path $installPath -Destination 'C:\Program Files\Docker\Docker\resources\bin\docker-compose.exe'" -Verb RunAs
Write-Output "Docker Compose Installed"
} else {
Write-Output "Docker Compose already installed"
}
- name: Pull Image from Docker Hub
run: Start-Process -FilePath "powershell.exe" -ArgumentList "-Command docker-compose -f docker-compose.yml pull" -Verb RunAs
- name: Delete Old Container
run: Start-Process -FilePath "powershell.exe" -ArgumentList "-Command docker-compose -f docker-compose.yml rm" -Verb RunAs
- name: Run Docker Container
run: Start-Process -FilePath "powershell.exe" -ArgumentList "-Command docker-compose -f docker-compose.yml up -d" -Verb RunAs