Skip to content

Commit

Permalink
Merge pull request #57 from inclusion-numerique/chore/updates
Browse files Browse the repository at this point in the history
Bring updates from Les Bases to Stack
  • Loading branch information
hugues-m authored Feb 12, 2024
2 parents 163abc9 + 37c01d1 commit 2820410
Show file tree
Hide file tree
Showing 51 changed files with 4,547 additions and 3,253 deletions.
185 changes: 178 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ workflows:
equal: [ web_app_deployment, << pipeline.parameters.trigger_workflow >> ]
jobs:
- prepare_workspace_dependencies
- lint:
- lint_web:
requires:
- prepare_workspace_dependencies
- lint_packages:
requires:
- prepare_workspace_dependencies
- test_packages:
Expand All @@ -90,6 +93,9 @@ workflows:
- test_web:
requires:
- prepare_workspace_dependencies
- test_web_integration:
requires:
- prepare_workspace_dependencies
- build_web:
requires:
- prepare_workspace_dependencies
Expand All @@ -104,16 +110,80 @@ workflows:

- deploy_web:
requires:
- lint
- lint_web
- lint_packages
- build_web
- test_packages
- test_web
- test_web_integration
- test_components
- test_web_e2e

- chromatic:
requires:
- deploy_web
- lint_web
- lint_packages
- build_web
- test_packages
- test_web
- test_web_integration
- test_components
- test_web_e2e

manual_backup_main_database:
when:
equal: [ backup_main_database, << pipeline.parameters.trigger_workflow >> ]
jobs:
- prepare_workspace_dependencies
- backup_main_database:
requires:
- prepare_workspace_dependencies

weekly_backup_main_database:
triggers:
- schedule:
cron: "0 0 * * 0"
filters:
branches:
only:
- main
jobs:
- prepare_workspace_dependencies
- backup_main_database:
backup_type: weekly
expires_in_days: 600
requires:
- prepare_workspace_dependencies

daily_backup_main_database:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- main
jobs:
- prepare_workspace_dependencies
- backup_main_database:
backup_type: daily
expires_in_days: 90
requires:
- prepare_workspace_dependencies
hourly_backup_main_database:
triggers:
- schedule:
cron: "0 * * * *"
filters:
branches:
only:
- main
jobs:
- prepare_workspace_dependencies
- backup_main_database:
backup_type: hourly
expires_in_days: 4
requires:
- prepare_workspace_dependencies

project_infrastructure_deployment:
when:
Expand Down Expand Up @@ -190,7 +260,7 @@ jobs:
paths:
- /home/circleci/.cache/Cypress

lint:
lint_web:
executor: node
resource_class: large
steps:
Expand All @@ -203,8 +273,25 @@ jobs:
name: 'Tsc'
command: pnpm tsc
- run:
name: 'Lint'
command: pnpm lint
name: 'Lint @app/web'
command: pnpm -F '@app/web' lint
no_output_timeout: 30m

lint_packages:
executor: node
resource_class: large
steps:
- checkout
- install_dependencies
- run:
name: 'Prisma generate'
command: pnpm --silent -F @app/web prisma generate
- run:
name: 'Tsc'
command: pnpm tsc
- run:
name: 'Lint all packages except @app/web'
command: pnpm '!@app/web' lint
no_output_timeout: 30m

