Update cicd.yml #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Docker Login | |
run: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
- 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 | |
run: docker-compose -f docker-compose.yml build | |
- name: Tag Docker Image with Elevated Privileges | |
shell: powershell | |
run: | | |
Start-Process -FilePath "docker" -ArgumentList "tag your-image-name:latest your-docker-username/your-image-name:latest" -Verb RunAs | |
- name: Push Docker Images | |
run: docker-compose -f docker-compose.yml push | |
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: docker-compose -f docker-compose.yml pull | |
- name: Delete Old Container | |
run: docker rm -f baphomet-server-container | |
- name: Run Docker Container | |
run: docker-compose -f docker-compose.yml up -d |