Skip to content

Commit

Permalink
Merge branch 'main' into TET-3959/add-tracking-to-all-FA-filtres
Browse files Browse the repository at this point in the history
  • Loading branch information
elisfainstein authored Dec 17, 2024
2 parents e49ba02 + 816e019 commit 3beaace
Show file tree
Hide file tree
Showing 22 changed files with 652 additions and 249 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/cd-tools-automation-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Déploiement à la demande de l'api d'automatisation technique
run-name: Déploiement de l'api d'automatisation technique sur ${{ github.event.inputs.target }}

on:
workflow_dispatch:
inputs:
target:
type: choice
description: Quel environnement ?
options:
- preprod
- prod

jobs:
build-tools-automation-api:
name: Build l'api d'automatisation technique
environment: ${{ github.event.inputs.target }}
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- uses: actions/checkout@v4
- uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GH_TOKEN }}
version: ^0.8.0
- name: Login into registry
run: docker login ghcr.io/territoiresentransitions --username "${{ secrets.GH_USER }}" --password "${{ secrets.GH_TOKEN }}"

- name: Build and push tools-automation-api image
run: >
earthly
--use-inline-cache --save-inline-cache --push
--platform=linux/amd64
+tools-automation-api-docker
--ENV_NAME=${{ github.event.inputs.target }}
deploy-tools-automation-api:
name: Déploie l'api d'automatisation technique
needs: build-tools-automation-api
environment: ${{ github.event.inputs.target }}
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- uses: actions/checkout@v4
- uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GH_TOKEN }}
version: ^0.8.0
- name: Login into registry
run: docker login ghcr.io/territoiresentransitions --username "${{ secrets.GH_USER }}" --password "${{ secrets.GH_TOKEN }}"
- name: Deploy tools-automation-api on Koyeb
run: >
earthly
--use-inline-cache --save-inline-cache
+tools-automation-api-deploy
--ENV_NAME=${{ github.event.inputs.target }}
--KOYEB_API_KEY=${{ secrets.KOYEB_API_KEY }}
15 changes: 15 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LOCALLY
# chemins vers les modules front
ARG --global APP_DIR='./app.territoiresentransitions.react'
ARG --global BACKEND_DIR='./backend'
ARG --global TOOLS_AUTOMATION_API_DIR='./apps/tools-automation-api'
ARG --global SITE_DIR='./packages/site'
ARG --global AUTH_DIR='./packages/auth'
ARG --global PANIER_DIR='./packages/panier'
Expand All @@ -28,6 +29,7 @@ ARG --global APPLICATION_VERSION=$(git describe --tags --always)

# TODO changer le tag
ARG --global BACKEND_IMG_NAME=$REG_TARGET/backend:$ENV_NAME-$(sh ./subdirs_hash.sh $BACKEND_DIR)
ARG --global TOOLS_AUTOMATION_API_IMG_NAME=$REG_TARGET/tools-automation-api:$ENV_NAME-$(sh ./subdirs_hash.sh $TOOLS_AUTOMATION_API_DIR)
ARG --global SITE_IMG_NAME=$REG_TARGET/site:$ENV_NAME-$FRONT_DEPS_TAG-$(sh ./subdirs_hash.sh $SITE_DIR,$UI_DIR,$API_DIR)
ARG --global AUTH_IMG_NAME=$REG_TARGET/auth:$ENV_NAME-$FRONT_DEPS_TAG-$(sh ./subdirs_hash.sh $AUTH_DIR,$UI_DIR,$API_DIR)
ARG --global PANIER_IMG_NAME=$REG_TARGET/panier:$ENV_NAME-$FRONT_DEPS_TAG-$(sh ./subdirs_hash.sh $PANIER_DIR,$UI_DIR,$API_DIR)
Expand Down Expand Up @@ -391,6 +393,19 @@ backend-test:
BUILD --pass-args ./backend+test


# BACKEND ENTRYPOINTS
# -------------------

tools-automation-api-docker:
BUILD --pass-args ./apps/tools-automation-api+docker

tools-automation-api-deploy:
ARG --required KOYEB_API_KEY
BUILD --pass-args ./apps/tools-automation-api+deploy

tools-automation-api-test:
BUILD --pass-args ./apps/tools-automation-api+test

# PANIER ENTRYPOINTS
# ------------------

Expand Down
18 changes: 18 additions & 0 deletions apps/tools-automation-api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
57 changes: 57 additions & 0 deletions apps/tools-automation-api/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
VERSION 0.8

build:
FROM ../../+front-deps

COPY . ./apps/tools-automation-api

