Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output container app url #67

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 6 additions & 175 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,191 +1,22 @@
name: Deploy
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
# Trigger the workflow on push to the main branch
push:
branches:
- main
# Publish semver tags as releases.
tags: ["v*.*.*"]
# pull_request:
# branches:
# - main
workflow_dispatch:

# env:
# RESOURCE_GROUP: rg-poorclaresarundel
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}
# BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
build-and-deploy:
uses: ./.github/workflows/shared-build-and-deploy.yaml
with:
deploy: true
secrets: inherit
# build:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# services: [{ "imageName": "node-service" }]
# permissions:
# contents: read
# packages: write
# outputs:
# image-node: ${{ steps.image-tag.outputs.image-node-service }}
# sha-short: ${{ steps.sha_short.outputs.sha_short }}
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4

# - name: Set SHA_SHORT environment variable
# id: sha_short
# run: echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

# - name: Check SHA_SHORT environment variable
# run: echo ${{ steps.sha_short.outputs.sha_short }}

# # - name: Dump GitHub context
# # env:
# # GITHUB_CONTEXT: ${{ toJSON(github) }}
# # run: echo "$GITHUB_CONTEXT"
# # - name: Dump job context
# # env:
# # JOB_CONTEXT: ${{ toJSON(job) }}
# # run: echo "$JOB_CONTEXT"
# # - name: Dump steps context
# # env:
# # STEPS_CONTEXT: ${{ toJSON(steps) }}
# # run: echo "$STEPS_CONTEXT"
# # - name: Dump runner context
# # env:
# # RUNNER_CONTEXT: ${{ toJSON(runner) }}
# # run: echo "$RUNNER_CONTEXT"
# # - name: Dump strategy context
# # env:
# # STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
# # run: echo "$STRATEGY_CONTEXT"
# # - name: Dump matrix context
# # env:
# # MATRIX_CONTEXT: ${{ toJSON(matrix) }}
# # run: echo "$MATRIX_CONTEXT"

# # Login against a Docker registry except on PR
# # https://github.com/docker/login-action
# - name: Log into registry ${{ env.REGISTRY }}
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# # Extract metadata (tags, labels) for Docker
# # https://github.com/docker/metadata-action
# - name: Extract Docker metadata
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.services.imageName }}
# tags: |
# type=semver,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
# type=semver,pattern={{major}}
# type=ref,event=branch
# type=sha

# # Build and push Docker image with Buildx (don't push on PR)
# # https://github.com/docker/build-push-action
# - name: Build and push Docker image
# uses: docker/build-push-action@v6
# with:
# context: ./
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}

# - name: Output image tag
# id: image-tag
# run: |
# name=$(echo "image-${{ matrix.services.imageName }}" | tr '[:upper:]' '[:lower:]')
# value=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.services.imageName }}:sha-${{ steps.sha_short.outputs.sha_short }}" | tr '[:upper:]' '[:lower:]')
# echo "setting output: $name=$value"
# echo "$name=$value" >> $GITHUB_OUTPUT

# deploy:
# runs-on: ubuntu-latest
# if: github.event_name != 'pull_request'
# needs: [build]
# permissions:
# id-token: write
# contents: read
# packages: write
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4

# - name: "AZ CLI login"
# uses: azure/login@v2
# with:
# client-id: ${{ secrets.AZURE_CLIENT_ID }}
# tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

# - name: Deploy bicep
# uses: azure/CLI@v2
# with:
# # azcliversion: 2.63.0 # pinning because https://github.com/Azure/cli/issues/165
# inlineScript: |
# REF_SHA="${{ env.BRANCH_NAME }}.${{ needs.build.outputs.sha-short }}"
# DEPLOYMENT_NAME="${REF_SHA////-}"
# echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME"

# TAGS='{"owner":"johnnyreilly", "email":"johnny_reilly@hotmail.com"}'
# az deployment group create \
# --resource-group ${{ env.RESOURCE_GROUP }} \
# --name "$DEPLOYMENT_NAME" \
# --template-file ./infra/main.bicep \
# --parameters \
# webServiceImage='${{ needs.build.outputs.image-node }}' \
# containerRegistry=${{ env.REGISTRY }} \
# containerRegistryUsername=${{ github.actor }} \
# containerRegistryPassword=${{ secrets.PACKAGES_TOKEN }} \
# workspaceName='shared-log-analytics' \
# appInsightsName='shared-app-insights' \
# managedEnvironmentName='shared-env' \
# webServiceContainerAppName='${{ env.BRANCH_NAME }}-web' \
# tags="$TAGS" \
# APPSETTINGS_API_KEY="${{ secrets.APPSETTINGS_API_KEY }}" \
# APPSETTINGS_DOMAIN="${{ vars.APPSETTINGS_DOMAIN }}" \
# APPSETTINGS_PRAYER_REQUEST_FROM_EMAIL="${{ vars.APPSETTINGS_PRAYER_REQUEST_FROM_EMAIL }}" \
# APPSETTINGS_PRAYER_REQUEST_RECIPIENT_EMAIL="${{ vars.APPSETTINGS_PRAYER_REQUEST_RECIPIENT_EMAIL }}"

