Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify azure #6

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/azure-deploy-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
- uses: actions/checkout@v2
- name: Deploy everything to Azure
env:
VAHTER_DEPLOY_APPID: ${{ secrets.VAHTER_DEPLOY_APPID }}
VAHTER_DEPLOY_PWD: ${{ secrets.VAHTER_DEPLOY_PWD }}
VAHTER_DEPLOY_TENANT: ${{ secrets.VAHTER_DEPLOY_TENANT }}
DOTNETRU_DEPLOY_APPID: ${{ secrets.DOTNETRU_DEPLOY_APPID }}
DOTNETRU_DEPLOY_PWD: ${{ secrets.DOTNETRU_DEPLOY_PWD }}
DOTNETRU_DEPLOY_TENANT: ${{ secrets.DOTNETRU_DEPLOY_TENANT }}
VAHTER_CONFIG: ${{ secrets.VAHTER_CONFIG }}
run: |
cd src/Grinder.Farmer
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/azure-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
- uses: actions/checkout@v2
- name: Build and push docker image to registry
env:
VAHTER_DEPLOY_APPID: ${{ secrets.VAHTER_DEPLOY_APPID }}
VAHTER_DEPLOY_PWD: ${{ secrets.VAHTER_DEPLOY_PWD }}
VAHTER_DEPLOY_TENANT: ${{ secrets.VAHTER_DEPLOY_TENANT }}
DOTNETRU_DEPLOY_APPID: ${{ secrets.DOTNETRU_DEPLOY_APPID }}
DOTNETRU_DEPLOY_PWD: ${{ secrets.DOTNETRU_DEPLOY_PWD }}
DOTNETRU_DEPLOY_TENANT: ${{ secrets.DOTNETRU_DEPLOY_TENANT }}
VAHTER_CONFIG: ${{ secrets.VAHTER_CONFIG }}
run: |
cd src/Grinder.Farmer
Expand Down
66 changes: 44 additions & 22 deletions src/Grinder.Farmer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ open Farmer
open Farmer.Builders
open Medallion.Shell

let resourceGroup = "vahter-rg"
let acrName = "vahterregistry"
let logName = "vahter-log"
let resourceGroup = "dotnetru-rg"
let acrName = "dotnetruacr"
let logName = "dotnetru-log"
let appName = "vahter-app"

let servicePlanName = "dotnetru-service-plan"

let getEnv name =
match Environment.GetEnvironmentVariable name with
| null ->
Expand All @@ -17,9 +19,9 @@ let getEnv name =
// Console.ReadLine()
| value -> value

let appId = getEnv "VAHTER_DEPLOY_APPID"
let pwd = getEnv "VAHTER_DEPLOY_PWD"
let tenant = getEnv "VAHTER_DEPLOY_TENANT"
let appId = getEnv "DOTNETRU_DEPLOY_APPID"
let pwd = getEnv "DOTNETRU_DEPLOY_PWD"
let tenant = getEnv "DOTNETRU_DEPLOY_TENANT"

type Result.ResultBuilder with
member _.Bind(cmd: Command, next: unit -> Result<'a, string>): Result<'a, string> =
Expand All @@ -33,15 +35,14 @@ type Result.ResultBuilder with
let botSettings =
let vahterConfig = Environment.GetEnvironmentVariable "VAHTER_CONFIG"
if File.Exists "./settings.json" then
File.ReadAllText "settings.json"
File.ReadAllText "./settings.json"
else if vahterConfig <> null then
vahterConfig
else
failwith "Please put bot settings either 1) in settings.json 2) or in env VAHTER_CONFIG"

let logs = logAnalytics {
name logName

retention_period 30<Days>
enable_query
enable_ingestion
Expand All @@ -54,21 +55,25 @@ let registry = containerRegistry {
enable_admin_user
}

let servicePlan = servicePlan {
name servicePlanName
sku WebApp.Sku.B1
operating_system Linux
}

let botApp = webApp {
name appName

app_insights_off
always_on
operating_system Linux
sku WebApp.Sku.B1

link_to_service_plan servicePlan

setting "VAHTER_CONFIG" botSettings

docker_ci
docker_use_azure_registry acrName
docker_image "vahter/grinder:latest" ""

depends_on logs.Name
}

let registryDeployment = arm {
Expand All @@ -81,10 +86,13 @@ let registryDeployment = arm {

let appDeployment = arm {
location Location.NorthEurope
add_resources [
logs
botApp
]
add_resource servicePlan
add_resource botApp
add_resource logs
}

let addLogsToWebApp = arm {
location Location.NorthEurope
add_resource (Resource.ofJson $"""
{{
"type": "Microsoft.Web/sites/providers/diagnosticSettings",
Expand Down Expand Up @@ -142,29 +150,43 @@ let pushDockerImage (host, user, pwd) = result {
let deployAll() = result {
// authenticate into Azure
let! authResult = Deploy.authenticate appId pwd tenant
printfn "%A" authResult
printfn $"%A{authResult}"

// deploying container registry
let! registryDeploymentResult =
Deploy.tryExecute
resourceGroup
Deploy.NoParameters
registryDeployment

printfn "ACR deployed successfully"

let registryPwd = registryDeploymentResult.["pwd"]
let registryLogin = registryDeploymentResult.["login"]
let registryHost = registryDeploymentResult.["host"]

printfn $"%A{registryDeploymentResult}"

// build&push image to registry
do! pushDockerImage(registryHost, registryLogin, registryPwd)

printfn "Docker image pushed successfully"

// deploy webapp with bot
let! deploymentResult =
// deploy webapp
let! _ =
Deploy.tryExecute
resourceGroup
[ botApp.DockerAcrCredentials.Value.Password.Value, registryPwd ]
appDeployment
return printfn "%A" deploymentResult
printfn "Webapp, log analytic and service plan deployed successfully"

// deploy logs
let! _ =
Deploy.tryExecute
resourceGroup
Deploy.NoParameters
addLogsToWebApp
return printfn "Logs linked with webapp successfully"
}

[<EntryPoint>]
Expand All @@ -180,6 +202,6 @@ let main argv =
// deploy everything = resources + image
deployAll()
| x ->
failwithf "Unknown arguments %A" x
failwith $"Unknown arguments %A{x}"
|> Result.get
0
0
6 changes: 3 additions & 3 deletions src/Grinder.Farmer/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ To deploy just an image don't pass any argument
- Net5 SDK

- Azure credentials (put them in env variables)
- `VAHTER_DEPLOY_APPID`
- `VAHTER_DEPLOY_PWD`
- `VAHTER_DEPLOY_TENANT`
- `DOTNETRU_DEPLOY_APPID`
- `DOTNETRU_DEPLOY_PWD`
- `DOTNETRU_DEPLOY_TENANT`

- Bot settings (pick one)
- `settings.json` file
Expand Down