Skip to content

Update cicd.yml

Update cicd.yml #89

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: |
echo "ATLAS_DB_PASSWORD=${{ secrets.ATLAS_DB_PASSWORD }}" >> ~/.env
echo "ATLAS_DB_USERNAME=${{ secrets.ATLAS_DB_USERNAME }}" >> ~/.env
echo "ATLAS_CLUSTER=${{ secrets.ATLAS_CLUSTER }}" >> ~/.env
echo "ATLAS_DB=${{ secrets.ATLAS_DB }}" >> ~/.env
echo "ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }}" >> ~/.env
echo "REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }}" >> ~/.env
echo "SSL_CERT=${{ secrets.SSL_CERT }}" >> ~/.env
echo "SSL_PRIVATE_KEY=${{ secrets.SSL_PRIVATE_KEY }}" >> ~/.env
echo "SSL_CERT_INTERMEDIATE=${{ secrets.SSL_CERT_INTERMEDIATE }}" >> ~/.env
- 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: Debug Docker Hub Login
shell: powershell
run: |
Start-Process -FilePath "docker" -ArgumentList "logout" -NoNewWindow
Write-Output "Logging into Docker Hub..."
Start-Process -FilePath "docker" -ArgumentList "login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}" -NoNewWindow
Write-Output "Docker login completed."
# - name: Login to Docker Hub
# shell: powershell
# run: Start-Process -FilePath "docker" -ArgumentList "login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}" -Verb RunAs
- name: Docker Login
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
# - name: Verify Docker Hub Login
# shell: powershell
# run: |
# if (-not (docker info | Select-String 'Username: ${{ secrets.DOCKER_USERNAME }}')) {
# Write-Output "Docker login verification failed."
# exit 1
# } else {
# Write-Output "Docker login verified."
# }
- name: Build Docker Images
shell: powershell
run: Start-Process -FilePath "docker-compose" -ArgumentList "-f docker-compose.yml build --no-cache" -Verb RunAs
- name: Tag Docker Image
shell: powershell
run: docker tag baphomet-server:latest collinlucke/baphomet-server:latest
- name: Push Docker Images with Logging
shell: powershell
run: |
$process = Start-Process -FilePath "docker-compose" -ArgumentList "-f docker-compose.yml push" -NoNewWindow -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."
}
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
shell: powershell
run: Start-Process -FilePath "docker-compose" -ArgumentList "-f docker-compose.yml pull" -Verb RunAs
- name: Delete Old Container
shell: powershell
run: Start-Process -FilePath "docker" -ArgumentList "rm -f baphomet-server-container" -Verb RunAs
- name: Run Docker Container
shell: powershell
run: Start-Process -FilePath "docker-compose" -ArgumentList "-f docker-compose.yml up -d" -Verb RunAs