Skip to content

Fix docker build yaml #103

Fix docker build yaml

Fix docker build yaml #103

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: 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 Publish\Config.json | ConvertFrom-Json
$trimmedIps = "${{ secrets.COMMA_SEPARATED_IPS }}" -split ',' | ForEach-Object { $_.Trim() }
$newAddressesArray = $jsonContent.IpWhitelistOptions.Addresses + $trimmedIps
$jsonContent.IpWhitelistOptions.Addresses = $newAddressesArray
$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 .
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"