After setting up a CI/CD pipeline using GitLab, Harbor, and Rancher, I identified an issue with the deployment of my application where it didn’t function properly.
However, when deploying manually (building the image on my local machine, pushing it manually to Harbor, and applying it to the Rancher deployment), the application works perfectly. One thing I noticed is that the image in question has different sizes when I push it locally versus when it’s built and sent through the pipeline. Through the pipeline, it’s always smaller. This leads me to believe there might be some kind of caching issue.
Pipeline:
variables:
HARBOR_URL: "harbor.domain"
PROJECT_NAME: "ciencia_de_dados/cde"
KUBECONFIG: "${KUBECONFIG}"
stages:
- prepare
- build
- push
- deploy
prepare_kubeconfig:
stage: prepare
image: bitnami/minideb:latest
tags:
- docker
- rancher
script:
- apt-get update && apt-get install -y curl
- echo "$KUBECONFIG" | base64 -d > temp_kubeconfig
.build_and_push_before_script: &build_and_push_before_script
- echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USER" --password-stdin "$HARBOR_URL"
build_image:
stage: build
image: docker:latest
tags:
- docker
- rancher
before_script:
*build_and_push_before_script
script:
- ls -R
- docker build --no-cache -t "$HARBOR_URL/$PROJECT_NAME:latest" -f Dockerfile .
only:
- develop
push_image:
stage: push
image: docker:latest
tags:
- docker
before_script:
*build_and_push_before_script
script:
- docker push "$HARBOR_URL/$PROJECT_NAME:latest"
only:
- develop
deploy_to_rancher:
stage: deploy
image: bitnami/minideb:latest
tags:
- rancher
before_script:
- apt-get update && apt-get install -y curl
- curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- echo "$KUBECONFIG" | base64 -d > temp_kubeconfig
script:
- curl -v -k "https://rancherhml.domain:443/k8s/clusters/c-m-cn8gmtcs/version"
- KUBECONFIG=temp_kubeconfig kubectl create namespace cde --dry-run=client -o yaml | KUBECONFIG=temp_kubeconfig kubectl apply -f -
- KUBECONFIG=temp_kubeconfig kubectl apply -f deployment.yaml --validate=false
only:
- develop
Dockerfile
:
FROM python:3.9.19-bullseye
RUN apt-get update && \
apt-get install -y libaio1 && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app/cde
COPY requirements.txt .
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --no-cache-dir --upgrade pip && \
pip install --trusted-host pypi.org --trusted-host pypi.pythonhosted.org --trusted-host files.pythonhosted.org -r requirements.txt
COPY instantclient_21_12 /opt/oracle/instantclient_21_12
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_21_12
ENV TNS_ADMIN=/opt/oracle/instantclient_21_12/network/admin
COPY . .
EXPOSE 8000
CMD ["bash", "-c", "python manage.py runserver 0.0.0.0:8000"]
I checked the .dockerignore
file to ensure there was nothing in my repository that could cause build failures. I reviewed the Dockerfile
and validated its configurations. I added the --no-cache
flag to the build image step. I also included a no-cache step in the runner that executes this job. Additionally, I checked for configuration and authentication issues with Harbor.