Remove local testing code containing API key #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test and deploy to branch | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| validate: | |
| name: Validate branch | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.9' | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Install frontend dependencies | |
| run: | | |
| cd UI | |
| npm install | |
| - name: Build frontend | |
| run: | | |
| cd UI | |
| npm run build | |
| # Optionnel : Ajouter des tests ici si disponibles | |
| # - name: Run backend tests | |
| # run: pytest | |
| deploy: | |
| name: Deploy to branch | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Login to registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ secrets.DOCKER_REGISTRY }} | |
| username: ${{ secrets.DOCKER_LOGIN }} | |
| password: ${{ secrets.DOCKER_PASSWD }} | |
| - name: Build and push API image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile-api | |
| push: true | |
| tags: ${{ secrets.DOCKER_REGISTRY }}/yam-report:api | |
| - name: Build and push UI image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile-ui | |
| push: true | |
| tags: ${{ secrets.DOCKER_REGISTRY }}/yam-report:ui | |
| - name: Configure SSH | |
| run: | | |
| mkdir -p ~/.ssh/ | |
| echo "$SSH_KEY" > ~/.ssh/staging.key | |
| chmod 600 ~/.ssh/staging.key | |
| cat >>~/.ssh/config <<END | |
| Host staging | |
| HostName $SSH_HOST | |
| User $SSH_USER | |
| Port $SSH_PORT | |
| IdentityFile ~/.ssh/staging.key | |
| StrictHostKeyChecking no | |
| END | |
| env: | |
| SSH_USER: ${{ secrets.SSH_USER }} | |
| SSH_KEY: ${{ secrets.SSH_KEY }} | |
| SSH_HOST: ${{ secrets.SSH_HOST }} | |
| SSH_PORT: ${{ secrets.SSH_PORT }} | |
| - name: Update branch environment | |
| env: | |
| DOCKER_BRANCH: ${{ github.ref_name }} | |
| DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} | |
| DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }} | |
| DOCKER_PASSWD: ${{ secrets.DOCKER_PASSWD }} | |
| DOMAIN_URL: ${{ secrets.DOMAIN_URL }} | |
| run: | | |
| if [[ "$DOCKER_BRANCH" == "main" ]]; then | |
| export HOSTNAME="yam-report.$DOMAIN_URL" | |
| elif [[ "$DOCKER_BRANCH" == "staging" ]]; then | |
| export HOSTNAME="yam-report.$DOCKER_BRANCH.$DOMAIN_URL" | |
| else | |
| export HOSTNAME="yam-report.$DOCKER_BRANCH.$DOMAIN_URL" | |
| fi | |
| ssh staging <<EOF | |
| set -euxo pipefail | |
| export DOCKER_BRANCH="$DOCKER_BRANCH" | |
| export DOCKER_REGISTRY="$DOCKER_REGISTRY" | |
| cd /var/docker/yam-report/$DOCKER_BRANCH | |
| git pull origin $DOCKER_BRANCH | |
| docker compose --file docker-compose-branch.yml pull | |
| docker login -u "$DOCKER_LOGIN" -p "$DOCKER_PASSWD" $DOCKER_REGISTRY | |
| HOSTNAME="$HOSTNAME" \ | |
| docker compose --project-name $DOCKER_BRANCH-yam-report --file docker-compose-branch.yml up -d | |
| EOF |