Skip to content

Commit

Permalink
many changes to marketing (microsoft#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
crgarcia12 authored Jul 11, 2024
1 parent cd51e60 commit fc6c7cd
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 583 deletions.
29 changes: 4 additions & 25 deletions .github/workflows/marketing-builddeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,10 @@ jobs:
echo "::set-output name=azd-no-state-flag::"
}
- name: Provision Infrastructure
- name: Provision Infrastructure and deploy application
run: |
Write-Verbose "Provision infrastructure" -Verbose
azd provision `
Write-Verbose "Provision infrastructure and deploying application" -Verbose
azd up `
--no-prompt `
--environment ${{ env.AZURE_ENV_NAME }} `
${{ steps.no-state.outputs.azd-no-state-flag }}
# Make environment variables out of all outputs from bicep file
azd env get-values | % {
$name,$value = $_.Split('=')
#Value is quoted, so remove quotes
$value = $value.Replace('"','')
[System.Environment]::SetEnvironmentVariable($name,$value)
Write-Verbose "Variable '$name' set to '$value'" -Verbose
}
Write-Verbose "Frontend .env file updated with backend endpoint" -Verbose
# Replace the backend endpoint in the frontend .env file
pushd src/frontend
Copy-Item -Path .env.template -Destination .env.production
(Get-Content .env.production) -replace '<AZURE_BACKEND_URI>', $env:AZURE_BACKEND_URI | Set-Content .env.production
popd
Write-Verbose "Building and deploying application" -Verbose
azd deploy --no-prompt --environment ${{ env.AZURE_ENV_NAME }}
${{ steps.no-state.outputs.azd-no-state-flag }}
44 changes: 5 additions & 39 deletions .github/workflows/support-center-builddeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ jobs:
--federated-credential-provider "github" `
--tenant-id "$Env:AZURE_TENANT_ID"
# - name: Log in with Azure (Client Credentials)
# if: ${{ env.AZURE_CREDENTIALS != '' }}
# run: |
# $info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
# Write-Host "::add-mask::$($info.clientSecret)"
# azd auth login `
# --client-id "$($info.clientId)" `
# --client-secret "$($info.clientSecret)" `
# --tenant-id "$($info.tenantId)"
# shell: pwsh
# env:
# AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set --no-state flag for azd
id: no-state
run: |
Expand All @@ -98,31 +85,10 @@ jobs:
echo "::set-output name=azd-no-state-flag::"
}
- name: Provision Infrastructure
- name: Provision Infrastructure and deploy application
run: |
Write-Verbose "Provision infrastructure" -Verbose
azd provision `
Write-Verbose "Provision infrastructure and deploying application" -Verbose
azd up `
--no-prompt `
--environment ${{ env.AZURE_ENV_NAME }}-sc `
${{ steps.no-state.outputs.azd-no-state-flag }}
# Make environment variables out of all outputs from bicep file
azd env get-values | % {
$name,$value = $_.Split('=')
#Value is quoted, so remove quotes
$value = $value.Replace('"','')
Write-Verbose "Variable '$name' set to '$value'" -Verbose
[System.Environment]::SetEnvironmentVariable($name,$value)
}
Write-Verbose "Frontend .env file updated with backend endpoint" -Verbose
# Replace the backend endpoint in the frontend .env file
pushd src/frontend
Copy-Item -Path .env.azureConfig -Destination .env
(Get-Content .env) -replace '<AZURE_BACKEND_ENDPOINT>', $env:AZURE_BACKEND_ENDPOINT | Set-Content .env
popd
Write-Verbose "Building and deploying application" -Verbose
azd deploy --no-prompt --environment ${{ env.AZURE_ENV_NAME }}-sc
--environment ${{ env.AZURE_ENV_NAME }} `
${{ steps.no-state.outputs.azd-no-state-flag }}
5 changes: 5 additions & 0 deletions samples/marketing/azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
name: marketing
metadata:
template: [email protected]
hooks:
postprovision:
interactive: false
shell: pwsh
run: infra/azd-hooks/Write-MarketingEnvironmentVariables.ps1
services:
backend:
project: "src/backend"
Expand Down
6 changes: 2 additions & 4 deletions samples/marketing/infra/app/backend.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module fetchLatestImage '../modules/fetch-container-image.bicep' = {
}
}

resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
resource app 'Microsoft.App/containerApps@2023-11-02-preview' = {
name: name
location: location
tags: union(tags, {'azd-service-name': 'backend' })
Expand All @@ -75,9 +75,7 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
targetPort: 5244
transport: 'auto'
corsPolicy: {
allowedOrigins: union(allowedOrigins, [
// define additional allowed origins here
])
allowedOrigins: allowedOrigins
}
}
registries: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Make environment variables out of all outputs from bicep file
Write-Verbose "---Setting environment variables..." -Verbose
azd env get-values | % {
$name,$value = $_.Split('=')

#Value is quoted, so remove quotes
$value = $value.Replace('"','')

[System.Environment]::SetEnvironmentVariable($name,$value)
Write-Verbose "Variable '$name' set to '$value'" -Verbose
}
Write-Verbose "---Done setting environment variables" -Verbose

$templateFileName = ".env.template"
$prodEnvFileName = ".env"

# Replace the backend endpoint in the frontend .env file
Write-Verbose "---Updating '$prodEnvFileName' file updated with backend endpoint..." -Verbose
pushd src/frontend
if (-not (Test-Path -Path $templateFileName)) {
Write-Error "The file '$templateFileName' does not exist."
}
Copy-Item -Path $templateFileName -Destination $prodEnvFileName
(Get-Content $prodEnvFileName) -replace '<AZURE_BACKEND_URI>', $env:AZURE_BACKEND_URI | Set-Content $prodEnvFileName
popd
Write-Verbose "---Done updating '$prodEnvFileName' file updated with backend endpoint..." -Verbose
2 changes: 1 addition & 1 deletion samples/marketing/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(Test-Path src/backend/appsettings.json) {
Write-Verbose "appsettings.json created" -Verbose
}

if((Get-Content .\src\backend\appsettings.local.template.json -Raw | Select-String "<mandatory>") -ne $null) {
if((Get-Content .\src\backend\appsettings.json -Raw | Select-String "<mandatory>") -ne $null) {
Write-Error "Please update the appsettings.json file with the correct values" -ErrorAction Stop
}

Expand Down
4 changes: 2 additions & 2 deletions samples/marketing/src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ EXPOSE 30000
ENV ASPNETCORE_URLS=http://+:5274

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG configuration=Release
ARG configuration=Debug
COPY . .
RUN dotnet restore "samples/marketing/src/backend/Marketing.csproj"
WORKDIR "samples/marketing/src/backend"
RUN dotnet build "Marketing.csproj" -c $configuration -o /app/build

FROM build AS publish
ARG configuration=Release
ARG configuration=Debug
RUN dotnet publish "Marketing.csproj" -c $configuration -o /app/publish

FROM base AS final
Expand Down
6 changes: 2 additions & 4 deletions samples/marketing/src/backend/Marketing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Oagents.Core" Version="0.0.2-alpha.20240710143921" />
<PackageReference Include="Oagents.Orleans" Version="0.0.2-alpha.20240710143921" />
<PackageReference Include="Octokit.Webhooks.AspNetCore" Version="2.1.1" />
<PackageReference Include="Octokit" Version="11.0.1" />

Expand Down Expand Up @@ -51,10 +53,6 @@


</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Oagents.Orleans\Oagents.Orleans.csproj" />
</ItemGroup>


</Project>
12 changes: 0 additions & 12 deletions samples/marketing/src/backend/Marketing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marketing", "Marketing.csproj", "{491A6E2F-A0D0-4723-80A2-B0F60091E39D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AI.Agents.Orleans", "..\..\..\..\src\Microsoft.AI.Agents.Orleans\Microsoft.AI.Agents.Orleans.csproj", "{4C246005-605C-4F7F-8D67-839A5640587A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AI.Agents", "..\..\..\..\src\Microsoft.AI.Agents\Microsoft.AI.Agents.csproj", "{5CB1E5D6-33BF-4E09-BDE3-29F8A24F2158}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,14 +15,6 @@ Global
{491A6E2F-A0D0-4723-80A2-B0F60091E39D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{491A6E2F-A0D0-4723-80A2-B0F60091E39D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{491A6E2F-A0D0-4723-80A2-B0F60091E39D}.Release|Any CPU.Build.0 = Release|Any CPU
{4C246005-605C-4F7F-8D67-839A5640587A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C246005-605C-4F7F-8D67-839A5640587A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C246005-605C-4F7F-8D67-839A5640587A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C246005-605C-4F7F-8D67-839A5640587A}.Release|Any CPU.Build.0 = Release|Any CPU
{5CB1E5D6-33BF-4E09-BDE3-29F8A24F2158}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CB1E5D6-33BF-4E09-BDE3-29F8A24F2158}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CB1E5D6-33BF-4E09-BDE3-29F8A24F2158}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CB1E5D6-33BF-4E09-BDE3-29F8A24F2158}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
24 changes: 11 additions & 13 deletions samples/marketing/src/backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@
builder.Services.AddSingleton<ISignalRService, SignalRService>();


// Allow any CORS origin if in DEV
const string AllowDebugOriginPolicy = "AllowDebugOrigin";
if (builder.Environment.IsDevelopment())
// CORS is handled at the platform level (ex: Azure Container Apps)
const string AllowAllCorsOrigin = "AllowAllCorsOrigin";
builder.Services.AddCors(options =>
{
builder.Services.AddCors(options =>
options.AddPolicy(AllowAllCorsOrigin, builder =>
{
options.AddPolicy(AllowDebugOriginPolicy, builder => {
builder
.WithOrigins("http://localhost:3000") // client url
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
builder
.WithOrigins("http://localhost:3000", "https://*.azurecontainerapps.io")
.AllowAnyHeader()
.AllowAnyMethod();
});
}
});

builder.Services.AddOptions<OpenAIOptions>()
.Configure<IConfiguration>((settings, configuration) =>
Expand Down Expand Up @@ -72,8 +69,9 @@

var app = builder.Build();

app.UseCors(AllowAllCorsOrigin);

app.UseRouting();
app.UseCors(AllowDebugOriginPolicy);
app.MapControllers();

app.UseSwagger();
Expand Down
1 change: 0 additions & 1 deletion samples/marketing/src/frontend/.env.production

This file was deleted.

2 changes: 1 addition & 1 deletion samples/marketing/src/frontend/.env.template
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_BACKEND_URI=<AZURE_BACKEND_URI>
NEXT_PUBLIC_BACKEND_URI=<AZURE_BACKEND_URI>
19 changes: 4 additions & 15 deletions samples/marketing/src/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
FROM refinedev/node:18 AS base

FROM base AS deps

RUN apk add --no-cache libc6-compat

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./

RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
Expand All @@ -14,29 +11,21 @@ RUN \
fi

FROM base AS builder

ENV NEXT_TELEMETRY_DEBUG=1
COPY --from=deps /app/refine/node_modules ./node_modules

COPY . .
RUN npm run build

FROM base AS runner

ENV NODE_ENV production

ENV NODE_ENV=production
COPY --from=builder /app/refine/public ./public

RUN mkdir .next
RUN chown refine:nodejs .next

COPY --from=builder --chown=refine:nodejs /app/refine/.next/standalone ./
COPY --from=builder --chown=refine:nodejs /app/refine/.next/static ./.next/static

USER refine

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
Loading

0 comments on commit fc6c7cd

Please sign in to comment.