lint_and_test_cdk_package:
Expand Down Expand Up @@ -390,6 +477,46 @@ jobs:
name: 'Run cypress e2e tests'
command: |
pnpm --silent -F @app/e2e cy run --record --parallel --group e2e
test_web_integration:
executor: node-e2e
resource_class: large
steps:
- checkout
- install_dependencies
- create_dotenv_file
- add_secrets_to_dotenv_file
- setup_docker_web_env
- run:
name: "Add NEXT_PUBLIC_* env to .env"
command: |
pnpm --silent cli dotenv:add-next-public --local $NAMESPACE
- run:
name: 'Add e2e vars to .env'
command: |
echo "DATABASE_URL=$CI_DATABASE_URL" >> .env
echo "SMTP_SERVER=localhost" >> .env
echo "SMTP_PORT=1025" >> .env
echo "SMTP_USERNAME=mailuser" >> .env
echo "SMTP_PASSWORD=mailpassword" >> .env
echo "SMTP_SERVER=localhost" >> .env
- run:
name: 'Prisma generate'
command: pnpm --silent -F @app/web prisma generate
- run:
name: 'Create CI database schema'
command: |
pnpm --silent -F @app/web prisma migrate deploy
- run:
name: 'Load fixtures'
command: |
pnpm -F @app/fixtures load
- restore_cache:
key: << pipeline.id >>-web-build
- add_dotenv_vars_to_bash_env
- run:
name: 'Run web integrations jest test'
command: |
pnpm --silent -F @app/web test:integration
deploy_web:
executor: node
Expand Down Expand Up @@ -512,6 +639,50 @@ jobs:
command: |
pnpm --silent -F @app/cdk cdktf deploy project --var-file .tfvars.json --auto-approve --outputs-file=cdk.out.json --outputs-file-include-sensitive-outputs
backup_main_database:
executor: node
resource_class: large
parameters:
backup_type:
type: string
default: manual
expires_in_days:
type: integer
default: 90
steps:
- checkout
- install_dependencies
- create_dotenv_file
- add_secrets_to_dotenv_file
- add_dotenv_vars_to_bash_env
- run:
name: 'Set backup file name'
command: |
BACKUP_FILE_NAME="backup_${BACKUP_DATABASE_NAME}_<< parameters.backup_type >>_$(date -u +'%Y-%m-%d-%H%M%S')"
echo "export BACKUP_FILE_NAME=$BACKUP_FILE_NAME" >> ${BASH_ENV}
echo "Backup file name: $BACKUP_FILE_NAME"
- run:
name: 'Set expires at'
# Set the BACKUP_EXPIRES_AT env variable to iso 8601 format to now + number of days in {{parameters.expires_in_days}}
command: |
BACKUP_EXPIRES_AT=$(date -u -d "+<< parameters.expires_in_days >> days" +'%Y-%m-%dT%H:%M:%SZ')
echo "export BACKUP_EXPIRES_AT=$BACKUP_EXPIRES_AT" >> ${BASH_ENV}
echo "Backup expires at: $BACKUP_EXPIRES_AT"
- run:
name: "Create backup file"
command: |
curl -X POST \
-H "X-Auth-Token: $CI_SCW_SECRET_KEY" \
-H "Content-Type: application/json" \
-d "{
\"database_name\": \"$BACKUP_DATABASE_NAME\",
\"instance_id\": \"$DATABASE_INSTANCE_ID\",
\"name\": \"$BACKUP_FILE_NAME\",
\"expires_at\": \"$BACKUP_EXPIRES_AT\"
}" \
--fail --include \
"https://api.scaleway.com/rdb/v1/regions/fr-par/backups"
web_app_preview_deletion:
executor: node
resource_class: large
Expand Down
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ CIRCLE_CI_TOKEN="<secret>"
# Used for cdk development tests only
#CDK_FORCE_BRANCH="ops/new-domain"

DATABASE_INSTANCE_ID="<secret>"
BACKUP_DATABASE_NAME=$NEXT_PUBLIC_APP_SLUG-main
MAIN_ROOT_DOMAIN=incubateur.anct.gouv.fr
PREVIEW_ROOT_DOMAIN=incubateur.anct.gouv.fr
MAIN_SUBDOMAIN=$NEXT_PUBLIC_APP_SLUG
Expand Down
10 changes: 5 additions & 5 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
},
"dependencies": {
"@commander-js/extra-typings": "^11.1.0",
"axios": "^1.6.6",
"axios": "^1.6.7",
"axios-retry": "^3.9.1",
"commander": "^11.1.0",
"csv-parse": "^5.5.3",
"csv-stringify": "^6.4.5",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"form-data": "^4.0.0",
"lodash": "^4.17.21",
"octokit": "^3.1.2",
"picocolors": "^1.0.0",
"slug": "^8.2.3",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"undici": "^5.28.2",
"undici": "^5.28.3",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.6",
"@types/node": "^20.11.17",
"@types/slug": "^5.0.7",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"joi": "^17.12.0",
"joi": "^17.12.1",
"typescript": "^5.3.3"
}
}
2 changes: 1 addition & 1 deletion apps/cli/src/deploymentTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const configureDeploymentTarget = async ({
process.env.CLI_TARGET_DEPLOYMENT_DATABASE_URL ?? ''

if (deployment !== cliEnvDeploymentTargetBranch) {
output(`⚠️ Your .env file is not configured for targetting ${deployment}:`)
output(`⚠️ Your .env file is not configured for targeting ${deployment}:`)
output(
`-> In your .env file: CLI_TARGET_DEPLOYMENT_BRANCH=${cliEnvDeploymentTargetBranch}`,
)
Expand Down
1 change: 0 additions & 1 deletion apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const path = require('node:path')
// https://github.com/vercel/next.js/tree/canary/examples/modularize-imports
const modularizeImports = {
'date-fns': { transform: 'date-fns/{{member}}' },
'chart.js': { transform: 'chart.js/{{member}}' },
}

const serverComponentsExternalPackages = ['html-minifier']
Expand Down
Loading

0 comments on commit 2820410

Please sign in to comment.