diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml index 9767e54a7e..80ed973477 100644 --- a/.github/workflows/build-push-docker.yml +++ b/.github/workflows/build-push-docker.yml @@ -1,17 +1,15 @@ -name: Build and Push to ACR +name: Build and Push to Azure + on: push: branches: - - 'main' + - main + workflow_dispatch: + jobs: build: - name: 'Build and Push to ACR' runs-on: ubuntu-latest - defaults: - run: - shell: bash - steps: - uses: actions/checkout@v4 @@ -21,8 +19,12 @@ jobs: username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }} password: ${{ secrets.DOCKER_REGISTRY_SERVER_PASSWORD }} - - uses: docker/build-push-action@v6 + - run: | + docker build -t ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest . + docker push ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest + + - uses: azure/webapps-deploy@v3 with: - push: true - tags: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest - file: Dockerfile \ No newline at end of file + app-name: 'kantega-big-agi' + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + images: '${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest' diff --git a/infra/build.tf b/infra/build.tf deleted file mode 100644 index 773274914c..0000000000 --- a/infra/build.tf +++ /dev/null @@ -1,32 +0,0 @@ -resource "null_resource" "docker_build" { - triggers = { - always_run = "${timestamp()}" - } - - provisioner "local-exec" { - command = < /dev/null 2>&1; then - echo "Docker is not running. Please start Docker and try again." - exit 1 - fi - - # Create a temporary Buildx builder with docker-container driver - BUILDER_NAME=temp-builder-$(date +%s) - docker buildx create --name $BUILDER_NAME --use --driver docker-container - - docker image remove ${azurerm_container_registry.acr.login_server}/${var.project_name}:latest || true - az acr repository delete --name ${azurerm_container_registry.acr.name} --image ${var.project_name}:latest --yes || true - - docker buildx build --platform linux/amd64,linux/arm64 -t ${azurerm_container_registry.acr.login_server}/${var.project_name}:latest --push . - - # Clean up the temporary builder - docker buildx rm $BUILDER_NAME - EOT - } - - depends_on = [azurerm_container_registry.acr] -} diff --git a/infra/main.tf b/infra/main.tf index a4957751ca..1047c8620c 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -18,6 +18,28 @@ resource "azurerm_resource_group" "rg" { location = var.location } +resource "azurerm_virtual_network" "vnet" { + name = "${var.project_name}-vnet" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "subnet" { + name = "${var.project_name}-subnet" + resource_group_name = azurerm_resource_group.rg.name + virtual_network_name = azurerm_virtual_network.vnet.name + address_prefixes = ["10.0.1.0/24"] + + delegation { + name = "webapp-delegation" + service_delegation { + name = "Microsoft.Web/serverFarms" + actions = ["Microsoft.Network/virtualNetworks/subnets/action"] + } + } +} + resource "azurerm_container_registry" "acr" { name = replace("${var.project_name}registry", "-", "") resource_group_name = azurerm_resource_group.rg.name @@ -34,8 +56,8 @@ resource "azurerm_service_plan" "asp" { sku_name = "B1" } -resource "azurerm_linux_web_app" "app" { - name = "${var.project_name}" +resource "azurerm_linux_web_app" "browserless" { + name = "${var.project_name}-browserless" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name service_plan_id = azurerm_service_plan.asp.id @@ -43,44 +65,107 @@ resource "azurerm_linux_web_app" "app" { app_settings = { WEBSITES_ENABLE_APP_SERVICE_STORAGE = "false" WEBSITES_PORT = "3000" - - # Environment variables for the container - OPENAI_API_KEY = var.openai_api_key - ANTHROPIC_API_KEY = var.anthropic_api_key - GEMINI_API_KEY = var.gemini_api_key + MAX_CONCURRENT_SESSIONS = "10" } site_config { always_on = true - application_stack { - docker_registry_url = "https://${azurerm_container_registry.acr.login_server}" - docker_image_name = "${var.project_name}:latest" - docker_registry_username = azurerm_container_registry.acr.admin_username - docker_registry_password = azurerm_container_registry.acr.admin_password + docker_registry_url = "https://registry.hub.docker.com" + docker_image_name = "browserless/chrome:latest" + } + + ip_restriction { + ip_address = var.allowed_ip + action = "Allow" + priority = 100 + name = "AllowKantegaIP" + } + + dynamic "ip_restriction" { + for_each = toset(split(",", azurerm_linux_web_app.app.outbound_ip_addresses)) + content { + ip_address = "${ip_restriction.value}/32" + action = "Allow" + priority = 200 + name = "A-${ip_restriction.value}" + } + } + + ip_restriction { + ip_address = "0.0.0.0/0" + action = "Deny" + priority = 300 + name = "DenyAll" + } } + logs { + detailed_error_messages = false + failed_request_tracing = false + http_logs { + file_system { + retention_in_days = 7 + retention_in_mb = 25 + } + } + } + + identity { + type = "SystemAssigned" + } + + depends_on = [ + azurerm_service_plan.asp, + azurerm_subnet.subnet + ] +} + +resource "azurerm_linux_web_app" "app" { + name = var.project_name + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + service_plan_id = azurerm_service_plan.asp.id + + app_settings = { + WEBSITES_ENABLE_APP_SERVICE_STORAGE = "false" + WEBSITES_PORT = "3000" + OPENAI_API_KEY = var.openai_api_key + ANTHROPIC_API_KEY = var.anthropic_api_key + GEMINI_API_KEY = var.gemini_api_key + } + + site_config { + always_on = true + application_stack { + docker_registry_url = "https://${azurerm_container_registry.acr.login_server}" + docker_image_name = "${var.project_name}:latest" + docker_registry_username = azurerm_container_registry.acr.admin_username + docker_registry_password = azurerm_container_registry.acr.admin_password + } + ip_restriction { ip_address = var.allowed_ip action = "Allow" priority = 100 - name = "AllowSpecificIP" + name = "KantegaIP" } ip_restriction { ip_address = "0.0.0.0/0" action = "Deny" - priority = 200 + priority = 300 name = "DenyAll" } } + logs { detailed_error_messages = false - failed_request_tracing = false + failed_request_tracing = false http_logs { file_system { retention_in_days = 7 - retention_in_mb = 25 + retention_in_mb = 25 } } } @@ -89,5 +174,32 @@ resource "azurerm_linux_web_app" "app" { type = "SystemAssigned" } - depends_on = [null_resource.docker_build] -} \ No newline at end of file + depends_on = [ + azurerm_container_registry.acr, + azurerm_subnet.subnet + ] +} + +resource "azurerm_app_service_virtual_network_swift_connection" "app_vnet_integration" { + app_service_id = azurerm_linux_web_app.app.id + subnet_id = azurerm_subnet.subnet.id +} + +resource "azurerm_app_service_virtual_network_swift_connection" "browserless_vnet_integration" { + app_service_id = azurerm_linux_web_app.browserless.id + subnet_id = azurerm_subnet.subnet.id +} + +resource "null_resource" "update_settings" { + triggers = { + always_run = "${timestamp()}" + } + + provisioner "local-exec" { + command = <