Skip to content

Commit d3bd139

Browse files
authored
feat: output container app url (#67)
1 parent 3347d17 commit d3bd139

File tree

2 files changed

+17
-196
lines changed

2 files changed

+17
-196
lines changed

.github/workflows/deploy.yaml

+6-175
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,22 @@
11
name: Deploy
22
on:
3-
# Trigger the workflow on push or pull request,
4-
# but only for the main branch
3+
# Trigger the workflow on push to the main branch
54
push:
65
branches:
76
- main
87
# Publish semver tags as releases.
98
tags: ["v*.*.*"]
10-
# pull_request:
11-
# branches:
12-
# - main
139
workflow_dispatch:
1410

15-
# env:
16-
# RESOURCE_GROUP: rg-poorclaresarundel
17-
# REGISTRY: ghcr.io
18-
# IMAGE_NAME: ${{ github.repository }}
19-
# BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
20-
2111
jobs:
2212
build-and-deploy:
2313
uses: ./.github/workflows/shared-build-and-deploy.yaml
2414
with:
2515
deploy: true
2616
secrets: inherit
27-
# build:
28-
# runs-on: ubuntu-latest
29-
# strategy:
30-
# matrix:
31-
# services: [{ "imageName": "node-service" }]
32-
# permissions:
33-
# contents: read
34-
# packages: write
35-
# outputs:
36-
# image-node: ${{ steps.image-tag.outputs.image-node-service }}
37-
# sha-short: ${{ steps.sha_short.outputs.sha_short }}
38-
# steps:
39-
# - name: Checkout repository
40-
# uses: actions/checkout@v4
41-
42-
# - name: Set SHA_SHORT environment variable
43-
# id: sha_short
44-
# run: echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
45-
46-
# - name: Check SHA_SHORT environment variable
47-
# run: echo ${{ steps.sha_short.outputs.sha_short }}
48-
49-
# # - name: Dump GitHub context
50-
# # env:
51-
# # GITHUB_CONTEXT: ${{ toJSON(github) }}
52-
# # run: echo "$GITHUB_CONTEXT"
53-
# # - name: Dump job context
54-
# # env:
55-
# # JOB_CONTEXT: ${{ toJSON(job) }}
56-
# # run: echo "$JOB_CONTEXT"
57-
# # - name: Dump steps context
58-
# # env:
59-
# # STEPS_CONTEXT: ${{ toJSON(steps) }}
60-
# # run: echo "$STEPS_CONTEXT"
61-
# # - name: Dump runner context
62-
# # env:
63-
# # RUNNER_CONTEXT: ${{ toJSON(runner) }}
64-
# # run: echo "$RUNNER_CONTEXT"
65-
# # - name: Dump strategy context
66-
# # env:
67-
# # STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
68-
# # run: echo "$STRATEGY_CONTEXT"
69-
# # - name: Dump matrix context
70-
# # env:
71-
# # MATRIX_CONTEXT: ${{ toJSON(matrix) }}
72-
# # run: echo "$MATRIX_CONTEXT"
73-
74-
# # Login against a Docker registry except on PR
75-
# # https://github.com/docker/login-action
76-
# - name: Log into registry ${{ env.REGISTRY }}
77-
# if: github.event_name != 'pull_request'
78-
# uses: docker/login-action@v3
79-
# with:
80-
# registry: ${{ env.REGISTRY }}
81-
# username: ${{ github.actor }}
82-
# password: ${{ secrets.GITHUB_TOKEN }}
83-
84-
# # Extract metadata (tags, labels) for Docker
85-
# # https://github.com/docker/metadata-action
86-
# - name: Extract Docker metadata
87-
# id: meta
88-
# uses: docker/metadata-action@v5
89-
# with:
90-
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.services.imageName }}
91-
# tags: |
92-
# type=semver,pattern={{version}}
93-
# type=semver,pattern={{major}}.{{minor}}
94-
# type=semver,pattern={{major}}
95-
# type=ref,event=branch
96-
# type=sha
97-
98-
# # Build and push Docker image with Buildx (don't push on PR)
99-
# # https://github.com/docker/build-push-action
100-
# - name: Build and push Docker image
101-
# uses: docker/build-push-action@v6
102-
# with:
103-
# context: ./
104-
# push: ${{ github.event_name != 'pull_request' }}
105-
# tags: ${{ steps.meta.outputs.tags }}
106-
# labels: ${{ steps.meta.outputs.labels }}
107-
108-
# - name: Output image tag
109-
# id: image-tag
110-
# run: |
111-
# name=$(echo "image-${{ matrix.services.imageName }}" | tr '[:upper:]' '[:lower:]')
112-
# value=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.services.imageName }}:sha-${{ steps.sha_short.outputs.sha_short }}" | tr '[:upper:]' '[:lower:]')
113-
# echo "setting output: $name=$value"
114-
# echo "$name=$value" >> $GITHUB_OUTPUT
115-
116-
# deploy:
117-
# runs-on: ubuntu-latest
118-
# if: github.event_name != 'pull_request'
119-
# needs: [build]
120-
# permissions:
121-
# id-token: write
122-
# contents: read
123-
# packages: write
124-
# steps:
125-
# - name: Checkout repository
126-
# uses: actions/checkout@v4
127-
128-
# - name: "AZ CLI login"
129-
# uses: azure/login@v2
130-
# with:
131-
# client-id: ${{ secrets.AZURE_CLIENT_ID }}
132-
# tenant-id: ${{ secrets.AZURE_TENANT_ID }}
133-
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
134-
135-
# - name: Deploy bicep
136-
# uses: azure/CLI@v2
137-
# with:
138-
# # azcliversion: 2.63.0 # pinning because https://github.com/Azure/cli/issues/165
139-
# inlineScript: |
140-
# REF_SHA="${{ env.BRANCH_NAME }}.${{ needs.build.outputs.sha-short }}"
141-
# DEPLOYMENT_NAME="${REF_SHA////-}"
142-
# echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME"
143-
144-
# TAGS='{"owner":"johnnyreilly", "email":"johnny_reilly@hotmail.com"}'
145-
# az deployment group create \
146-
# --resource-group ${{ env.RESOURCE_GROUP }} \
147-
# --name "$DEPLOYMENT_NAME" \
148-
# --template-file ./infra/main.bicep \
149-
# --parameters \
150-
# webServiceImage='${{ needs.build.outputs.image-node }}' \
151-
# containerRegistry=${{ env.REGISTRY }} \
152-
# containerRegistryUsername=${{ github.actor }} \
153-
# containerRegistryPassword=${{ secrets.PACKAGES_TOKEN }} \
154-
# workspaceName='shared-log-analytics' \
155-
# appInsightsName='shared-app-insights' \
156-
# managedEnvironmentName='shared-env' \
157-
# webServiceContainerAppName='${{ env.BRANCH_NAME }}-web' \
158-
# tags="$TAGS" \
159-
# APPSETTINGS_API_KEY="${{ secrets.APPSETTINGS_API_KEY }}" \
160-
# APPSETTINGS_DOMAIN="${{ vars.APPSETTINGS_DOMAIN }}" \
161-
# APPSETTINGS_PRAYER_REQUEST_FROM_EMAIL="${{ vars.APPSETTINGS_PRAYER_REQUEST_FROM_EMAIL }}" \
162-
# APPSETTINGS_PRAYER_REQUEST_RECIPIENT_EMAIL="${{ vars.APPSETTINGS_PRAYER_REQUEST_RECIPIENT_EMAIL }}"
163-
164-
# CONTAINER_APP_URL=$(az containerapp show \
165-
# --resource-group '${{ env.RESOURCE_GROUP }}' \
166-
# --name '${{ env.BRANCH_NAME }}-web' \
167-
# --query properties.configuration.ingress.fqdn \
168-
# --output tsv)
169-
170-
# echo "CONTAINER_APP_URL=$CONTAINER_APP_URL"
171-
172-
# # echo "az deployment group show --resource-group '${{ env.RESOURCE_GROUP }}' --name $DEPLOYMENT_NAME"
173-
# # DEPLOYMENT_OUTPUTS=$(az deployment group show \
174-
# # --resource-group ${{ env.RESOURCE_GROUP }} \
175-
# # --name $DEPLOYMENT_NAME \
176-
# # --query properties.outputs)
177-
178-
# # echo 'convert outputs to variables'
179-
# # echo $DEPLOYMENT_OUTPUTS | jq -c '. | to_entries[] | [.key, .value.value]' |
180-
# # while IFS=$"\n" read -r c; do
181-
# # OUTPUT_NAME=$(echo "$c" | jq -r '.[0]')
182-
# # OUTPUT_VALUE=$(echo "$c" | jq -r '.[1]')
183-
# # echo "setting variable $OUTPUT_NAME=$OUTPUT_VALUE"
184-
# # echo "{$OUTPUT_NAME}={$OUTPUT_VALUE}" >> $GITHUB_OUTPUT
185-
# # # echo "::set-output name=$OUTPUT_NAME::$OUTPUT_VALUE"
186-
# # done # --query properties.outputs.nodeUrl
18717

