Skip to content

Florent228 is testing out GitHub Actions #32

Florent228 is testing out GitHub Actions

Florent228 is testing out GitHub Actions #32

Workflow file for this run

name: Gestion des pushs
run-name: ${{ github.actor }} is testing out GitHub Actions
permissions: write-all
on:
push:
branches: [rabbitmq]
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DEBUG: ${{ secrets.DEBUG }}
ALLOWED_HOSTS_1: ${{ secrets.ALLOWED_HOSTS_1 }}
ALLOWED_HOSTS_2: ${{ secrets.ALLOWED_HOSTS_2 }}
CUSTOMER_API_URL: ${{ secrets.CUSTOMER_API_URL }}
DB_HOST: ${{ secrets.DB_HOST }}
MYSQL_PORT: ${{ secrets.MYSQL_PORT }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_TEST_DATABASE: ${{ secrets.MYSQL_TEST_DATABASE }}
steps:
- name: Pull Docker Image
run: docker pull ghcr.io/florent228/kawa_customer:latest
- name: Run Docker Image with Port Mapping
run: docker run -d --name kawa_customer -p 3000:3000 ghcr.io/florent228/kawa_customer:latest
- name: Display Running Containers
run: docker ps
- name: Test Customers APi
run: sleep 10 && curl -v http://localhost:3000
- name: Checkout code
uses: actions/checkout@v2
- name: Configuration de l'environnement python
uses: actions/setup-python@v2
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Exécution des tests
run: |
python manage.py test products.tests
build-and-push-docker:
needs: build-and-test
runs-on: ubuntu-latest
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DEBUG: ${{ secrets.DEBUG }}
ALLOWED_HOSTS_1: ${{ secrets.ALLOWED_HOSTS_1 }}
ALLOWED_HOSTS_2: ${{ secrets.ALLOWED_HOSTS_2 }}
CUSTOMER_API_URL: ${{ secrets.CUSTOMER_API_URL }}
DB_HOST: ${{ secrets.DB_HOST }}
MYSQL_PORT: ${{ secrets.MYSQL_PORT }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_TEST_DATABASE: ${{ secrets.MYSQL_TEST_DATABASE }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Allowed host issues
run: echo "${{ env.ALLOWED_HOSTS_1 }} ${{ env.ALLOWED_HOSTS_2 }} ${{ secrets.DB_HOST }}"
- name: Build Docker image
run: |
docker build \
--build-arg DEBUG=${{ secrets.DEBUG }} \
--build-arg ALLOWED_HOSTS_1=${{ secrets.ALLOWED_HOSTS_1 }} \
--build-arg ALLOWED_HOSTS_2=${{ secrets.ALLOWED_HOSTS_2 }} \
--build-arg CUSTOMER_API_URL=${{ secrets.CUSTOMER_API_URL }} \
--build-arg DB_HOST=${{ secrets.DB_HOST }} \
--build-arg MYSQL_PORT=${{ secrets.MYSQL_PORT }} \
--build-arg MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }} \
--build-arg MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} \
--build-arg MYSQL_USER=${{ secrets.MYSQL_USER }} \
--build-arg MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \
--build-arg MYSQL_TEST_DATABASE=${{ secrets.MYSQL_TEST_DATABASE }} \
-t kawa_product:latest .
- name: Push Docker image
run: |
docker tag kawa_product:latest ghcr.io/${{ github.repository_owner }}/kawa_product:latest
docker push ghcr.io/${{ github.repository_owner }}/kawa_product:latest
- name: Display Docker image path
run: echo "ghcr.io/${{ github.repository_owner }}/kawa_product:latest"
merge-branch-main:
needs: build-and-test
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Récupération de la date actuelle
id: get_current_date
run: |
echo "CURRENT_DATE=$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_ENV
- name: Merge branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ needs.build-and-test.result }}" == "success" ]; then
echo "Tests passed, merging to master..."
git fetch origin
git checkout main
git pull origin main
git fetch origin rabbitmq:rabbitmq # Récupération explicite de la branche dev
git merge rabbitmq
git push origin main
fi