Skip to content

get sha only once and store in configs #25

get sha only once and store in configs

get sha only once and store in configs #25

name: Build and Deploy to dev service app
on:
workflow_dispatch:
push:
branches: [elr/gh-action-dev-deploy]
# branches: [master]
env:
CODE_ENVIRONMENT: dev
APPLICATION_TYPE: api
AZURE_WEBAPP_NAME: clearlydefined-api-dev
DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}-dev
# SEMVER: '' # if you want to use semver, you will need to add a tag to the Docker build
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 }} # user that kicked off the action
password: ${{ secrets.GITHUB_TOKEN }} # token created when the action launched (short lived)
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: Dockerfile
tags: |
${{ env.DOCKER_IMAGE_NAME }}:latest
${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }}
labels: |
env=${{ env.CODE_ENVIRONMENT }}
type=${{ env.APPLICATION_TYPE }}
- name: Login for Azure cli commands
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set DOCKER configs in Azure web app
uses: Azure/appservice-settings@v1
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
app-settings-json: |
[
{
"name": "DOCKER_CUSTOM_IMAGE_NAME",
"value": "${{ env.DOCKER_IMAGE_NAME }}:latest }}",
"slotSetting": false
},
{
"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": "BUILD_SHA",
"value": "${{ github.sha }}",
"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