From 20395687be6ca89547b4b3d44f62b76979c379e3 Mon Sep 17 00:00:00 2001 From: Xtrah <12988459+Xtrah@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:19:11 +0200 Subject: [PATCH] tf infra, build image locally --- .dockerignore | 1 + .github/ISSUE_TEMPLATE/bug_report.yml | 32 ----- .github/ISSUE_TEMPLATE/maintainers-release.md | 132 ------------------ .github/ISSUE_TEMPLATE/roadmap-request.md | 18 --- .github/workflows/build-push-docker.yml | 28 ++++ .github/workflows/docker-image.yml | 69 --------- .gitignore | 5 + docker-compose.yaml | 27 +++- infra/build.tf | 32 +++++ infra/main.tf | 97 +++++++++++++ infra/variables.tf | 23 +++ src/common/app.config.ts | 2 +- src/common/app.nav.ts | 12 +- 13 files changed, 216 insertions(+), 262 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml delete mode 100644 .github/ISSUE_TEMPLATE/maintainers-release.md delete mode 100644 .github/ISSUE_TEMPLATE/roadmap-request.md create mode 100644 .github/workflows/build-push-docker.yml delete mode 100644 .github/workflows/docker-image.yml create mode 100644 infra/build.tf create mode 100644 infra/main.tf create mode 100644 infra/variables.tf diff --git a/.dockerignore b/.dockerignore index 2ae7123219..762b013471 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ # big-AGI non-code files /docs/ /dist/ +/infra/ README.md # Ignore build and log files diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml deleted file mode 100644 index 0089543f25..0000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: 🐞 Bug Report -description: Create a report to help us improve -title: '[BUG]' -labels: [ 'type: bug' ] -body: - - type: markdown - attributes: - value: Thank you for reporting a bug. - - type: textarea - attributes: - label: Description - description: (required) Please provide a clear description. Please also provide the steps to reproduce. - placeholder: 'Concise description + steps to reproduce.' - validations: - required: true - - type: textarea - attributes: - label: Device and browser - description: '(required) Please specify your Mobile/Desktop device, OS version, browser.' - placeholder: 'Device: (e.g., iPhone 16, Pixel 9, PC, Macbook...), OS: (e.g., iOS 17, Windows 12), Browser: (e.g., Chrome 119, Safari 18, Firefox..)' - validations: - required: true - - type: textarea - attributes: - label: Screenshots and more - placeholder: 'Attach screenshots, or add any additional context here.' - - type: checkboxes - attributes: - label: Willingness to Contribute - description: We appreciate contributions - would you be willing to submit a pull request? - options: - - label: '🙋‍♂️ Yes, I would like to contribute a fix.' diff --git a/.github/ISSUE_TEMPLATE/maintainers-release.md b/.github/ISSUE_TEMPLATE/maintainers-release.md deleted file mode 100644 index a6b781ab8a..0000000000 --- a/.github/ISSUE_TEMPLATE/maintainers-release.md +++ /dev/null @@ -1,132 +0,0 @@ ---- -name: Maintainers-Release -about: Maintainers -title: Release 1.2.3 -labels: '' -assignees: enricoros - ---- - -## Release checklist: - -- [x] Create a new [Release Issue](https://github.com/enricoros/big-AGI/issues/new?assignees=enricoros&projects=enricoros/4&template=maintainers-release.md&title=Release+1.2.3) - - [ ] Replace 1.1.0 with the _former_ release, and _1.2.3_ with THIS -- [ ] Update the [Roadmap](https://github.com/users/enricoros/projects/4/views/2) calling out shipped features -- [ ] Create and update a [Milestone](https://github.com/enricoros/big-agi/milestones) for the release - - [ ] Assign this task - - [ ] Assign all the shipped roadmap Issues - - [ ] Assign the relevant [recently closed Isssues](https://github.com/enricoros/big-agi/issues?q=is%3Aclosed+sort%3Aupdated-desc) -- Code changes: - - [ ] Create a release branch 'release-x.y.z': `git checkout -b release-1.2.3` - - [ ] Create a temporary tag `git tag v1.2.3 && git push opensource --tags` - - [ ] Create a [New Draft GitHub Release](https://github.com/enricoros/big-agi/releases/new), and generate the automated changelog (for new contributors) - - [ ] Update the release version in package.json, and `npm i` - - [ ] Update the in-app News version number - - [ ] Update in-app News [src/apps/news/news.data.tsx](/src/apps/news/news.data.tsx) - - [ ] Update in-app Cover graphics - - [ ] Update the README.md with the new release - - [ ] Copy the highlights to the [docs/changelog.md](/docs/changelog.md) -- Release: - - [ ] merge onto main `git checkout main && git merge --no-ff release-1.2.3` - - [ ] re-tag `git tag -f v1.2.3 && git push opensource --tags -f` - - [ ] verify deployment on Vercel - - [ ] verify container on GitHub Packages - - [ ] update the GitHub release - - [ ] push as stable `git push opensource main:main-stable` -- Announce: - - [ ] Discord announcement - - [ ] Twitter announcement - -### Links - -- Milestone: https://github.com/enricoros/big-AGI/milestone/X -- GitHub release: https://github.com/enricoros/big-AGI/releases/tag/v1.2.3 -- Former release task: #... - -## Artifacts Generation - -```markdown -You help me generate the following collateral for the new release of my opensource application called big-AGI. The new release is 1.2.3. -To familiarize yourself with the application, the following are the Website and the GitHub README.md. -``` - -- paste the URL: https://big-agi.com -- drag & drop: [README.md](https://raw.githubusercontent.com/enricoros/big-AGI/main/README.md) - -```markdown -I am announcing a new version, 1.2.3. -For reference, the following was the collateral for 1.1.0 (Discord announcement, GitHub Release, in-app-news file news.data.tsx). -``` - -- paste the former: `discord announcement`, -- `GitHub release`, -- `news.data.tsx`, -- `changelog.md` - -```markdown -The following are the new developments for 1.2.3: - -- ... -- git log --pretty=format:"%h %an %B" v1.1.0..v1.2.3 | clip -``` - -- paste the link to the milestone (closed) and each individual issue (content will be downloaded) -- paste the output of the git log command - -### news.data.tsx - -```markdown -I need the following from you: - -1. a table summarizing all the new features in 1.2.3 with the following columns: 4 words description (exactly what it is), short description, usefulness (what it does for the user), significance, link to the issue number (not the commit)), which will be used for the artifacts later -2. then double-check the git log to see if there are any features of significance that are not in the table -3. then score each feature in terms of importance for users (1-10), relative impact of the feature (1-10, where 10 applies to the broadest user base), and novelty and uniqueness (1-10, where 10 is truly unique and novel from what exists already) -4. then improve the table, in decreasing order of importance for features, fixing any detail that's missing, in particular check if there are commits of significance from a user or developer point of view, which are not contained in the table -5. then I want you then to update the news.data.tsx for the new release -``` - -### release name - -```markdown -please brainstorm 10 different names for this release. see the former names here: https://big-agi.com/blog -``` - -You can follow with 'What do you think of Modelmorphic?' or other selected name - -### cover images - -```markdown -Great, now I need to generate images for this. Before I used the following prompts (2 releases before). - -// An image of a capybara sculpted entirely from black cotton candy, set against a minimalist backdrop with splashes of bright, contrasting sparkles. The capybara is using a computer with split screen made of origami, split keyboard and is wearing origami sunglasses with very different split reflections. Split halves are very contrasting. Close up photography, bokeh, white background. -import coverV113 from '../../../public/images/covers/release-cover-v1.13.0.png'; -// An image of a capybara sculpted entirely from black cotton candy, set against a minimalist backdrop with splashes of bright, contrasting sparkles. The capybara is calling on a 3D origami old-school pink telephone and the camera is zooming on the telephone. Close up photography, bokeh, white background. -import coverV112 from '../../../public/images/covers/release-cover-v1.12.0.png'; - -What can I do now as far as images? Give me 4 prompt ideas with the same style as looks as the former, but different scene or action -``` - -### Readme (and Changelog) - -```markdown -I need you to update the README.md and the with the new release. -Attaching the in-app news, with my language for you to improve on, but keep the tone. -``` - -### GitHub release - -```markdown -Please create the 1.2.3 Release Notes for GitHub, following the format of the 1.1.0 GitHub release notes attached before. -Use a truthful and honest tone, understanding that people's time and attention span is short. -Today is 2024-XXXX-YYYY. -``` - -Now paste-attachment the former release notes (or 1.5.0 which was accurate and great), including the new contributors and -some stats (# of commits, etc.), and roll it for the new release. - -### Discord announcement - -```markdown -Can you generate my 1.2.3 big-AGI discord announcement from the GitHub Release announcement? -Please keep the formatting and stye of the discord announcement for 1.1.0, but with the new messaging above. -``` diff --git a/.github/ISSUE_TEMPLATE/roadmap-request.md b/.github/ISSUE_TEMPLATE/roadmap-request.md deleted file mode 100644 index 4a45933e53..0000000000 --- a/.github/ISSUE_TEMPLATE/roadmap-request.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Roadmap request -about: Suggest a roadmap item -title: "[Roadmap]" -labels: '' -assignees: '' - ---- - -**Why** -(replace this text with yours) The reason behind the request - we love it to be framed for "users will be able to do x" rather than quick-aging hype-tech-of-the-day requests - -**Description** -Clear and concise description of what you want to happen. - -**Requirements** -If you can, Please break-down the changes use cases, UX, technology, architecture, etc. -- [ ] ... diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml new file mode 100644 index 0000000000..9767e54a7e --- /dev/null +++ b/.github/workflows/build-push-docker.yml @@ -0,0 +1,28 @@ +name: Build and Push to ACR +on: + push: + branches: + - 'main' +jobs: + build: + name: 'Build and Push to ACR' + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - uses: docker/login-action@v3 + with: + registry: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }} + username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_SERVER_PASSWORD }} + + - uses: docker/build-push-action@v6 + with: + push: true + tags: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest + file: Dockerfile \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 022daa93fe..0000000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,69 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# GitHub recommends pinning actions to a commit SHA. -# To get a newer version, you will need to update the SHA. -# You can also reference a tag or branch, but the action may change without warning. - -name: Create and publish Docker images - -on: - push: - branches: - - main - #- main-stable # Disabled as the v* tag is used for stable releases - tags: - - 'v*' # Trigger on version tags (e.g., v1.7.0) - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=development,enable=${{ github.ref == 'refs/heads/main' }} - type=raw,value=stable,enable=${{ github.ref == 'refs/heads/main-stable' }} - type=ref,event=tag # Use the tag name as a tag for tag builds - type=semver,pattern={{version}} # Generate semantic versioning tags for tag builds - type=sha # Just in case none of the above applies - - - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 - with: - context: . - file: Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: NEXT_PUBLIC_GA4_MEASUREMENT_ID=${{ secrets.GA4_MEASUREMENT_ID }} diff --git a/.gitignore b/.gitignore index 874bf6f956..007982b997 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,11 @@ yarn-error.log* # local env files .env .env.* +terraform.tfvars + +# terraform +.terraform* +terraform.tfstate* # vercel .vercel diff --git a/docker-compose.yaml b/docker-compose.yaml index 61576370e8..04b6325217 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,14 +1,33 @@ -# Very simple docker-compose file to run the app on http://localhost:3000 (or http://127.0.0.1:3000). +# This file is used to run `big-AGI` and `browserless` with Docker Compose. # -# For more examples, such runnin big-AGI alongside a web browsing service, see the `docs/docker` folder. +# The two containers are linked together and `big-AGI` is configured to use `browserless` +# as its Puppeteer endpoint (from the containers intranet, it is available browserless:3000). +# +# From your host, you can access big-AGI on http://127.0.0.1:3000 and browserless on http://127.0.0.1:9222. +# +# To start the containers, run: +# docker-compose -f docs/docker/docker-compose-browserless.yaml up version: '3.9' services: big-agi: - image: ghcr.io/enricoros/big-agi:latest + build: + context: . + dockerfile: Dockerfile ports: - "3000:3000" env_file: - .env - command: [ "next", "start", "-p", "3000" ] \ No newline at end of file + environment: + - PUPPETEER_WSS_ENDPOINT=ws://browserless:3000 + command: [ "next", "start", "-p", "3000" ] + depends_on: + - browserless + + browserless: + image: browserless/chrome:latest + ports: + - "9222:3000" # Map host's port 9222 to container's port 3000 + environment: + - MAX_CONCURRENT_SESSIONS=10 \ No newline at end of file diff --git a/infra/build.tf b/infra/build.tf new file mode 100644 index 0000000000..773274914c --- /dev/null +++ b/infra/build.tf @@ -0,0 +1,32 @@ +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 new file mode 100644 index 0000000000..162f93fe02 --- /dev/null +++ b/infra/main.tf @@ -0,0 +1,97 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "4.1.0" + } + } +} + +provider "azurerm" { + features {} + subscription_id = var.azure_subscription_id + use_cli = true +} + +resource "azurerm_resource_group" "rg" { + name = "rg-${var.project_name}" + location = var.location +} + +resource "azurerm_container_registry" "acr" { + name = replace("${var.project_name}registry", "-", "") + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + sku = "Basic" + admin_enabled = true +} + +resource "azurerm_service_plan" "asp" { + name = "${var.project_name}-plan" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + os_type = "Linux" + sku_name = "B1" +} + +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" + + # 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 + } + + 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" + } + + ip_restriction { + ip_address = "0.0.0.0/0" + action = "Deny" + priority = 200 + 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" + } + + auth_settings { + enabled = false + } + + depends_on = [null_resource.docker_build] +} \ No newline at end of file diff --git a/infra/variables.tf b/infra/variables.tf new file mode 100644 index 0000000000..22a0bae0af --- /dev/null +++ b/infra/variables.tf @@ -0,0 +1,23 @@ +# variables.tf +variable "azure_subscription_id" {} +variable "openai_api_key" {} +variable "anthropic_api_key" {} +variable "gemini_api_key" {} + +variable "allowed_ip" { + description = "The IP address allowed to access the application" + type = string + default = "X.X.X.X/32" +} + +variable "project_name" { + description = "The main name for the project, used to derive other resource names" + type = string + default = "big-agi" +} + +variable "location" { + description = "The Azure region where resources will be created" + type = string + default = "Norway East" +} diff --git a/src/common/app.config.ts b/src/common/app.config.ts index 9b96e48ed1..6faab776c8 100644 --- a/src/common/app.config.ts +++ b/src/common/app.config.ts @@ -21,7 +21,7 @@ export const Brand = { Home: 'https://big-agi.com', // App: 'https://get.big-agi.com', CardImage: 'https://big-agi.com/icons/card-dark-1200.png', - OpenRepo: 'https://github.com/enricoros/big-agi', + OpenRepo: 'https://github.com/kantega/big-agi', OpenProject: 'https://github.com/users/enricoros/projects/4', SupportInvite: 'https://discord.gg/MkH4qj2Jp9', // Twitter: 'https://www.twitter.com/enricoros', diff --git a/src/common/app.nav.ts b/src/common/app.nav.ts index 74feeff3e7..0dcc34951e 100644 --- a/src/common/app.nav.ts +++ b/src/common/app.nav.ts @@ -234,12 +234,12 @@ export const navItems: { // icon: TwitterIcon, // href: 'https://twitter.com', // }, - { - type: 'extLink', - name: 'Discord', - icon: DiscordIcon, - href: Brand.URIs.SupportInvite, - }, + // { + // type: 'extLink', + // name: 'Discord', + // icon: DiscordIcon, + // href: Brand.URIs.SupportInvite, + // }, { type: 'extLink', name: 'GitHub',