# CONTAINER_APP_URL=$(az containerapp show \
# --resource-group '${{ env.RESOURCE_GROUP }}' \
# --name '${{ env.BRANCH_NAME }}-web' \
# --query properties.configuration.ingress.fqdn \
# --output tsv)

# echo "CONTAINER_APP_URL=$CONTAINER_APP_URL"

# # echo "az deployment group show --resource-group '${{ env.RESOURCE_GROUP }}' --name $DEPLOYMENT_NAME"
# # DEPLOYMENT_OUTPUTS=$(az deployment group show \
# # --resource-group ${{ env.RESOURCE_GROUP }} \
# # --name $DEPLOYMENT_NAME \
# # --query properties.outputs)

# # echo 'convert outputs to variables'
# # echo $DEPLOYMENT_OUTPUTS | jq -c '. | to_entries[] | [.key, .value.value]' |
# # while IFS=$"\n" read -r c; do
# # OUTPUT_NAME=$(echo "$c" | jq -r '.[0]')
# # OUTPUT_VALUE=$(echo "$c" | jq -r '.[1]')
# # echo "setting variable $OUTPUT_NAME=$OUTPUT_VALUE"
# # echo "{$OUTPUT_NAME}={$OUTPUT_VALUE}" >> $GITHUB_OUTPUT
# # # echo "::set-output name=$OUTPUT_NAME::$OUTPUT_VALUE"
# # done # --query properties.outputs.nodeUrl

# # az containerapp show \
# # --resource-group 'rg-poorclaresarundel' \
# # --name 'main-web' \
# # --query properties.configuration.ingress.fqdn
get-container-app-url:
runs-on: ubuntu-latest
needs: build-and-deploy
steps:
- run: echo "container-app-url=${{ needs.build-and-deploy.outputs.container-app-url }}"
32 changes: 11 additions & 21 deletions .github/workflows/shared-build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
# secrets:
# personal_access_token:
# required: true
# Map the workflow outputs to job outputs
outputs:
container-app-url:
description: "The URL of the deployed container app"
value: ${{ jobs.deploy.outputs.container-app-url }}

env:
RESOURCE_GROUP: rg-poorclaresarundel
Expand Down Expand Up @@ -41,7 +46,6 @@ jobs:
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
# if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
Expand Down Expand Up @@ -69,7 +73,6 @@ jobs:
uses: docker/build-push-action@v6
with:
context: ./
# push: ${{ github.event_name != 'pull_request' }}
push: ${{ inputs.deploy }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -78,6 +81,8 @@ jobs:
runs-on: ubuntu-latest
if: inputs.deploy == true
needs: [build]
outputs:
container-app-url: ${{ steps.deploy.outputs.CONTAINER_APP_URL }}
permissions:
id-token: write
contents: read
Expand All @@ -86,17 +91,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: "AZ CLI login"
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Deploy bicep
- name: Deploy to Azure
id: deploy
uses: azure/CLI@v2
with:
# azcliversion: 2.63.0 # pinning because https://github.com/Azure/cli/issues/165
inlineScript: |
REF_SHA="${{ env.BRANCH_NAME }}.${{ needs.build.outputs.sha-short }}"
DEPLOYMENT_NAME="${REF_SHA////-}"
Expand Down Expand Up @@ -132,19 +137,4 @@ jobs:
--output tsv)

echo "CONTAINER_APP_URL=$CONTAINER_APP_URL"

# echo "az deployment group show --resource-group '${{ env.RESOURCE_GROUP }}' --name $DEPLOYMENT_NAME"
# DEPLOYMENT_OUTPUTS=$(az deployment group show \
# --resource-group ${{ env.RESOURCE_GROUP }} \
# --name $DEPLOYMENT_NAME \
# --query properties.outputs)

# echo 'convert outputs to variables'
# echo $DEPLOYMENT_OUTPUTS | jq -c '. | to_entries[] | [.key, .value.value]' |
# while IFS=$"\n" read -r c; do
# OUTPUT_NAME=$(echo "$c" | jq -r '.[0]')
# OUTPUT_VALUE=$(echo "$c" | jq -r '.[1]')
# echo "setting variable $OUTPUT_NAME=$OUTPUT_VALUE"
# echo "{$OUTPUT_NAME}={$OUTPUT_VALUE}" >> $GITHUB_OUTPUT
# # echo "::set-output name=$OUTPUT_NAME::$OUTPUT_VALUE"
# done # --query properties.outputs.nodeUrl
echo "CONTAINER_APP_URL=$CONTAINER_APP_URL" >> $GITHUB_OUTPUT
Loading