Communication between job container1 and job container2

:hugs: Please help fill in this template with all the details to help others help you more efficiently. Use formatting blocks for code, config, logs and ensure to remove sensitive data.

I have cicd set up in which,

job1 is a mysql image container which use mysql service container
job2 is django image created which use DIND service container
I have enabled variables:
FF_NETWORK_PER_BUILD: 1 in cicd pipeline
So theoretically, I have 4 containers
job1 container + mysql service container
job2 container(django image)+ DIND service container
I am in need of connecting job2 container(django image) to mysql service container, but showing mysql host not found
As per documentation, i understood that, when FF_NETWORK_PER_BUILD: 1 , each job create isolated network, which results in two islolate dnetwork for my cicd set up
so wondering how communciaiton possible btwconnecting job2 container(django image) to mysql service container as these are in two isolated network. Please correct me if I am wrong.
Please anyone advise.

Steps to reproduce

Configuration

stages:

  • mysql-setup
  • versioning
  • django-setup
  • test

variables:
FF_NETWORK_PER_BUILD: 1 # Global variable, applies to all jobs in the pipeline

mysql_build:
stage: mysql-setup
variables:
MYSQL_ROOT: “$DB_ROOT”
MYSQL_ROOT_PASSWORD: “$DB_ROOT_PASSWORD”
MYSQL_DATABASE: “$DB_NAME”
MYSQL_DB_USER: “$DB_USER”
MYSQL_DB_PASSWORD: “$DB_PASSWORD”
MYSQL_HOST: “$DB_HOST”
services:
- name: mysql:latest
alias: mysql
image: mysql
before_script:
- mysql --version
script:
# Reset root password
# echo “Resetting root password…”
# mysqladmin --user=“${MYSQL_ROOT}” --password=“${MYSQL_ROOT_PASSWORD}” --host=mysql pamssword “${MYSQL_ROOT_PASSWORD}”

# Create new database user
- echo "Creating new database user..."
- echo "CREATE USER '${MYSQL_DB_USER}'@'%' IDENTIFIED BY '${MYSQL_DB_PASSWORD}';" | mysql --user="${MYSQL_ROOT}" --password="${MYSQL_ROOT_PASSWORD}" --host="${MYSQL_HOST}"

# Verify user creation
- echo "Verifying user creation..."
- echo "SELECT user FROM mysql.user;" | mysql --user="${MYSQL_ROOT}" --password="${MYSQL_ROOT_PASSWORD}" --host="${MYSQL_HOST}"

# Allow permission to DB
- echo "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_DB_USER}'@'%' WITH GRANT OPTION;" | mysql --user="${MYSQL_ROOT}" --password="${MYSQL_ROOT_PASSWORD}" --host="${MYSQL_HOST}" 

# Verify user and access
- echo "SELECT 'OK';" | mysql --user="${MYSQL_DB_USER}" --password="${MYSQL_DB_PASSWORD}" --host="${MYSQL_HOST}" "${MYSQL_DATABASE}"
- echo "SHOW DATABASES;" | mysql --user="${MYSQL_ROOT}" --password="${MYSQL_ROOT_PASSWORD}" --host="${MYSQL_HOST}"

update-version:
stage: versioning
variables:
VERSION_FILE: “version.txt” # Path to the version file
script:
- chmod +x update_version.sh # Ensure script is executable
- ./update_version.sh $VERSION_FILE major # Increment the minor version
artifacts:
paths:
- version.txt # Make the updated version file available as an artifact

django-build:
stage: django-setup
variables:
DOCKER_IMAGE_NAME: “realestate_backend” # Replace with your desired image name
image: docker:20.10.10
services:
- name: docker:20.10.10-dind
alias: dind # Alias for the DinD service container
- name: mysql:latest
alias: mysql # Alias for the MySQL service container
dependencies:
- update-version
script:
# Building django docker image
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- VERSION=$(cat version.txt) # Read version from the artifact
- docker build -t $CI_REGISTRY_IMAGE:$VERSION .
- echo “$CI_REGISTRY_IMAGE:$VERSION”
- docker push $CI_REGISTRY_IMAGE:$VERSION
# Apply Django database migrations and run tests inside the container
- docker run --rm -v $(pwd):/app $CI_REGISTRY_IMAGE:$VERSION sh -c “cd /app && python manage.py migrate && python manage.py test”
artifacts:
paths:
- version.txt

Versions

Gitlab cloud (GitLab.com SaaS )and Self-hosted Runners
Please select whether options apply, and add the version information.

  • Self-managed
  • [ *] GitLab.com SaaS
  • [* ] Self-hosted Runners

Versions

gitlab-runner --version
Version: 16.11.1
Git revision: 535ced5f
Git branch: 16-11-stable
GO version: go1.21.9
Built: 2024-05-03T15:52:38+0000
OS/Arch: linux/amd64