docker-compose.yml
stages:
- build
- deploy
image: docker:27.0.3
services:
- name: docker:dind
command: ["--tls=false"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_TLS_CERTDIR: ""
before_script:
- apk update
- apk add --no-cache python3 py3-pip build-base libffi-dev openssl-dev cython curl sshpass
- python3 -m venv /venv
- . /venv/bin/activate
- pip install --upgrade pip
- curl -SL "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker-compose --version
- docker system prune -af
build:
stage: build
script:
- set -e
- docker-compose -f docker-compose.yml build
only:
- main
deploy:
stage: deploy
script:
- |
sshpass -p '@987123Ubuntu' ssh -o StrictHostKeyChecking=no root@165.22.190.198 << 'EOF'
echo "Checking Docker Compose version on remote server..."
if ! command -v docker-compose &> /dev/null
then
echo "docker-compose could not be found, installing..."
curl -SL "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
docker-compose --version
echo "Updating codebase..."
if [ -d /home/username/ubolddashboard/ubolddashboard ]; then
cd /home/username/ubolddashboard/ubolddashboard
git fetch origin
git status
git pull origin main
git log --oneline -n 5
else
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git clone git@gitlab.com:shoaibahmadbhatti6252/ubolddashboard.git /home/username/ubolddashboard/ubolddashboard
fi
echo "Restarting Docker containers..."
cd /home/username/ubolddashboard/ubolddashboard && docker-compose down && docker-compose up -d
echo "Checking Docker Compose logs..."
docker-compose logs
EOF
only:
- main
Here i Also added The staticfiles
DockerFile
See I Also Add the Collect Static Command in
FROM python:3.12.3-slim
# Install system dependencies
RUN apt-get update \
&& apt-get install -y \
gcc \
libc-dev \
make \
libffi-dev \
libssl-dev \
libxml2-dev \
libxslt-dev \
build-essential \
python3-dev \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
# Upgrade pip and install requirements
RUN pip install --upgrade pip \
&& pip install -r requirements.txt \
&& pip install python-dotenv
COPY . .
# Ensure .env file is in the working directory
COPY .env /app/.env
EXPOSE 8000
# Use python-dotenv to load the .env file before running the server
CMD ["sh", "-c", "python manage.py collectstatic --noinput && python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
gitlab-cil.yml
stages:
- build
- deploy
image: docker:27.0.3
services:
- name: docker:dind
command: ["--tls=false"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_TLS_CERTDIR: ""
before_script:
- apk update
- apk add --no-cache python3 py3-pip build-base libffi-dev openssl-dev cython curl sshpass
- python3 -m venv /venv
- . /venv/bin/activate
- pip install --upgrade pip
- curl -SL "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker-compose --version
- docker system prune -af
build:
stage: build
script:
- set -e
- docker-compose -f docker-compose.yml build
only:
- main
deploy:
stage: deploy
script:
- |
sshpass -p '@987123Ubuntu' ssh -o StrictHostKeyChecking=no root@165.22.190.198 << 'EOF'
echo "Checking Docker Compose version on remote server..."
if ! command -v docker-compose &> /dev/null
then
echo "docker-compose could not be found, installing..."
curl -SL "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
docker-compose --version
echo "Updating codebase..."
if [ -d /home/username/ubolddashboard/ubolddashboard ]; then
cd /home/username/ubolddashboard/ubolddashboard
git fetch origin
git status
git pull origin main
git log --oneline -n 5
else
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git clone git@gitlab.com:shoaibahmadbhatti6252/ubolddashboard.git /home/username/ubolddashboard/ubolddashboard
fi
echo "Restarting Docker containers..."
cd /home/username/ubolddashboard/ubolddashboard && docker-compose down && docker-compose up -d
echo "Checking Docker Compose logs..."
docker-compose logs
EOF
only:
- main
settings.py
# STATIC
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR / "staticfiles")
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = "/static/"
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [str(APPS_DIR / "static")]
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
# MEDIA
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR / "media")
# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = "/media/"
I All Did But Same It is Succssfully deployed on vm but not load the static files
Url:
http://165.22.190.198:8000/