-
Notifications
You must be signed in to change notification settings - Fork 802
129 lines (116 loc) · 4.14 KB
/
Copy pathdocker-build-and-push.yml
File metadata and controls
129 lines (116 loc) · 4.14 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
128
129
name: Build Docker and Optional Push v4
on:
push:
branches:
- main
- dev-v4
- demo-v4
- hotfix
paths:
- 'src/frontend/**'
- 'src/backend/**'
- 'src/mcp_server/**'
- '.github/workflows/docker-build-and-push.yml'
- 'infra/main.bicep'
- 'infra/modules/**/*.bicep'
- 'infra/*.parameters.json'
- 'infra/scripts/**'
- '.github/workflows/deploy.yml'
- 'azure.yaml'
- 'azure_custom.yaml'
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
branches:
- main
- dev-v4
- demo-v4
- hotfix
paths:
- 'src/frontend/**'
- 'src/backend/**'
- 'src/mcp_server/**'
- '.github/workflows/docker-build-and-push.yml'
- 'infra/main.bicep'
- 'infra/modules/**/*.bicep'
- 'infra/*.parameters.json'
- 'infra/scripts/**'
- '.github/workflows/deploy.yml'
- 'azure.yaml'
- 'azure_custom.yaml'
workflow_dispatch:
permissions:
contents: read
actions: read
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Azure Container Registry
if: ${{ github.ref_name == 'main' || github.ref_name == 'dev-v4'|| github.ref_name == 'demo-v4' || github.ref_name == 'hotfix' }}
uses: azure/docker-login@v2
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Get registry
id: registry
run: |
echo "ext_registry=${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}" >> $GITHUB_OUTPUT
- name: Determine Tag Name Based on Branch
id: determine_tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "TAG=latest_v4" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/dev-v4" ]]; then
echo "TAG=dev_v4" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/demo-v4" ]]; then
echo "TAG=demo_v4" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then
echo "TAG=hotfix" >> $GITHUB_ENV
else
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
fi
- name: Set Historical Tag
run: |
DATE_TAG=$(date +'%Y-%m-%d')
RUN_ID=${{ github.run_number }}
# Create historical tag using TAG, DATE_TAG, and RUN_ID
echo "HISTORICAL_TAG=${{ env.TAG }}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV
- name: Build and optionally push Backend Docker image
uses: docker/build-push-action@v6
with:
context: ./src/backend
file: ./src/backend/Dockerfile
push: ${{ env.TAG != 'pullrequest-ignore' }}
tags: |
${{ steps.registry.outputs.ext_registry }}/macaebackend:${{ env.TAG }}
${{ steps.registry.outputs.ext_registry }}/macaebackend:${{ env.HISTORICAL_TAG }}
- name: Build and optionally push Frontend Docker image
uses: docker/build-push-action@v6
with:
context: ./src/frontend
file: ./src/frontend/Dockerfile
push: ${{ env.TAG != 'pullrequest-ignore' }}
tags: |
${{ steps.registry.outputs.ext_registry }}/macaefrontend:${{ env.TAG }}
${{ steps.registry.outputs.ext_registry }}/macaefrontend:${{ env.HISTORICAL_TAG }}
- name: Build and optionally push MCP Docker image
uses: docker/build-push-action@v6
with:
context: ./src/mcp_server
file: ./src/mcp_server/Dockerfile
push: ${{ env.TAG != 'pullrequest-ignore' }}
tags: |
${{ steps.registry.outputs.ext_registry }}/macaemcp:${{ env.TAG }}
${{ steps.registry.outputs.ext_registry }}/macaemcp:${{ env.HISTORICAL_TAG }}