Skip to content

Setup configurations (#6) #13

Setup configurations (#6)

Setup configurations (#6) #13

name: Build and Push Docker Image
on:
push:
branches: [ master ]
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.json -Value $content
Write-Host "Placeholder replaced successfully in Config.json"
- name: Build and push Docker image
run: |
cd GuildWarsPartySearch
.\BuildDockerImage.ps1
docker push guildwarspartysearch.azurecr.io/guildwarspartysearch.server
shell: pwsh
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