99 lines
3 KiB
YAML
99 lines
3 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: deploiement-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
tests:
|
|
runs-on: docker
|
|
container:
|
|
image: node:24-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Installer les dependances
|
|
run: npm ci
|
|
|
|
- name: Tests unitaires
|
|
run: npm run test:unit -- --run
|
|
|
|
- name: Installer Chromium
|
|
run: npx playwright install --with-deps chromium
|
|
|
|
- name: Tests end-to-end
|
|
run: npm run test:e2e
|
|
env:
|
|
NUXT_ORS_API_KEY: test
|
|
|
|
deploiement:
|
|
needs: tests
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: docker
|
|
container:
|
|
image: node:24-bookworm
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
env:
|
|
AWS_DEFAULT_REGION: eu-north-1
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
ECR: ${{ secrets.ECR_REPOSITORY }}
|
|
CLUSTER: lecheminvert
|
|
SERVICE: lecheminvert
|
|
FAMILLE: lecheminvert
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Installer docker, aws et jq
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -y -qq docker.io awscli jq
|
|
|
|
- name: Determiner l etiquette de l image
|
|
run: echo "TAG=$(echo "$GITHUB_SHA" | cut -c1-12)" >> "$GITHUB_ENV"
|
|
|
|
- name: S authentifier aupres d ECR
|
|
run: |
|
|
aws ecr get-login-password | docker login --username AWS --password-stdin "${ECR%%/*}"
|
|
|
|
- name: Construire et pousser l image
|
|
run: |
|
|
docker build --platform linux/arm64 -t "$ECR:$TAG" .
|
|
docker push "$ECR:$TAG"
|
|
|
|
- name: Enregistrer la definition de tache
|
|
run: |
|
|
aws ecs describe-task-definition --task-definition "$FAMILLE" \
|
|
--query taskDefinition > actuelle.json
|
|
|
|
jq --arg image "$ECR:$TAG" '
|
|
del(.taskDefinitionArn, .revision, .status, .requiresAttributes,
|
|
.compatibilities, .registeredAt, .registeredBy, .deregisteredAt)
|
|
| .containerDefinitions[0].image = $image
|
|
' actuelle.json > nouvelle.json
|
|
|
|
REVISION=$(aws ecs register-task-definition \
|
|
--cli-input-json file://nouvelle.json \
|
|
--query 'taskDefinition.revision' --output text)
|
|
echo "Revision enregistree : $REVISION"
|
|
|
|
- name: Redeployer le service
|
|
run: |
|
|
aws ecs update-service --cluster "$CLUSTER" --service "$SERVICE" \
|
|
--task-definition "$FAMILLE" --force-new-deployment \
|
|
--query 'service.deployments[0].status' --output text
|
|
|
|
- name: Attendre la stabilisation
|
|
run: aws ecs wait services-stable --cluster "$CLUSTER" --services "$SERVICE"
|
|
|
|
- name: Verifier le service en ligne
|
|
run: |
|
|
CODE=$(curl -s -o /dev/null -w '%{http_code}' https://lecheminvert.tech/api/health)
|
|
echo "GET /api/health -> $CODE"
|
|
test "$CODE" = "200"
|