Add deploy job #5
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: | |
pull_request: | |
branches: [ master ] | |
push: | |
branches: [ master ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Log in to Docker Hub | |
run: | | |
docker login guildwarspartysearch.azurecr.io --username "${{ secrets.DOCKERHUB_USERNAME }}" --password "${{ secrets.DOCKERHUB_PASSWORD }}" | |
- name: Build and push Docker image | |
run: | | |
cd GuildWarsPartySearch | |
.\BuildDockerImage.ps1 | |
docker push guildwarspartysearch.azurecr.io/guildwarspartysearch.server | |
shell: pwsh | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_SECRET }} | |
- 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-dns ` | |
--ports 8080 |