Skip to content

add credentials for private image #19

add credentials for private image

add credentials for private image #19

name: Build and Deploy to dev service app
on:
workflow_dispatch:
push:
# branches: [master]
branches: [elr/gh-action-dev-deploy]
env:
AZURE_WEBAPP_NAME: clearlydefined-api-dev
DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}-dev
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log into ghcr registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }} # GitHub username of person launching the action
password: ${{ secrets.GITHUB_TOKEN }} # 24-hour token starting from the time the job is run
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: DevDockerfile
tags: |
${{ env.DOCKER_IMAGE_NAME }}:latest
${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }}
labels: |
env=dev
type=api
- name: Install Azure CLI
uses: azure/CLI@v1
- name: Set Web App ACR authentication
uses: Azure/appservice-settings@v1
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
app-settings-json: |
[
{
"name": "DOCKER_REGISTRY_SERVER_URL",
"value": "https://ghcr.io",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_USERNAME",
"value": "${{ secrets.REGISTRY_USERNAME }}",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_PASSWORD",
"value": "${{ secrets.REGISTRY_PASSWORD }}",
"slotSetting": false
}
]
- name: 'Deploy to Azure WebApp'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: ${{ env.DOCKER_IMAGE_NAME }}:latest