-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (116 loc) · 5.65 KB
/
job-docker-build.yml
File metadata and controls
127 lines (116 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Docker Build Job
on:
workflow_call:
inputs:
trigger_type:
description: 'Trigger type (workflow_dispatch, pull_request, schedule)'
required: true
type: string
build_docker_image:
description: 'Build And Push Docker Image (Optional)'
required: false
default: false
type: boolean
outputs:
IMAGE_TAG:
description: "Generated Docker Image Tag"
value: ${{ jobs.docker-build.outputs.IMAGE_TAG }}
env:
BRANCH_NAME: ${{ github.event.workflow_run.head_branch || github.head_ref || github.ref_name }}
jobs:
docker-build:
if: inputs.trigger_type == 'workflow_dispatch' && inputs.build_docker_image == true
runs-on: ubuntu-latest
environment: production
outputs:
IMAGE_TAG: ${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Generate Unique Docker Image Tag
id: generate_docker_tag
shell: bash
run: |
echo "🔨 Building new Docker image - generating unique tag..."
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
RUN_ID="${{ github.run_id }}"
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
CLEAN_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/--*/-/g' | sed 's/^-\|-$//g')
UNIQUE_TAG="${CLEAN_BRANCH_NAME}-${TIMESTAMP}-${RUN_ID}"
echo "IMAGE_TAG=$UNIQUE_TAG" >> $GITHUB_ENV
echo "IMAGE_TAG=$UNIQUE_TAG" >> $GITHUB_OUTPUT
echo "Generated unique Docker tag: $UNIQUE_TAG"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log in to Azure Container Registry
run: az acr login --name ${{ secrets.ACR_TEST_LOGIN_SERVER }}
- name: Build and Push ContentProcessor Docker image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./src/ContentProcessor
file: ./src/ContentProcessor/Dockerfile
push: true
tags: |
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessor:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessor:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}_${{ github.run_number }}
- name: Build and Push ContentProcessorAPI Docker image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./src/ContentProcessorAPI
file: ./src/ContentProcessorAPI/Dockerfile
push: true
tags: |
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessorapi:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessorapi:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}_${{ github.run_number }}
- name: Build and Push ContentProcessorWeb Docker image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./src/ContentProcessorWeb
file: ./src/ContentProcessorWeb/Dockerfile
push: true
tags: |
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessorweb:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}
${{ secrets.ACR_TEST_LOGIN_SERVER }}/contentprocessorweb:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}_${{ github.run_number }}
- name: Verify Docker Image Build
shell: bash
run: |
echo "✅ Docker image successfully built and pushed"
echo "Image tag: ${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}"
- name: Generate Docker Build Summary
if: always()
shell: bash
run: |
ACR_NAME=$(echo "${{ secrets.ACR_TEST_LOGIN_SERVER }}")
echo "## 🐳 Docker Build Job Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| **Job Status** | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Image Tag** | \`${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Branch** | ${{ env.BRANCH_NAME }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ job.status }}" == "success" ]]; then
echo "### ✅ Build Details" >> $GITHUB_STEP_SUMMARY
echo "Successfully built and pushed three Docker images to ACR:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Built Images:**" >> $GITHUB_STEP_SUMMARY
echo "- \`${ACR_NAME}.azurecr.io/contentprocessor:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${ACR_NAME}.azurecr.io/contentprocessorapi:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${ACR_NAME}.azurecr.io/contentprocessorweb:${{ steps.generate_docker_tag.outputs.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Build Failed" >> $GITHUB_STEP_SUMMARY
echo "- Docker build process encountered an error" >> $GITHUB_STEP_SUMMARY
echo "- Check the docker-build job for detailed error information" >> $GITHUB_STEP_SUMMARY
fi