Strip Azure stuff #100
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: Build and Push Docker Image | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- "GuildWarsPartySearch.Common/**" | |
- "GuildWarsPartySearch/**" | |
- ".github/workflows/docker-deploy.yaml" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Install .NET Core | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.x' | |
- name: Install sshpass | |
run: sudo apt-get update && sudo apt-get install -y sshpass | |
# - name: Create Docker Environment File | |
# shell: pwsh | |
# run: | | |
# cd GuildWarsPartySearch | |
# $envFilePath = "envfile" | |
# $envContent = @( | |
# "ApplicationInsights__InstrumentationKey=${{ secrets.AZURE_INSIGHTS_INSTRUMENTATIONKEY }}", | |
# "AzureCredentialsOptions__ClientSecret=${{ secrets.AZURE_CLIENT_SECRET }}", | |
# "AzureCredentialsOptions__ClientId=${{ secrets.AZURE_CLIENT_ID }}", | |
# "AzureCredentialsOptions__TenantId=${{ secrets.AZURE_TENANT_ID }}" | |
# ) | |
# $envContent | Set-Content -Path $envFilePath | |
# Write-Host "Environment file created: $envFilePath" | |
- name: Build server | |
run: | | |
dotnet publish .\GuildWarsPartySearch\GuildWarsPartySearch.Server.csproj -c Release -r linux-x64 -o Publish\ | |
Copy-Item -Path .\GuildWarsPartySearch.FrontEnd\Content\ Publish\Content\ -Recurse | |
Copy-Item -Path .\GuildWarsPartySearch\Config.Release.json -Destination Publish\Config.json | |
shell: pwsh | |
- name: Replace secrets in configuration | |
shell: pwsh | |
run: | | |
$jsonContent = Get-Content -Raw -Path GuildWarsPartySearch\Publish\Config.json | ConvertFrom-Json | |
$jsonContent.AzureCredentialsOptions.ClientSecret = "${{ secrets.AZURE_CLIENT_SECRET }}" | |
$jsonContent.AzureCredentialsOptions.ClientId = "${{ secrets.AZURE_CLIENT_ID }}" | |
$jsonContent.AzureCredentialsOptions.TenantId = "${{ secrets.AZURE_TENANT_ID }}" | |
$updatedJsonContent = $jsonContent | ConvertTo-Json -Depth 32 | |
Set-Content -Path Publish\Config.json -Value $updatedJsonContent | |
- name: Build docker image | |
run: | | |
echo "Building docker image" | |
docker build -t guildwarspartysearch.server -f Dockerfile-Server . | |
cd .. | |
echo "Exporting docker image" | |
docker save -o guildwarspartysearch.server.tar guildwarspartysearch.server | |
echo "Exported docker image" | |
- name: Deploy Docker image to host | |
shell: pwsh | |
run: | | |
echo "Setting up staging folder" | |
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "mkdir -p /home/guildwarspartysearch/staging" | |
echo "Uploading image" | |
sshpass -p "${{ secrets.HOST_PASS }}" scp -o StrictHostKeyChecking=no guildwarspartysearch.server.tar ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }}:/home/guildwarspartysearch/staging | |
echo "Stopping and removing old containers" | |
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker rmi -f guildwarspartysearch.server:latest" | |
echo "Loading new image" | |
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker load -i /home/guildwarspartysearch/staging/guildwarspartysearch.server.tar" | |
echo "Running new image" | |
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker run -d --name partysearch -p 8080:80 guildwarspartysearch.server:latest" | |
echo "Cleaning up" | |
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "rm -f /home/guildwarspartysearch/staging/guildwarspartysearch.server.tar" |