188-
# # az containerapp show \
189-
# # --resource-group 'rg-poorclaresarundel' \
190-
# # --name 'main-web' \
191-
# # --query properties.configuration.ingress.fqdn
18+
get-container-app-url:
19+
runs-on: ubuntu-latest
20+
needs: build-and-deploy
21+
steps:
22+
- run: echo "container-app-url=${{ needs.build-and-deploy.outputs.container-app-url }}"

.github/workflows/shared-build-and-deploy.yaml

+11-21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
# secrets:
88
# personal_access_token:
99
# required: true
10+
# Map the workflow outputs to job outputs
11+
outputs:
12+
container-app-url:
13+
description: "The URL of the deployed container app"
14+
value: ${{ jobs.deploy.outputs.container-app-url }}
1015

1116
env:
1217
RESOURCE_GROUP: rg-poorclaresarundel
@@ -41,7 +46,6 @@ jobs:
4146
# Login against a Docker registry except on PR
4247
# https://github.com/docker/login-action
4348
- name: Log into registry ${{ env.REGISTRY }}
44-
# if: github.event_name != 'pull_request'
4549
uses: docker/login-action@v3
4650
with:
4751
registry: ${{ env.REGISTRY }}
@@ -69,7 +73,6 @@ jobs:
6973
uses: docker/build-push-action@v6
7074
with:
7175
context: ./
72-
# push: ${{ github.event_name != 'pull_request' }}
7376
push: ${{ inputs.deploy }}
7477
tags: ${{ steps.meta.outputs.tags }}
7578
labels: ${{ steps.meta.outputs.labels }}
@@ -78,6 +81,8 @@ jobs:
7881
runs-on: ubuntu-latest
7982
if: inputs.deploy == true
8083
needs: [build]
84+
outputs:
85+
container-app-url: ${{ steps.deploy.outputs.CONTAINER_APP_URL }}
8186
permissions:
8287
id-token: write
8388
contents: read
@@ -86,17 +91,17 @@ jobs:
8691
- name: Checkout repository
8792
uses: actions/checkout@v4
8893

