Push to Master #30
This file contains 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: Push to Master | |
on: | |
workflow_run: | |
workflows: ["Staging to Production"] | |
types: | |
- completed | |
jobs: | |
build-and-push: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
# Étape 1 : Vérifier le code | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# Connexion à DockerHub | |
- name: Log in to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Construire et pousser l'image du backend | |
- name: Build and Push Backend Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./app/backend | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/ml_ops_rest_server:latest | |
# Construire et pousser l'image du frontend | |
- name: Build and Push Frontend Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./app/frontend | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/ml_ops_front_react:latest | |
# Construire et pousser l'image du serveur web | |
- name: Build and Push Web Server Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./app/nginx | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/ml_ops_web_server:latest | |
# Step 2: Set up SSH Key for Ansible | |
- name: Configure SSH Key | |
run: | | |
echo "${{ secrets.ANSIBLE_SSH_KEY }}" > /tmp/id_rsa | |
chmod 600 /tmp/id_rsa | |
# Step 2: Set up Ansible | |
- name: Install Ansible | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y ansible | |
# Step 3: Run Ansible Playbook | |
- name: Deploy Application with Ansible | |
run: | | |
ansible-playbook -i ansible/inventories/setup.yml ansible/playbooks/deploy-playbook.yml | |
env: | |
ANSIBLE_HOST_KEY_CHECKING: "false" |