RUN pnpm build:tools-automation-api

SAVE ARTIFACT dist /dist AS LOCAL earthly-build/dist

docker:
FROM ../../+prod-deps

ARG DOCKER_IMAGE=$TOOLS_AUTOMATION_API_IMG_NAME

ENV NODE_ENV production
ENV PORT 3000
ENV GIT_COMMIT_SHORT_SHA=$EARTHLY_GIT_SHORT_HASH
ENV GIT_COMMIT_TIMESTAMP=$EARTHLY_GIT_COMMIT_TIMESTAMP
ENV APPLICATION_VERSION=$APPLICATION_VERSION

EXPOSE ${PORT}

COPY +build/dist ./dist

CMD ["node", "dist/apps/tools-automation-api/src/main.js"]
SAVE IMAGE --push $DOCKER_IMAGE

deploy: ## Déploie le backend dans une app Koyeb existante
ARG --required KOYEB_API_KEY
ARG --required DEPLOYMENT_TIMESTAMP
ARG SERVICE_NAME=$ENV_NAME-tools-automation-api
FROM ../../+koyeb --KOYEB_API_KEY=$KOYEB_API_KEY

RUN ./koyeb services update $SERVICE_NAME/tools-automation-api \
--debug \
--docker $BACKEND_IMG_NAME \
--env ENV_NAME=$ENV_NAME \
--env DEPLOYMENT_TIMESTAMP=$DEPLOYMENT_TIMESTAMP

test-build: ## construit une image pour exécuter les tests du backend
FROM ../../+front-deps
COPY . ./apps/tools-automation-api

CMD pnpm run test:tools-automation-api
SAVE IMAGE tools-automation-api-test:latest

test: ## lance les tests
ARG network=host
LOCALLY
RUN earthly +test-build
RUN docker run --rm \
--name tools-automation-api-test_tet \
--network $network \
tools-automation-api-test:latest

10 changes: 10 additions & 0 deletions apps/tools-automation-api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'tools-automation-api',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/tools-automation-api',
};
10 changes: 10 additions & 0 deletions apps/tools-automation-api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "./src",
"entryFile": "apps/tools-automation-api/src/main",
"compilerOptions": {
"deleteOutDir": true,
"tsConfigPath": "tsconfig.app.json"
}
}
22 changes: 22 additions & 0 deletions apps/tools-automation-api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "tools-automation-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/tools-automation-api/src",
"projectType": "application",
"tags": [],
"targets": {
"dev": {
"command": "nest start --watch",
"// debug": "nest start --debug --watch",
"options": {
"cwd": "apps/tools-automation-api"
}
},
"build": {
"command": "nest build",
"options": {
"cwd": "apps/tools-automation-api"
}
}
}
}
22 changes: 22 additions & 0 deletions apps/tools-automation-api/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let app: TestingModule;

beforeAll(async () => {
app = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
});

describe('getData', () => {
it('should return "Hello API"', () => {
const appController = app.get<AppController>(AppController);
expect(appController.getData()).toEqual({ message: 'Hello API' });
});
});
});
13 changes: 13 additions & 0 deletions apps/tools-automation-api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get } from '@nestjs/common';

import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getData() {
return this.appService.getData();
}
}
11 changes: 11 additions & 0 deletions apps/tools-automation-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
21 changes: 21 additions & 0 deletions apps/tools-automation-api/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';

describe('AppService', () => {
let service: AppService;

beforeAll(async () => {
const app = await Test.createTestingModule({
providers: [AppService],
}).compile();

service = app.get<AppService>(AppService);
});

describe('getData', () => {
it('should return "Hello API"', () => {
expect(service.getData()).toEqual({ message: 'Hello API' });
});
});
});
8 changes: 8 additions & 0 deletions apps/tools-automation-api/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getData(): { message: string } {
return { message: 'Hello API' };
}
}
Empty file.
22 changes: 22 additions & 0 deletions apps/tools-automation-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
}

bootstrap();
15 changes: 15 additions & 0 deletions apps/tools-automation-api/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"exclude": [
"vitest.config.mts",
"src/**/*.spec.ts",
"src/**/*.e2e-spec.ts",
"src/**/*.test.ts"
],
"include": [
"src/**/*.ts",
]
}
17 changes: 17 additions & 0 deletions apps/tools-automation-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
28 changes: 28 additions & 0 deletions apps/tools-automation-api/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
],
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"include": [
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.e2e-spec.ts",
"test/**/*.e2e-spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
Loading

0 comments on commit 3beaace

Please sign in to comment.