89-
- name: "AZ CLI login"
94+
- name: Azure login
9095
uses: azure/login@v2
9196
with:
9297
client-id: ${{ secrets.AZURE_CLIENT_ID }}
9398
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
9499
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
95100

96-
- name: Deploy bicep
101+
- name: Deploy to Azure
102+
id: deploy
97103
uses: azure/CLI@v2
98104
with:
99-
# azcliversion: 2.63.0 # pinning because https://github.com/Azure/cli/issues/165
100105
inlineScript: |
101106
REF_SHA="${{ env.BRANCH_NAME }}.${{ needs.build.outputs.sha-short }}"
102107
DEPLOYMENT_NAME="${REF_SHA////-}"
@@ -132,19 +137,4 @@ jobs:
132137
--output tsv)
133138
134139
echo "CONTAINER_APP_URL=$CONTAINER_APP_URL"
135-
136-
# echo "az deployment group show --resource-group '${{ env.RESOURCE_GROUP }}' --name $DEPLOYMENT_NAME"
137-
# DEPLOYMENT_OUTPUTS=$(az deployment group show \
138-
# --resource-group ${{ env.RESOURCE_GROUP }} \
139-
# --name $DEPLOYMENT_NAME \
140-
# --query properties.outputs)
141-
142-
# echo 'convert outputs to variables'
143-
# echo $DEPLOYMENT_OUTPUTS | jq -c '. | to_entries[] | [.key, .value.value]' |
144-
# while IFS=$"\n" read -r c; do
145-
# OUTPUT_NAME=$(echo "$c" | jq -r '.[0]')
146-
# OUTPUT_VALUE=$(echo "$c" | jq -r '.[1]')
147-
# echo "setting variable $OUTPUT_NAME=$OUTPUT_VALUE"
148-
# echo "{$OUTPUT_NAME}={$OUTPUT_VALUE}" >> $GITHUB_OUTPUT
149-
# # echo "::set-output name=$OUTPUT_NAME::$OUTPUT_VALUE"
150-
# done # --query properties.outputs.nodeUrl
140+
echo "CONTAINER_APP_URL=$CONTAINER_APP_URL" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)