Fix release (#10) #18
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/**" | |
- ".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: Log in to Docker Hub | |
run: | | |
docker login guildwarspartysearch.azurecr.io --username "${{ secrets.DOCKERHUB_USERNAME }}" --password "${{ secrets.DOCKERHUB_PASSWORD }}" | |
- name: Replace Config Placeholders | |
shell: pwsh | |
run: | | |
cd GuildWarsPartySearch | |
$content = Get-Content Config.Release.json | |
$content = $content.Replace("[APIKEY]", "${{ secrets.APIKEY }}") | |
$content = $content.Replace("[AZURE_TABLESTORAGE_CONNECTIONSTRING]", "${{ secrets.AZURE_TABLESTORAGE_CONNECTIONSTRING }}") | |
Set-Content -Path Config.Release.json -Value $content | |
Write-Host "Placeholder replaced successfully in Config.Release.json" | |
- name: Build and push Docker image | |
run: | | |
cd GuildWarsPartySearch | |
.\BuildDockerImage.ps1 | |
docker push guildwarspartysearch.azurecr.io/guildwarspartysearch.server | |
shell: pwsh | |
- name: Debug | |
run: | | |
cd GuildWarsPartySearch/bin/Release/net8.0/publish/ | |
ls | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Login to Azure | |
shell: pwsh | |
run: | | |
az login --service-principal -u "${{ secrets.AZURE_CLIENTID }}" -p "${{ secrets.AZURE_SECRET }}" --tenant "${{ secrets.AZURE_TENANT }}" | |
- name: Check and Delete Existing Container Instance | |
shell: pwsh | |
run: | | |
# Check if the container instance exists | |
$exists = az container show --name guildwarspartysearch --resource-group ${{ secrets.AZURE_RESOURCEGROUPNAME }} --query "name" -o tsv | |
if ($exists -eq "guildwarspartysearch") { | |
Write-Host "Container instance exists. Deleting..." | |
# Delete the existing container instance | |
az container delete --name guildwarspartysearch --resource-group ${{ secrets.AZURE_RESOURCEGROUPNAME }} --yes | |
} else { | |
Write-Host "Container instance does not exist. Skipping delete step." | |
} | |
- name: Create New Container Instance | |
shell: pwsh | |
run: | | |
az container create ` | |
--resource-group ${{ secrets.AZURE_RESOURCEGROUPNAME }} ` | |
--name guildwarspartysearch ` | |
--image guildwarspartysearch.azurecr.io/guildwarspartysearch.server:latest ` | |
--cpu 1 --memory 1 ` | |
--registry-login-server guildwarspartysearch.azurecr.io ` | |
--registry-username ${{ secrets.DOCKERHUB_USERNAME }} ` | |
--registry-password ${{ secrets.DOCKERHUB_PASSWORD }} ` | |
--dns-name-label guildwarspartysearch ` | |
--ports 8080 |