From 1f458c2a382cc5843a403120359cb44a92a33be5 Mon Sep 17 00:00:00 2001
From: nn2-minh <Nguyen12.Minh@live.uwe.ac.uk>
Date: Sun, 27 Apr 2025 15:15:34 +0700
Subject: [PATCH] fix cicd

---
 .gitlab-ci.yml | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c99e56e..35e2621 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,37 +3,56 @@ stages:
   - test
   - run
 
+image: python:3.9
+
 variables:
   VIRTUAL_ENV: .venv
-  PATH: $VIRTUAL_ENV/Scripts:$PATH
+  PATH: $VIRTUAL_ENV/bin:$PATH
+  DATABASE_HOST: mysql
+  DATABASE_USERNAME: root
+  DATABASE_PASSWORD: root
+
+services:
+  - mysql:8.0
 
 before_script:
   - python --version
   - pip --version
   # Create virtual environment
   - python -m venv $VIRTUAL_ENV
+  - source $VIRTUAL_ENV/bin/activate
   - pip install --upgrade pip
   - pip install -r requirements.txt
-  # Copy environment file
-  - cp .env.example .env
-  # Wait for MySQL (optional if already running)
-  - until mysqladmin ping -h"$DATABASE_HOST" --silent; do echo "Waiting for MySQL..."; sleep 2; done
-  # Optionally create database if it doesn't exist
-  - |
-    mysql -h"$DATABASE_HOST" -u"$DATABASE_USERNAME" -p"$DATABASE_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS shopping;"
+  # Copy environment file if exists
+  - if [ -f .env.example ]; then cp .env.example .env; fi
+  # Wait for MySQL
+  - apt-get update && apt-get install -y default-mysql-client
+  - until mysql -h"$DATABASE_HOST" -u"$DATABASE_USERNAME" -p"$DATABASE_PASSWORD" -e "SELECT 1"; do echo "Waiting for MySQL..."; sleep 2; done
+  # Create database if it doesn't exist
+  - mysql -h"$DATABASE_HOST" -u"$DATABASE_USERNAME" -p"$DATABASE_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS shopping;"
 
 install_dependencies:
   stage: install
   script:
     - echo "Dependencies installed."
+  artifacts:
+    paths:
+      - $VIRTUAL_ENV/
+    expire_in: 1 hour
 
 test:
   stage: test
   script:
+    - source $VIRTUAL_ENV/bin/activate
     - pytest
+  dependencies:
+    - install_dependencies
 
 run_app:
   stage: run
   script:
+    - source $VIRTUAL_ENV/bin/activate
     - python run_app.py
   when: manual
+  dependencies:
+    - install_dependencies
-- 
GitLab