diff --git a/.github/workflows/api_build.yaml b/.github/workflows/api_build.yaml deleted file mode 100644 index b3734b1..0000000 --- a/.github/workflows/api_build.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: 'API Build' -on: - workflow_call: - inputs: - environment_name: - required: true - type: string - version_number: - required: true - type: string - -jobs: - build: - runs-on: ubuntu-latest - environment: ${{ inputs.environment_name }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - sparse-checkout: | - api - - - name: Install Nest CLI - run: | - npm install -g @nestjs/cli - - - name: 'Setup Node' - uses: actions/setup-node@v4 - with: - node-version: ${{ vars.NODE_VERSION }} - - - name: Install dependencies - run: | - npm ci - - - name: Build - run: | - npm run build - - - name: Log into Docker Hub - if: ${{ github.event_name != 'pull_request' }} - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Setup Docker Buildx - if: ${{ github.event_name != 'pull_request' }} - uses: docker/setup-buildx-action@v3 - - - name: Build and push to registry - if: ${{ github.event_name != 'pull_request' }} - uses: docker/build-push-action@v6 - with: - push: true - tags: noahspan/flying-api:${{ inputs.version_number }} - context: . - target: api diff --git a/.github/workflows/app_build.yaml b/.github/workflows/app_build.yaml deleted file mode 100644 index 5cc19da..0000000 --- a/.github/workflows/app_build.yaml +++ /dev/null @@ -1,70 +0,0 @@ -name: 'App Build' -on: - workflow_call: - inputs: - environment_name: - required: true - type: string - version_number: - required: true - type: string - -env: - VITE_API_URL: ${{ vars.VITE_API_URL }} - VITE_CLIENT_ID: ${{ vars.VITE_CLIENT_ID }} - VITE_TENANT_ID: ${{ vars.VITE_TENANT_ID }} - VITE_REDIRECT_URL: ${{ vars.VITE_REDIRECT_URL }} - -jobs: - build: - runs-on: ubuntu-latest - environment: ${{ inputs.environment_name }} - steps: - - uses: actions/checkout@v4 - with: - sparse-checkout: | - app - - - uses: pnpm/action-setup@v4 - name: Install pnpm - with: - version: 10 - run_install: false - - - name: 'Setup Node' - uses: actions/setup-node@v4 - with: - node-version: ${{ vars.NODE_VERSION }} - - - name: Install - run: | - pnpm install - - - name: Build - run: | - pnpm --filter app build - - - name: Deploy - if: ${{ github.event_name != 'pull_request' }} - run: | - pnpm --filter app --prod deploy ./.prod/app - - - name: Setup Docker Buildx - if: ${{ github.event_name != 'pull_request' }} - uses: docker/setup-buildx-action@v3 - - - name: Log into Docker Hub - if: ${{ github.event_name != 'pull_request' }} - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push to registry - if: ${{ github.event_name != 'pull_request' }} - uses: docker/build-push-action@v6 - with: - push: true - tags: noahspan/flying-app:${{ inputs.version_number }} - context: . - target: app diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 40a9e70..0fd1067 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,48 +8,25 @@ jobs: changes: uses: ./.github/workflows/changes.yaml - build-api: - if: ${{ needs.changes.outputs.api == 'true' }} - name: build-api - needs: - - changes - uses: ./.github/workflows/api_build.yaml - with: - environment_name: test - version_number: ${{ github.run_id }} - secrets: inherit - - deploy-api: - name: deploy-api - needs: - - changes - - build-api - uses: ./.github/workflows/deploy.yaml - with: - app_name: flying-api - environment_name: test - version_number: ${{ github.run_id }} - secrets: inherit - - build-app: + build: if: ${{ needs.changes.outputs.app == 'true' }} - name: build-app + name: build needs: - changes - uses: ./.github/workflows/app_build.yaml + uses: ./.github/workflows/build.yaml with: environment_name: test version_number: ${{ github.run_id }} secrets: inherit - deploy-app: - name: deploy-app + deploy: + name: deploy needs: - changes - - build-app + - build uses: ./.github/workflows/deploy.yaml with: - app_name: flying-app + app_name: flying environment_name: test version_number: ${{ github.run_id }} secrets: inherit diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index 73277e2..20ff45f 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -5,40 +5,21 @@ on: - 'v[0-9]+.[0-9]+.[0-9]+' jobs: - build-api: - name: build-api - uses: ./.github/workflows/api_build.yaml + build: + name: build + uses: ./.github/workflows/build.yaml with: environment_name: prod version_number: ${{ github.ref_name }} secrets: inherit - deploy-api: - name: deploy-api + deploy: + name: deploy needs: - - build-api + - build uses: ./.github/workflows/deploy.yaml with: - app_name: flying-api - environment_name: prod - version_number: ${{ github.ref_name }} - secrets: inherit - - build-app: - name: build-app - uses: ./.github/workflows/app_build.yaml - with: - environment_name: prod - version_number: ${{ github.ref_name }} - secrets: inherit - - deploy-app: - name: deploy-app - needs: - - build-app - uses: ./.github/workflows/deploy.yaml - with: - app_name: flying-app + app_name: flying environment_name: prod version_number: ${{ github.ref_name }} secrets: inherit diff --git a/Dockerfile b/Dockerfile index 1508532..4da73dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,18 @@ -# FROM --platform=linux/amd64 node:18-alpine AS base -# ENV PNPM_HOME="/pnpm" -# ENV PATH="$PNPM_HOME:$PATH" -# RUN corepack enable +FROM --platform=linux/amd64 node:22-slim -# FROM base AS api -# COPY /api/dist /app/dist -# COPY /api/node_modules /app/node_modules -# WORKDIR /app -# EXPOSE 3000 -# # CMD ["node", "dist/main.js"] -# ENTRYPOINT ["tail", "-f", "/dev/null"] - -# FROM base AS app -# COPY /app/dist /app/dist -# WORKDIR /app -# RUN npm i -g serve -# EXPOSE 8080 -# CMD [ "serve", "-s", "/dist", "-p", "8080" ] - - - - - -FROM --platform=linux/amd64 node:22-slim AS base - -FROM base AS api -COPY ./api/entrypoint.sh ./entrypoint.sh -RUN chmod +x entrypoint.sh +WORKDIR app +COPY ./api/dist ./api/dist +COPY ./api/package.json package-lock.json ./api +COPY ./client/dist ./client/dist WORKDIR api -COPY ./api/dist ./dist -COPY ./api/package.json package-lock.json . RUN npm ci +WORKDIR / +COPY ./api/entrypoint.sh ./entrypoint.sh +RUN chmod +x entrypoint.sh + EXPOSE 3000 ENTRYPOINT ["/entrypoint.sh"] -# ENTRYPOINT ["tail", "-f", "/dev/null"] - -FROM base AS app -WORKDIR app -COPY ./app/dist ./dist -RUN npm i -g serve -EXPOSE 8080 -CMD [ "serve", "-s", "dist", "-p", "8080" ] \ No newline at end of file +# ENTRYPOINT ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/api/entrypoint.sh b/api/entrypoint.sh index 624b8cd..7eaefbe 100644 --- a/api/entrypoint.sh +++ b/api/entrypoint.sh @@ -1,3 +1,3 @@ #!/bin/bash -npx typeorm migration:run -d ./dist/config/typeorm-cli.config.js -node ./dist/main.js \ No newline at end of file +npx typeorm migration:run -d ./app/api/dist/database/data-source.js +node ./app/api/dist/main.js \ No newline at end of file diff --git a/api/src/database/data-source.ts b/api/src/database/data-source.ts index cd6dbe6..ee34a70 100644 --- a/api/src/database/data-source.ts +++ b/api/src/database/data-source.ts @@ -9,8 +9,8 @@ const configService = new ConfigService(); export const dataSourceOptions: DataSourceOptions = { type: 'better-sqlite3', database: configService.get('DB_PATH'), - entities: ['dist/**/*.entity.js'], - migrations: ['dist/database/migrations/*.js'], + entities: ['../**/*.entity.js'], + migrations: ['./migrations/*.js'], synchronize: configService.get('DB_SYNC') } diff --git a/api/src/log/log.controller.ts b/api/src/log/log.controller.ts index 2e6dd62..702aea1 100644 --- a/api/src/log/log.controller.ts +++ b/api/src/log/log.controller.ts @@ -41,7 +41,7 @@ export class LogController { return await this.logService.find(id); } catch (error) { const customError = error as CustomError; - + console.log(error) throw new HttpException(customError.message, customError.statusCode); } } @@ -50,10 +50,11 @@ export class LogController { @Public() async findAll(): Promise { try { + console.log('blah') return await this.logService.findAll(); } catch (error) { const customError = error as CustomError; - + console.log(error) throw new HttpException(customError.message, customError.statusCode); } } diff --git a/api/src/pilot/pilot.interceptor.ts b/api/src/pilot/pilot.interceptor.ts index 5ef7036..34bf2db 100644 --- a/api/src/pilot/pilot.interceptor.ts +++ b/api/src/pilot/pilot.interceptor.ts @@ -26,7 +26,7 @@ export class PilotInterceptor implements NestInterceptor { }; }) } - + console.log(req.headers.authorization) if (req.headers.authorization) { const authHeader = req.headers.authorization; const token = authHeader && authHeader.split(' ')[1]; diff --git a/client/vite.config.ts b/client/vite.config.ts index 8c89313..64d9525 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -19,7 +19,7 @@ export default defineConfig({ target: 'http://localhost:3000', changeOrigin: true, secure: false, - rewrite: (path) => path.replace(/^\/api/, '') + // rewrite: (path) => path.replace(/^\/api/, '') } } } diff --git a/docker-compose.yaml b/docker-compose.yaml index 2ba031e..a044036 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,23 +16,22 @@ services: container_name: restore image: litestream/litestream:0.3.13 volumes: - - ./api/src/database/flying.db:/var/lib/data/flying.db - - ./api/src/database/litestream.yml:/mnt/litestream/litestream.yml + - ./database/flying.db:/var/lib/data/flying.db + - ./database/litestream/litestream.yml:/mnt/litestream/litestream.yml - backup:/mnt/data/backup - data:/var/lib/data command: restore -config /mnt/litestream/litestream.yml -if-db-not-exists -if-replica-exists /var/lib/data/flying.db - api: - container_name: flying-api + app: + container_name: flying build: context: . - target: api ports: - '3000:3000' env_file: - ./api/.env environment: - - DB_PATH=/var/lib/data/flying.db + - DB_PATH=../../var/lib/data/flying.db volumes: - data:/var/lib/data depends_on: @@ -43,22 +42,14 @@ services: container_name: replicate image: litestream/litestream:0.3.13 volumes: - - ./api/src/database/litestream.yml:/mnt/litestream/litestream.yml + - ./database/litestream/litestream.yml:/mnt/litestream/litestream.yml - backup:/mnt - data:/var/lib/data command: replicate -config /mnt/litestream/litestream.yml depends_on: - api: + app: condition: service_started - # app: - # container_name: flying-app - # build: - # context: . - # target: app - # ports: - # - '8080:8080' - volumes: # azurite-data: backup: diff --git a/infrastructure/config/api/main.tf b/infrastructure/config/api/main.tf deleted file mode 100644 index 3159b44..0000000 --- a/infrastructure/config/api/main.tf +++ /dev/null @@ -1,51 +0,0 @@ -locals { - app_name = { - test = "flying-api-test" - prod = "flying-api-prod" - } - - container_image = { - test = "docker.io/noahspan/flying-api:v2.0.0-beta" - prod = "docker.io/noahspan/flying-api:v2.0.0-beta" - } - - container_name = { - test = "flying-api-test" - prod = "flying-api-prod" - } - - custom_domain_count = { - test = 0 - prod = 0 - } - - ingress_external_enabled = { - test = true - prod = true - } - - ingress_target_port = { - test = 3000 - prod = 3000 - } - - ingress_transport = { - test = "auto" - prod = "auto" - } - - traffic_weight_percentage = { - test = 100 - prod = 100 - } - - template_min_replicas = { - test = 0 - prod = 0 - } - - template_max_replicas = { - test = 2 - prod = 2 - } -} \ No newline at end of file diff --git a/infrastructure/config/api/outputs.tf b/infrastructure/config/api/outputs.tf deleted file mode 100644 index 9578578..0000000 --- a/infrastructure/config/api/outputs.tf +++ /dev/null @@ -1,39 +0,0 @@ -output "app_name" { - value = local.app_name[var.environment] -} - -output "container_image" { - value = local.container_image[var.environment] -} - -output "container_name" { - value = local.container_name[var.environment] -} - -output "custom_domain_count" { - value = local.custom_domain_count[var.environment] -} - -output "ingress_external_enabled" { - value = local.ingress_external_enabled[var.environment] -} - -output "ingress_target_port" { - value = local.ingress_target_port[var.environment] -} - -output "ingress_transport" { - value = local.ingress_transport[var.environment] -} - -output "traffic_weight_percentage" { - value = local.traffic_weight_percentage[var.environment] -} - -output "template_min_replicas" { - value = local.template_min_replicas[var.environment] -} - -output "template_max_replicas" { - value = local.template_max_replicas[var.environment] -} \ No newline at end of file diff --git a/infrastructure/config/api/variables.tf b/infrastructure/config/api/variables.tf deleted file mode 100644 index 9b5503e..0000000 --- a/infrastructure/config/api/variables.tf +++ /dev/null @@ -1 +0,0 @@ -variable "environment" {} \ No newline at end of file diff --git a/infrastructure/config/app/main.tf b/infrastructure/config/app/main.tf deleted file mode 100644 index 0c04359..0000000 --- a/infrastructure/config/app/main.tf +++ /dev/null @@ -1,56 +0,0 @@ -locals { - app_name = { - test = "flying-test" - prod = "flying-prod" - } - - container_app_environment_name = { - test = "noahspan-test" - prod = "noahspan-prod" - } - - container_image = { - test = "noahspan/flying-app:v2.0.0-alpha" - prod = "noahspan/flying-app:v2.0.0-alpha" - } - - container_name = { - test = "flying-app-test" - prod = "flying-app-prod" - } - - custom_domain_count = { - test = 0 - prod = 1 - } - - ingress_external_enabled = { - test = true - prod = true - } - - ingress_target_port = { - test = 8080 - prod = 8080 - } - - ingress_transport = { - test = "auto" - prod = "auto" - } - - traffic_weight_percentage = { - test = 100 - prod = 100 - } - - template_min_replicas = { - test = 0 - prod = 0 - } - - template_max_replicas = { - test = 2 - prod = 2 - } -} \ No newline at end of file diff --git a/infrastructure/config/app/outputs.tf b/infrastructure/config/app/outputs.tf deleted file mode 100644 index 34329e1..0000000 --- a/infrastructure/config/app/outputs.tf +++ /dev/null @@ -1,43 +0,0 @@ -output "app_name" { - value = local.app_name[var.environment] -} - -output "container_app_environment_name" { - value = local.container_app_environment_name[var.environment] -} - -output "container_image" { - value = local.container_image[var.environment] -} - -output "container_name" { - value = local.container_name[var.environment] -} - -output "custom_domain_count" { - value = local.custom_domain_count[var.environment] -} - -output "ingress_external_enabled" { - value = local.ingress_external_enabled[var.environment] -} - -output "ingress_target_port" { - value = local.ingress_target_port[var.environment] -} - -output "ingress_transport" { - value = local.ingress_transport[var.environment] -} - -output "traffic_weight_percentage" { - value = local.traffic_weight_percentage[var.environment] -} - -output "template_min_replicas" { - value = local.template_min_replicas[var.environment] -} - -output "template_max_replicas" { - value = local.template_max_replicas[var.environment] -} \ No newline at end of file diff --git a/infrastructure/config/app/variables.tf b/infrastructure/config/app/variables.tf deleted file mode 100644 index 9b5503e..0000000 --- a/infrastructure/config/app/variables.tf +++ /dev/null @@ -1 +0,0 @@ -variable "environment" {} \ No newline at end of file diff --git a/infrastructure/config/main.tf b/infrastructure/config/main.tf index 9361aa1..5de107e 100644 --- a/infrastructure/config/main.tf +++ b/infrastructure/config/main.tf @@ -1,9 +1,36 @@ -module "app" { - source = "./app" - environment = var.environment -} +locals { + app_name = { + test = "flying-test" + prod = "flying-prod" + } -module "storage" { - source = "./storage" - environment = var.environment -} \ No newline at end of file + container_image = { + test = "noahspan/flying-app:v2.0.0-alpha" + prod = "noahspan/flying-app:v2.0.0-alpha" + } + + container_name = { + test = "flying-container-test" + prod = "flying-container-prod" + } + + container_app_environment_name = { + test = "noahspan-test" + prod = "noahspan-prod" + } + + storage_account_name = { + test = "noahspanflyingtest" + prod = "noahspanflyingprod" + } + + storage_account_containers = { + test = ["tracks"] + prod = ["tracks"] + } + + storage_account_storage_shares = { + test = ["flying-test-database-share"] + prod = ["flying-prod-database-share"] + } +} diff --git a/infrastructure/config/outputs.tf b/infrastructure/config/outputs.tf index bb7d635..ba91d03 100644 --- a/infrastructure/config/outputs.tf +++ b/infrastructure/config/outputs.tf @@ -1,7 +1,27 @@ -output "app" { - value = module.app +output "app_name" { + value = local.app_name[var.environment] } -output "storage" { - value = module.storage +output "container_image" { + value = local.container_image[var.environment] +} + +output "container_name" { + value = local.container_name[var.environment] +} + +output "container_app_environment_name" { + value = local.container_app_environment_name[var.environment] +} + +output "storage_account_name" { + value = local.storage_account_name[var.environment] +} + +output "storage_account_containers" { + value = local.storage_account_containers[var.environment] +} + +output "storage_account_storage_shares" { + value = local.storage_account_storage_shares[var.environment] } \ No newline at end of file diff --git a/infrastructure/config/storage/main.tf b/infrastructure/config/storage/main.tf deleted file mode 100644 index c414048..0000000 --- a/infrastructure/config/storage/main.tf +++ /dev/null @@ -1,21 +0,0 @@ -locals { - account_name = { - test = "noahspanflyingtest" - prod = "noahspanflyingprod" - } - - containers = { - test = ["tracks"] - prod = ["tracks"] - } - - shares = { - test = ["flying-test-files"] - prod = ["flying-prod-files"] - } - - tables = { - test = ["logs", "pilots"] - prod = ["logs", "pilots"] - } -} \ No newline at end of file diff --git a/infrastructure/config/storage/outputs.tf b/infrastructure/config/storage/outputs.tf deleted file mode 100644 index c6569ea..0000000 --- a/infrastructure/config/storage/outputs.tf +++ /dev/null @@ -1,15 +0,0 @@ -output "account_name" { - value = local.account_name[var.environment] -} - -output "containers" { - value = local.containers[var.environment] -} - -output "shares" { - value = local.shares[var.environment] -} - -output "tables" { - value = local.tables[var.environment] -} \ No newline at end of file diff --git a/infrastructure/config/storage/variables.tf b/infrastructure/config/storage/variables.tf deleted file mode 100644 index 9b5503e..0000000 --- a/infrastructure/config/storage/variables.tf +++ /dev/null @@ -1 +0,0 @@ -variable "environment" {} \ No newline at end of file diff --git a/infrastructure/container_app.tf b/infrastructure/container_app.tf index 7842a77..a67bea5 100644 --- a/infrastructure/container_app.tf +++ b/infrastructure/container_app.tf @@ -1,12 +1,12 @@ resource "azurerm_container_app" "container_app" { - name = module.environment.app.app_name + name = module.environment.app_name container_app_environment_id = data.azurerm_container_app_environment.container_app_environment.id resource_group_name = data.azurerm_resource_group.resource_group.name revision_mode = "Single" template { - min_replicas = module.environment.app.template_min_replicas - max_replicas = module.environment.app.template_max_replicas + min_replicas = 0 + max_replicas = 2 init_container { args = ["restore", "-if-db-not-exists", "-if-replica-exists", "/var/lib/data/flying.db"] @@ -60,9 +60,9 @@ resource "azurerm_container_app" "container_app" { container { cpu = 0.25 - image = module.environment.app.container_image + image = "noahspan/flying-app:v2.0.0-alpha" memory = "0.5Gi" - name = module.environment.app.container_name + name = "flying" env { name = "AZURE_STORAGE_CONNECTION_STRING" @@ -111,7 +111,7 @@ resource "azurerm_container_app" "container_app" { volume { name = "backup" - storage_name = azurerm_container_app_environment_storage.container_app_environment_storage_backup.name + storage_name = azurerm_container_app_environment_storage.container_app_environment_storage_database.name storage_type = "AzureFile" } @@ -123,13 +123,13 @@ resource "azurerm_container_app" "container_app" { ingress { allow_insecure_connections = false - external_enabled = module.environment.app.ingress_external_enabled - target_port = module.environment.app.ingress_target_port - transport = module.environment.app.ingress_transport + external_enabled = true + target_port = 3000 + transport = "auto" traffic_weight { latest_revision = true - percentage = module.environment.app.traffic_weight_percentage + percentage = 100 } } diff --git a/infrastructure/container_app_environment_storage.tf b/infrastructure/container_app_environment_storage.tf index e23187b..63d8727 100644 --- a/infrastructure/container_app_environment_storage.tf +++ b/infrastructure/container_app_environment_storage.tf @@ -1,8 +1,8 @@ -resource "azurerm_container_app_environment_storage" "container_app_environment_storage_backup" { - name = "${module.environment.app.app_name}-backup" +resource "azurerm_container_app_environment_storage" "container_app_environment_storage_database" { + name = "${module.environment.app_name}-database" container_app_environment_id = data.azurerm_container_app_environment.container_app_environment.id account_name = azurerm_storage_account.storage_account.name - share_name = azurerm_storage_share.backup_storage_share.name + share_name = azurerm_storage_share.storage_share[0].name access_key = azurerm_storage_account.storage_account.primary_access_key access_mode = "ReadOnly" } \ No newline at end of file diff --git a/infrastructure/main.tf b/infrastructure/main.tf index 8a0ff77..3cc6ebe 100644 --- a/infrastructure/main.tf +++ b/infrastructure/main.tf @@ -5,6 +5,6 @@ data "azurerm_resource_group" "resource_group" { } data "azurerm_container_app_environment" "container_app_environment" { - name = module.environment.app.container_app_environment_name + name = module.environment.container_app_environment_name resource_group_name = var.RESOURCE_GROUP_NAME } diff --git a/infrastructure/storage.tf b/infrastructure/storage.tf index 7b4163f..4577001 100644 --- a/infrastructure/storage.tf +++ b/infrastructure/storage.tf @@ -1,5 +1,5 @@ resource "azurerm_storage_account" "storage_account" { - name = module.environment.storage.account_name + name = module.environment.storage_account_name resource_group_name = data.azurerm_resource_group.resource_group.name location = data.azurerm_resource_group.resource_group.location account_tier = "Standard" @@ -7,13 +7,15 @@ resource "azurerm_storage_account" "storage_account" { } resource "azurerm_storage_container" "storage_container" { - name = "tracks" + count = length(module.environment.storage_account_containers) + name = module.environment.storage_account_containers[count.index] storage_account_id = azurerm_storage_account.storage_account.id container_access_type = "private" } -resource "azurerm_storage_share" "backup_storage_share" { - name = "${module.environment.app.app_name}-backup-storage-share" +resource "azurerm_storage_share" "storage_share" { + count = length(module.environment.storage_account_storage_shares) + name = module.environment.storage_account_storage_shares[count.index] quota = 50 storage_account_name = azurerm_storage_account.storage_account.name } \ No newline at end of file