Skip to content

Commit 3c81cc2

Browse files
Initial build docker and optional push
1 parent 455ca23 commit 3c81cc2

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build Docker and Optional Push - Content Generation Solution Accelerator
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
- demo
9+
paths:
10+
- 'content-gen/src/backend/**'
11+
- 'content-gen/src/frontend/**'
12+
- 'content-gen/src/frontend-server/**'
13+
- '.github/workflows/docker-build.yml'
14+
pull_request:
15+
types:
16+
- opened
17+
- ready_for_review
18+
- reopened
19+
- synchronize
20+
branches:
21+
- main
22+
- dev
23+
- demo
24+
paths:
25+
- 'content-gen/src/backend/**'
26+
- 'content-gen/src/frontend/**'
27+
- 'content-gen/src/frontend-server/**'
28+
- '.github/workflows/docker-build.yml'
29+
workflow_dispatch:
30+
31+
permissions:
32+
contents: read
33+
actions: read
34+
jobs:
35+
build-and-push:
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to Azure Container Registry
46+
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo')) || (github.event_name == 'workflow_dispatch' && (github.ref_name == 'dependabotchanges'||github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo')) }}
47+
uses: azure/docker-login@v2
48+
with:
49+
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
50+
username: ${{ secrets.ACR_USERNAME }}
51+
password: ${{ secrets.ACR_PASSWORD }}
52+
53+
- name: Get current date
54+
id: date
55+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
56+
57+
- name: Output ACR Login Server
58+
run: |
59+
echo "ACR Login Server: ${{ secrets.ACR_LOGIN_SERVER }}"
60+
61+
- name: Determine Tag Name Based on Branch
62+
id: determine_tag
63+
run: |
64+
if [[ "${{ github.ref_name }}" == "main" ]]; then
65+
echo "tagname=latest_v2" >> $GITHUB_OUTPUT
66+
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
67+
echo "tagname=dev" >> $GITHUB_OUTPUT
68+
elif [[ "${{ github.ref_name }}" == "demo" ]]; then
69+
echo "tagname=demo" >> $GITHUB_OUTPUT
70+
elif [[ "${{ github.ref_name }}" == "dependabotchanges" ]]; then
71+
echo "tagname=dependabotchanges" >> $GITHUB_OUTPUT
72+
else
73+
echo "tagname=default" >> $GITHUB_OUTPUT
74+
75+
fi
76+
- name: Build and Push Docker Image for Frontend Server
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: ./content-gen/src
80+
file: ./content-gen/src/WebApp.Dockerfile
81+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }}
82+
tags: |
83+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-app:${{ steps.determine_tag.outputs.tagname }}
84+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-app:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}
85+
86+
- name: Build and Push Docker Image for Backend Server
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: ./content-gen/src/backend
90+
file: ./content-gen/src/backend/ApiApp.Dockerfile
91+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }}
92+
tags: |
93+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-api:${{ steps.determine_tag.outputs.tagname }}
94+
${{ secrets.ACR_LOGIN_SERVER || 'acrlogin.azurecr.io' }}/content-gen-api:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}

0 commit comments

Comments
 (0)