1- # This is a workflow to build a Docker image and deploy it to Docker Hub
1+ # Build and Deploy to Azure Storage Static Website
22
3- name : Docker CI/CD
3+ name : Build and Deploy to Azure Storage
44
55# Controls when the workflow will run
66on :
7- # Triggers the workflow on push or pull request events but only for the "main" branch
7+ # Triggers the workflow on push events but only for the "main" branch
88 push :
99 branches : ["main"]
10- pull_request :
11- branches : ["main"]
12-
10+
1311 # Allows you to run this workflow manually from the Actions tab
1412 workflow_dispatch :
1513
1614env :
1715 PROJECT_NAME : utilplex
18- DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
19- DOCKER_HUB_REPOSITORY : ${{ vars.DOCKER_HUB_REPOSITORY || 'utilplex' }}
20- IMAGE_TAG : ${{ github.sha }}
16+ AZURE_STORAGE_ACCOUNT : ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}
2117
2218jobs :
2319 build :
24- name : Build and test
20+ name : Build Angular Application
2521 runs-on : ubuntu-latest
2622 steps :
2723 - name : Checkout
28- uses : actions/checkout@v3
24+ uses : actions/checkout@v4
2925 with :
3026 fetch-depth : 0
31-
27+
3228 - name : Set up Node 20.x
33- uses : actions/setup-node@v3
29+ uses : actions/setup-node@v4
3430 with :
3531 node-version : " 20.x"
3632 cache : ' npm'
37-
33+
3834 - name : Install dependencies
3935 run : npm ci
40-
41- - name : Build
36+
37+ - name : Build application
4238 run : npm run build:ci
43-
44- - name : Set up Docker Buildx
45- uses : docker/setup-buildx-action@v2
46-
47- - name : Build and export Docker image
48- uses : docker/build-push-action@v4
49- with :
50- context : .
51- load : true
52- tags : ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
53-
54- - name : Test Docker image
55- run : |
56- docker run --rm ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }} echo "Docker image built successfully"
57-
58- - name : Archive build
39+
40+ - name : Archive build artifacts
5941 if : success()
6042 uses : actions/upload-artifact@v4
6143 with :
62- name : docker_meta
63- path : |
64- .docker/
65- Dockerfile
66- docker-compose.yml
67- if-no-files-found : ignore
44+ name : browser-build
45+ path : dist/utilplex/browser/
46+ retention-days : 1
6847
6948 deploy :
70- name : Deploy to Docker Hub
49+ name : Deploy to Azure Storage
7150 runs-on : ubuntu-latest
7251 needs : build
73- if : github.event_name != 'pull_request'
7452 steps :
75- - name : Checkout
76- uses : actions/checkout@v3
77-
7853 - name : Download build artifacts
7954 uses : actions/download-artifact@v4
8055 with :
81- name : docker_meta
82- path : .
83-
84- - name : Set up Docker Buildx
85- uses : docker/setup-buildx-action@v2
86-
87- - name : Login to Docker Hub
88- uses : docker/login-action@v3
89- with :
90- username : ${{ secrets.DOCKER_HUB_USERNAME }}
91- password : ${{ secrets.DOCKER_HUB_TOKEN }}
92-
93- - name : Build and push Docker image
94- uses : docker/build-push-action@v4
95- with :
96- context : .
97- push : true
98- tags : |
99- ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
100- ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:latest
56+ name : browser-build
57+ path : ./browser
58+
59+ - name : Install Azure CLI
60+ run : |
61+ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
62+
63+ - name : Login to Azure
64+ run : |
65+ az storage account show \
66+ --name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
67+ --query 'name' \
68+ --output tsv
69+ env :
70+ AZURE_STORAGE_ACCOUNT : ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}
71+ AZURE_STORAGE_KEY : ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }}
72+
73+ - name : Enable static website hosting
74+ run : |
75+ az storage blob service-properties update \
76+ --account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
77+ --account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
78+ --static-website \
79+ --index-document index.html \
80+ --404-document index.html
81+
82+ - name : Upload files to Azure Storage
83+ run : |
84+ # Upload index.html with short cache (5 minutes)
85+ az storage blob upload-batch \
86+ --account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
87+ --account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
88+ --destination '$web' \
89+ --source ./browser \
90+ --pattern "index.html" \
91+ --content-cache-control "public, max-age=300, must-revalidate" \
92+ --overwrite
93+
94+ # Upload hashed JS/CSS files with long cache (1 year)
95+ az storage blob upload-batch \
96+ --account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
97+ --account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
98+ --destination '$web' \
99+ --source ./browser \
100+ --pattern "*.js" \
101+ --content-cache-control "public, max-age=31536000, immutable" \
102+ --overwrite
103+
104+ az storage blob upload-batch \
105+ --account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
106+ --account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
107+ --destination '$web' \
108+ --source ./browser \
109+ --pattern "*.css" \
110+ --content-cache-control "public, max-age=31536000, immutable" \
111+ --overwrite
112+
113+ # Upload all other files with medium cache (1 day)
114+ az storage blob upload-batch \
115+ --account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \
116+ --account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
117+ --destination '$web' \
118+ --source ./browser \
119+ --content-cache-control "public, max-age=86400" \
120+ --overwrite
121+
122+ - name : Display deployment URL
123+ run : |
124+ echo "🚀 Deployment successful!"
125+ echo "Static website URL: https://${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}.z13.web.core.windows.net/"
126+ echo "Note: The exact URL format depends on your Azure region."
0 commit comments