-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
christian bellee
authored and
christian bellee
committed
Dec 31, 2024
1 parent
e2afcd1
commit cc66a02
Showing
8 changed files
with
198 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ env: | |
RESIZE_API_NAME: 'resize' | ||
RESIZE_API_PORT: 8080 | ||
VERSION: 1.0.0 | ||
CLOUDFLARE_ZONE_ID: 'b553a0e598bd23879036daf46b81cbb3' | ||
CLOUDFLARE_EMAIL: '[email protected]' | ||
CLOUDFLARE_API_KEY: 'cloudflare_api_key' | ||
|
||
jobs: | ||
deploy-rg-job: | ||
|
@@ -121,6 +124,17 @@ jobs: | |
id: checkout-code | ||
uses: actions/checkout@main | ||
|
||
- name: create storage account | ||
uses: azure/CLI@v2 | ||
with: | ||
azcliversion: 2.67.0 | ||
inlineScript: | | ||
az deployment group create \ | ||
--name deploy-infra \ | ||
--resource-group ${{ needs.deploy-rg-job.outputs.rgName}} \ | ||
--template-file ./modules/stor.bicep \ | ||
--parameters | ||
- name: login-azure | ||
id: login-azure | ||
uses: azure/login@v2 | ||
|
@@ -142,4 +156,8 @@ jobs: | |
--parameters resizeApiContainerImage=${{ needs.deploy-rg-job.outputs.resizeApiImage }} \ | ||
--parameters ghcrPullToken=${{ secrets.PAT_TOKEN }} \ | ||
--parameters ghcrName='ghcr.io' \ | ||
--parameters githubUsername=${{ github.actor }} | ||
--parameters githubUsername=${{ github.actor }} \ | ||
--parameters cNameRecord=${{ vars.CNAME }} \ | ||
--parameters zoneName=${{ vars.ZONE_NAME }} \ | ||
--parameters cloudFlareApiToken=${{ secrets.CLOUDFLARE_API_TOKEN }} \ | ||
--parameters cloudFlareZoneId=${{ secrets.CLOUDFLARE_ZONE_ID }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
param( | ||
[string] | ||
$cloudFlareApiToken, | ||
[string] | ||
$cloudFlareZoneId, | ||
[string] | ||
$storageAccountWebEndpoint, | ||
[string] | ||
$cName | ||
) | ||
|
||
# Add CNAME DNS Record | ||
$uri = "https://api.cloudflare.com/client/v4/zones/$cloudFlareZoneId/dns_records" | ||
|
||
$params = @{ | ||
Uri = $uri | ||
Headers = @{"Authorization" = "Bearer $cloudFlareApiToken"; "Content-Type" = "application/json" } | ||
Method = 'POST' | ||
Body = | ||
@" | ||
{ | ||
"comment": "CNAME record", | ||
"content": "$storageAccountWebEndpoint", | ||
"name": "$cName", | ||
"proxied": true, | ||
"ttl": 3600, | ||
"type": "CNAME" | ||
} | ||
"@ | ||
} | ||
|
||
try { | ||
$resp = Invoke-WebRequest @params -ErrorAction Stop | ||
if ($resp.StatusCode -ne 200) { | ||
throw "Failed to add DNS Record. Code: $($resp.StatusCode) Desc: $($resp.StatusDescription)" | ||
} | ||
else { | ||
Write-Output "DNS Record added successfully" | ||
} | ||
} | ||
catch { | ||
Write-Error "Failed to add DNS Record. $($_.Exception.Message)" | ||
} | ||
|
||
# Add Cloud Connector Rule | ||
$uri = "https://api.cloudflare.com/client/v4/zones/$cloudFlareZoneId/cloud_connector/rules"; | ||
|
||
$params = @{ | ||
Uri = $uri | ||
Headers = @{"Authorization" = "Bearer $cloudFlareApiToken"; "Content-Type" = "application/json" } | ||
Method = 'PUT' | ||
Body = | ||
@" | ||
[ | ||
{ | ||
"enabled": true, | ||
"expression": "(http.request.full_uri wildcard \u0022\u0022)", | ||
"provider": "azure_storage", | ||
"description": "Connect to Azure storage container", | ||
"parameters": {"host": "$storageAccountWebEndpoint"} | ||
} | ||
] | ||
"@ | ||
} | ||
|
||
$resp = Invoke-WebRequest @params | ||
if ($resp.StatusCode -ne 200) { | ||
throw "Failed to add Cloud Connector rule. Code: $($resp.StatusCode) Desc: $($resp.StatusDescription)" | ||
} | ||
else { | ||
Write-Output "Cloud Connector rule added successfully" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
STORAGE_ACCOUNT_NAME='storhw3eyjlyy236y' | ||
STORAGE_ACCOUNT_NAME='stor6aq2g56sfcosi' | ||
|
||
az storage blob delete-batch --account-name $STORAGE_ACCOUNT_NAME --source uploads | ||
az storage blob delete-batch --account-name $STORAGE_ACCOUNT_NAME --source images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CLOUDFLARE_API_TOKEN='' | ||
CLOUDFLARE_API_KEY='' | ||
CLOUDFLARE_EMAIL='' | ||
CLOUDFLARE_ZONE_ID='' | ||
STORAGE_ACCOUNT_WEB_ENDPOINT='<storageAccountName>.z8.web.core.windows.net' | ||
CNAME='photo' | ||
ZONE_NAME='bellee.net' | ||
|
||
curl --request POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/dns_records" \ | ||
-header 'Content-Type: application/json' \ | ||
-header "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \ | ||
-header "X-Auth-Key: ${CLOUDFLARE_API_KEY}" \ | ||
-data \ | ||
" | ||
{ | ||
\"comment\": \"CNAME record\", \ | ||
\"content\": \"$STORAGE_ACCOUNT_WEB_ENDPOINT\", \ | ||
\"name\": \"$CNAME\", \ | ||
\"proxied\": true, \ | ||
\"ttl\": 3600, \ | ||
\"type\": \"CNAME\" | ||
} | ||
" | ||
|
||
curl --request PUT "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/cloud_connector/rules" \ | ||
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ | ||
--header "Content-Type: application/json" \ | ||
--data \ | ||
" | ||
[ | ||
{ | ||
\"enabled\": true, \ | ||
\"expression\": \"(http.request.full_uri wildcard)\", \ | ||
\"provider\": \"azure_storage\", \ | ||
\"description\": \"Connect to Azure storage container\", \ | ||
\"parameters\": {\"host\": \"${STORAGE_ACCOUNT_WEB_ENDPOINT}\"} | ||
} | ||
] | ||
" | ||
|
||
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \ | ||
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ | ||
-H "Content-Type:application/json" |