96 switch from azure table storage to sqlite #97
58
.github/workflows/api_build.yaml
vendored
58
.github/workflows/api_build.yaml
vendored
@@ -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
|
|
||||||
70
.github/workflows/app_build.yaml
vendored
70
.github/workflows/app_build.yaml
vendored
@@ -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
|
|
||||||
37
.github/workflows/main.yaml
vendored
37
.github/workflows/main.yaml
vendored
@@ -8,48 +8,25 @@ jobs:
|
|||||||
changes:
|
changes:
|
||||||
uses: ./.github/workflows/changes.yaml
|
uses: ./.github/workflows/changes.yaml
|
||||||
|
|
||||||
build-api:
|
build:
|
||||||
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:
|
|
||||||
if: ${{ needs.changes.outputs.app == 'true' }}
|
if: ${{ needs.changes.outputs.app == 'true' }}
|
||||||
name: build-app
|
name: build
|
||||||
needs:
|
needs:
|
||||||
- changes
|
- changes
|
||||||
uses: ./.github/workflows/app_build.yaml
|
uses: ./.github/workflows/build.yaml
|
||||||
with:
|
with:
|
||||||
environment_name: test
|
environment_name: test
|
||||||
version_number: ${{ github.run_id }}
|
version_number: ${{ github.run_id }}
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
deploy-app:
|
deploy:
|
||||||
name: deploy-app
|
name: deploy
|
||||||
needs:
|
needs:
|
||||||
- changes
|
- changes
|
||||||
- build-app
|
- build
|
||||||
uses: ./.github/workflows/deploy.yaml
|
uses: ./.github/workflows/deploy.yaml
|
||||||
with:
|
with:
|
||||||
app_name: flying-app
|
app_name: flying
|
||||||
environment_name: test
|
environment_name: test
|
||||||
version_number: ${{ github.run_id }}
|
version_number: ${{ github.run_id }}
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|||||||
33
.github/workflows/tag.yaml
vendored
33
.github/workflows/tag.yaml
vendored
@@ -5,40 +5,21 @@ on:
|
|||||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-api:
|
build:
|
||||||
name: build-api
|
name: build
|
||||||
uses: ./.github/workflows/api_build.yaml
|
uses: ./.github/workflows/build.yaml
|
||||||
with:
|
with:
|
||||||
environment_name: prod
|
environment_name: prod
|
||||||
version_number: ${{ github.ref_name }}
|
version_number: ${{ github.ref_name }}
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
deploy-api:
|
deploy:
|
||||||
name: deploy-api
|
name: deploy
|
||||||
needs:
|
needs:
|
||||||
- build-api
|
- build
|
||||||
uses: ./.github/workflows/deploy.yaml
|
uses: ./.github/workflows/deploy.yaml
|
||||||
with:
|
with:
|
||||||
app_name: flying-api
|
app_name: flying
|
||||||
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
|
|
||||||
environment_name: prod
|
environment_name: prod
|
||||||
version_number: ${{ github.ref_name }}
|
version_number: ${{ github.ref_name }}
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|||||||
48
Dockerfile
48
Dockerfile
@@ -1,46 +1,18 @@
|
|||||||
# FROM --platform=linux/amd64 node:18-alpine AS base
|
FROM --platform=linux/amd64 node:22-slim
|
||||||
# ENV PNPM_HOME="/pnpm"
|
|
||||||
# ENV PATH="$PNPM_HOME:$PATH"
|
|
||||||
# RUN corepack enable
|
|
||||||
|
|
||||||
# FROM base AS api
|
WORKDIR app
|
||||||
# COPY /api/dist /app/dist
|
COPY ./api/dist ./api/dist
|
||||||
# COPY /api/node_modules /app/node_modules
|
COPY ./api/package.json package-lock.json ./api
|
||||||
# WORKDIR /app
|
COPY ./client/dist ./client/dist
|
||||||
# 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 api
|
WORKDIR api
|
||||||
COPY ./api/dist ./dist
|
|
||||||
COPY ./api/package.json package-lock.json .
|
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
COPY ./api/entrypoint.sh ./entrypoint.sh
|
||||||
|
RUN chmod +x entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
# ENTRYPOINT ["tail", "-f", "/dev/null"]
|
# 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" ]
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
npx typeorm migration:run -d ./dist/config/typeorm-cli.config.js
|
npx typeorm migration:run -d ./app/api/dist/database/data-source.js
|
||||||
node ./dist/main.js
|
node ./app/api/dist/main.js
|
||||||
@@ -9,8 +9,8 @@ const configService = new ConfigService();
|
|||||||
export const dataSourceOptions: DataSourceOptions = {
|
export const dataSourceOptions: DataSourceOptions = {
|
||||||
type: 'better-sqlite3',
|
type: 'better-sqlite3',
|
||||||
database: configService.get<string>('DB_PATH'),
|
database: configService.get<string>('DB_PATH'),
|
||||||
entities: ['dist/**/*.entity.js'],
|
entities: ['../**/*.entity.js'],
|
||||||
migrations: ['dist/database/migrations/*.js'],
|
migrations: ['./migrations/*.js'],
|
||||||
synchronize: configService.get<boolean>('DB_SYNC')
|
synchronize: configService.get<boolean>('DB_SYNC')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export class LogController {
|
|||||||
return await this.logService.find(id);
|
return await this.logService.find(id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const customError = error as CustomError;
|
const customError = error as CustomError;
|
||||||
|
console.log(error)
|
||||||
throw new HttpException(customError.message, customError.statusCode);
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,10 +50,11 @@ export class LogController {
|
|||||||
@Public()
|
@Public()
|
||||||
async findAll(): Promise<LogEntity[]> {
|
async findAll(): Promise<LogEntity[]> {
|
||||||
try {
|
try {
|
||||||
|
console.log('blah')
|
||||||
return await this.logService.findAll();
|
return await this.logService.findAll();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const customError = error as CustomError;
|
const customError = error as CustomError;
|
||||||
|
console.log(error)
|
||||||
throw new HttpException(customError.message, customError.statusCode);
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class PilotInterceptor implements NestInterceptor {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
console.log(req.headers.authorization)
|
||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
const token = authHeader && authHeader.split(' ')[1];
|
const token = authHeader && authHeader.split(' ')[1];
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default defineConfig({
|
|||||||
target: 'http://localhost:3000',
|
target: 'http://localhost:3000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
// rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,23 +16,22 @@ services:
|
|||||||
container_name: restore
|
container_name: restore
|
||||||
image: litestream/litestream:0.3.13
|
image: litestream/litestream:0.3.13
|
||||||
volumes:
|
volumes:
|
||||||
- ./api/src/database/flying.db:/var/lib/data/flying.db
|
- ./database/flying.db:/var/lib/data/flying.db
|
||||||
- ./api/src/database/litestream.yml:/mnt/litestream/litestream.yml
|
- ./database/litestream/litestream.yml:/mnt/litestream/litestream.yml
|
||||||
- backup:/mnt/data/backup
|
- backup:/mnt/data/backup
|
||||||
- data:/var/lib/data
|
- data:/var/lib/data
|
||||||
command: restore -config /mnt/litestream/litestream.yml -if-db-not-exists -if-replica-exists /var/lib/data/flying.db
|
command: restore -config /mnt/litestream/litestream.yml -if-db-not-exists -if-replica-exists /var/lib/data/flying.db
|
||||||
|
|
||||||
api:
|
app:
|
||||||
container_name: flying-api
|
container_name: flying
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: api
|
|
||||||
ports:
|
ports:
|
||||||
- '3000:3000'
|
- '3000:3000'
|
||||||
env_file:
|
env_file:
|
||||||
- ./api/.env
|
- ./api/.env
|
||||||
environment:
|
environment:
|
||||||
- DB_PATH=/var/lib/data/flying.db
|
- DB_PATH=../../var/lib/data/flying.db
|
||||||
volumes:
|
volumes:
|
||||||
- data:/var/lib/data
|
- data:/var/lib/data
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -43,22 +42,14 @@ services:
|
|||||||
container_name: replicate
|
container_name: replicate
|
||||||
image: litestream/litestream:0.3.13
|
image: litestream/litestream:0.3.13
|
||||||
volumes:
|
volumes:
|
||||||
- ./api/src/database/litestream.yml:/mnt/litestream/litestream.yml
|
- ./database/litestream/litestream.yml:/mnt/litestream/litestream.yml
|
||||||
- backup:/mnt
|
- backup:/mnt
|
||||||
- data:/var/lib/data
|
- data:/var/lib/data
|
||||||
command: replicate -config /mnt/litestream/litestream.yml
|
command: replicate -config /mnt/litestream/litestream.yml
|
||||||
depends_on:
|
depends_on:
|
||||||
api:
|
app:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
||||||
# app:
|
|
||||||
# container_name: flying-app
|
|
||||||
# build:
|
|
||||||
# context: .
|
|
||||||
# target: app
|
|
||||||
# ports:
|
|
||||||
# - '8080:8080'
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
# azurite-data:
|
# azurite-data:
|
||||||
backup:
|
backup:
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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]
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
variable "environment" {}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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]
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
variable "environment" {}
|
|
||||||
@@ -1,9 +1,36 @@
|
|||||||
module "app" {
|
locals {
|
||||||
source = "./app"
|
app_name = {
|
||||||
environment = var.environment
|
test = "flying-test"
|
||||||
}
|
prod = "flying-prod"
|
||||||
|
}
|
||||||
|
|
||||||
module "storage" {
|
container_image = {
|
||||||
source = "./storage"
|
test = "noahspan/flying-app:v2.0.0-alpha"
|
||||||
environment = var.environment
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,27 @@
|
|||||||
output "app" {
|
output "app_name" {
|
||||||
value = module.app
|
value = local.app_name[var.environment]
|
||||||
}
|
}
|
||||||
|
|
||||||
output "storage" {
|
output "container_image" {
|
||||||
value = module.storage
|
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]
|
||||||
}
|
}
|
||||||
@@ -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"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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]
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
variable "environment" {}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
resource "azurerm_container_app" "container_app" {
|
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
|
container_app_environment_id = data.azurerm_container_app_environment.container_app_environment.id
|
||||||
resource_group_name = data.azurerm_resource_group.resource_group.name
|
resource_group_name = data.azurerm_resource_group.resource_group.name
|
||||||
revision_mode = "Single"
|
revision_mode = "Single"
|
||||||
|
|
||||||
template {
|
template {
|
||||||
min_replicas = module.environment.app.template_min_replicas
|
min_replicas = 0
|
||||||
max_replicas = module.environment.app.template_max_replicas
|
max_replicas = 2
|
||||||
|
|
||||||
init_container {
|
init_container {
|
||||||
args = ["restore", "-if-db-not-exists", "-if-replica-exists", "/var/lib/data/flying.db"]
|
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 {
|
container {
|
||||||
cpu = 0.25
|
cpu = 0.25
|
||||||
image = module.environment.app.container_image
|
image = "noahspan/flying-app:v2.0.0-alpha"
|
||||||
memory = "0.5Gi"
|
memory = "0.5Gi"
|
||||||
name = module.environment.app.container_name
|
name = "flying"
|
||||||
|
|
||||||
env {
|
env {
|
||||||
name = "AZURE_STORAGE_CONNECTION_STRING"
|
name = "AZURE_STORAGE_CONNECTION_STRING"
|
||||||
@@ -111,7 +111,7 @@ resource "azurerm_container_app" "container_app" {
|
|||||||
|
|
||||||
volume {
|
volume {
|
||||||
name = "backup"
|
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"
|
storage_type = "AzureFile"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,13 +123,13 @@ resource "azurerm_container_app" "container_app" {
|
|||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
allow_insecure_connections = false
|
allow_insecure_connections = false
|
||||||
external_enabled = module.environment.app.ingress_external_enabled
|
external_enabled = true
|
||||||
target_port = module.environment.app.ingress_target_port
|
target_port = 3000
|
||||||
transport = module.environment.app.ingress_transport
|
transport = "auto"
|
||||||
|
|
||||||
traffic_weight {
|
traffic_weight {
|
||||||
latest_revision = true
|
latest_revision = true
|
||||||
percentage = module.environment.app.traffic_weight_percentage
|
percentage = 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
resource "azurerm_container_app_environment_storage" "container_app_environment_storage_backup" {
|
resource "azurerm_container_app_environment_storage" "container_app_environment_storage_database" {
|
||||||
name = "${module.environment.app.app_name}-backup"
|
name = "${module.environment.app_name}-database"
|
||||||
container_app_environment_id = data.azurerm_container_app_environment.container_app_environment.id
|
container_app_environment_id = data.azurerm_container_app_environment.container_app_environment.id
|
||||||
account_name = azurerm_storage_account.storage_account.name
|
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_key = azurerm_storage_account.storage_account.primary_access_key
|
||||||
access_mode = "ReadOnly"
|
access_mode = "ReadOnly"
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,6 @@ data "azurerm_resource_group" "resource_group" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data "azurerm_container_app_environment" "container_app_environment" {
|
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
|
resource_group_name = var.RESOURCE_GROUP_NAME
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
resource "azurerm_storage_account" "storage_account" {
|
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
|
resource_group_name = data.azurerm_resource_group.resource_group.name
|
||||||
location = data.azurerm_resource_group.resource_group.location
|
location = data.azurerm_resource_group.resource_group.location
|
||||||
account_tier = "Standard"
|
account_tier = "Standard"
|
||||||
@@ -7,13 +7,15 @@ resource "azurerm_storage_account" "storage_account" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_storage_container" "storage_container" {
|
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
|
storage_account_id = azurerm_storage_account.storage_account.id
|
||||||
container_access_type = "private"
|
container_access_type = "private"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_storage_share" "backup_storage_share" {
|
resource "azurerm_storage_share" "storage_share" {
|
||||||
name = "${module.environment.app.app_name}-backup-storage-share"
|
count = length(module.environment.storage_account_storage_shares)
|
||||||
|
name = module.environment.storage_account_storage_shares[count.index]
|
||||||
quota = 50
|
quota = 50
|
||||||
storage_account_name = azurerm_storage_account.storage_account.name
|
storage_account_name = azurerm_storage_account.storage_account.name
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user