Trigger Azure Pipeline for Alloy Samples #9
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: Deploy Alloy Samples | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
sample: | |
description: 'Specific sample to deploy (leave empty to deploy all)' | |
required: false | |
type: choice | |
options: | |
- ajo-content-cards | |
- ajo-in-app-messages | |
- ajo-personalization-client-side | |
- ajo-personalization-hybrid | |
- ajo-personalization-server-side | |
- ajo-proposition-interaction-tracking | |
- target-personalization-client-side | |
- target-personalization-hybrid | |
- target-personalization-hybrid-spa | |
- target-personalization-server-side | |
- target-top-and-bottom | |
- media-collection | |
env: | |
ACR_NAME: alloysamples.azurecr.io | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
ajo_matrix: ${{ steps.set-matrix.outputs.ajo_matrix }} | |
target_matrix: ${{ steps.set-matrix.outputs.target_matrix }} | |
media_matrix: ${{ steps.set-matrix.outputs.media_matrix }} | |
steps: | |
- id: set-matrix | |
run: | | |
if [ "${{ github.event.inputs.sample }}" != "" ]; then | |
if [[ "${{ github.event.inputs.sample }}" == ajo-* ]]; then | |
echo "ajo_matrix={\"include\":[{\"sample\":\"${{ github.event.inputs.sample }}\"}]}" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.event.inputs.sample }}" == target-* ]]; then | |
echo "target_matrix={\"include\":[{\"sample\":\"${{ github.event.inputs.sample }}\"}]}" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.event.inputs.sample }}" == media-* ]]; then | |
echo "media_matrix={\"include\":[{\"sample\":\"${{ github.event.inputs.sample }}\"}]}" >> $GITHUB_OUTPUT | |
fi | |
else | |
echo "ajo_matrix={\"include\":[{\"sample\":\"ajo-content-cards\"},{\"sample\":\"ajo-in-app-messages\"},{\"sample\":\"ajo-personalization-client-side\"},{\"sample\":\"ajo-personalization-hybrid\"},{\"sample\":\"ajo-personalization-server-side\"},{\"sample\":\"ajo-proposition-interaction-tracking\"}]}" >> $GITHUB_OUTPUT | |
echo "target_matrix={\"include\":[{\"sample\":\"target-personalization-client-side\"},{\"sample\":\"target-personalization-hybrid\"},{\"sample\":\"target-personalization-hybrid-spa\"},{\"sample\":\"target-personalization-server-side\"},{\"sample\":\"target-top-and-bottom\"}]}" >> $GITHUB_OUTPUT | |
echo "media_matrix={\"include\":[{\"sample\":\"media-collection\"}]}" >> $GITHUB_OUTPUT | |
fi | |
deploy-ajo: | |
needs: setup | |
if: ${{ fromJson(needs.setup.outputs.ajo_matrix).include[0] }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.setup.outputs.ajo_matrix)}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Docker Login to ACR | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ env.ACR_NAME }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- name: Set environment variables | |
run: | | |
echo "BASE_PATH=/$(echo ${{ matrix.sample }} | cut -d'-' -f2-)" >> $GITHUB_ENV | |
echo "APP_DOMAIN=ajo.alloyio.com" >> $GITHUB_ENV | |
echo "COMPOSE_FILE=docker/ajo.yml" >> $GITHUB_ENV | |
echo "SERVICE_NAME=$(echo ${{ matrix.sample }} | sed 's/^ajo-//')" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
run: | | |
docker compose -f ${{ env.COMPOSE_FILE }} build ${{ env.SERVICE_NAME }} | |
docker compose -f ${{ env.COMPOSE_FILE }} push ${{ env.SERVICE_NAME }} | |
- name: Deploy to Azure Web App | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ matrix.sample }} | |
publish-profile: ${{ secrets[format('{0}_PUBLISH_PROFILE', matrix.sample)] }} | |
images: ${{ env.ACR_NAME }}/${{ matrix.sample }}:latest | |
deploy-target: | |
needs: setup | |
if: ${{ fromJson(needs.setup.outputs.target_matrix).include[0] }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.setup.outputs.target_matrix)}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Docker Login to ACR | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ env.ACR_NAME }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- name: Set environment variables | |
run: | | |
echo "BASE_PATH=/$(echo ${{ matrix.sample }} | cut -d'-' -f2-)" >> $GITHUB_ENV | |
echo "APP_DOMAIN=target.alloyio.com" >> $GITHUB_ENV | |
echo "COMPOSE_FILE=docker/target.yml" >> $GITHUB_ENV | |
echo "SERVICE_NAME=$(echo ${{ matrix.sample }} | sed 's/^target-//')" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
run: | | |
docker compose -f ${{ env.COMPOSE_FILE }} build ${{ env.SERVICE_NAME }} | |
docker compose -f ${{ env.COMPOSE_FILE }} push ${{ env.SERVICE_NAME }} | |
- name: Deploy to Azure Web App | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ matrix.sample }} | |
publish-profile: ${{ secrets[format('{0}_PUBLISH_PROFILE', matrix.sample)] }} | |
images: ${{ env.ACR_NAME }}/${{ matrix.sample }}:latest | |
deploy-media: | |
needs: setup | |
if: ${{ fromJson(needs.setup.outputs.media_matrix).include[0] }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.setup.outputs.media_matrix)}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Docker Login to ACR | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ env.ACR_NAME }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- name: Set environment variables | |
run: | | |
echo "BASE_PATH=/$(echo ${{ matrix.sample }} | cut -d'-' -f2-)" >> $GITHUB_ENV | |
echo "APP_DOMAIN=media.alloyio.com" >> $GITHUB_ENV | |
echo "COMPOSE_FILE=docker/media.yml" >> $GITHUB_ENV | |
echo "SERVICE_NAME=$(echo ${{ matrix.sample }} | sed 's/^media-//')" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
run: | | |
docker compose -f ${{ env.COMPOSE_FILE }} build ${{ env.SERVICE_NAME }} | |
docker compose -f ${{ env.COMPOSE_FILE }} push ${{ env.SERVICE_NAME }} | |
- name: Deploy to Azure Web App | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ matrix.sample }} | |
publish-profile: ${{ secrets[format('{0}_PUBLISH_PROFILE', matrix.sample)] }} | |
images: ${{ env.ACR_NAME }}/${{ matrix.sample }}:latest |