Commit 6dfb830c authored by Benavides Ontiveros's avatar Benavides Ontiveros
Browse files

modify .gitlab yaml

parent 05a16de4
Pipeline #12166 canceled with stages
...@@ -9,26 +9,30 @@ variables: ...@@ -9,26 +9,30 @@ variables:
DOCKER_REGISTRY: "docker.io" DOCKER_REGISTRY: "docker.io"
DOCKERHUB_REPO: "$DOCKER_USERNAME/reddit_data_fetcher" DOCKERHUB_REPO: "$DOCKER_USERNAME/reddit_data_fetcher"
# ----------------- Base Template ----------------- # ----------------- Base Template for Docker Executor -----------------
.build_template: .build_template:
tags: ["ubuntu", "vm"] tags: ["ubuntu", "vm"] # Your runner tags
image: docker:24.0.9 image: docker:24.0.9 # Main job container containing Docker CLI
services:
- docker:dind # Docker daemon for building images
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: "" # Needed to disable TLS for DIND
before_script: before_script:
- echo "Docker CLI info:" - echo "=== Docker info (from DinD service) ==="
- docker version - docker info || true
# ----------------- Lint Stage ----------------- # ----------------- Lint Stage -----------------
# This does not need Docker; run it with a Python image.
lint: lint:
stage: lint stage: lint
image: python:3.10 image: python:3.10
extends: .build_template script:
before_script:
- pip install flake8 - pip install flake8
script: | - echo "Linting Python code..."
echo "Linting Python code..." - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - echo "Done running Python lint stage"
echo "Done running Python lint stage"
rules: rules:
- if: '$CI_COMMIT_BRANCH' - if: '$CI_COMMIT_BRANCH'
when: always when: always
...@@ -38,7 +42,7 @@ diag: ...@@ -38,7 +42,7 @@ diag:
stage: diag stage: diag
extends: .build_template extends: .build_template
script: | script: |
echo "Check Docker socket and info..." echo "=== Checking Docker connectivity ==="
ls -l /var/run || true ls -l /var/run || true
stat /var/run/docker.sock || true stat /var/run/docker.sock || true
docker version || true docker version || true
...@@ -51,16 +55,17 @@ diag: ...@@ -51,16 +55,17 @@ diag:
build: build:
stage: build stage: build
extends: .build_template extends: .build_template
before_script:
- echo "Logging in to Docker registry..."
- echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin
script: | script: |
echo "Logging in to Docker registry..."
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin
echo "Building Docker image for commit: ${CI_COMMIT_SHORT_SHA}" echo "Building Docker image for commit: ${CI_COMMIT_SHORT_SHA}"
docker build \ docker build \
--build-arg REDDIT_CLIENT_ID="$REDDIT_CLIENT_ID" \ --build-arg REDDIT_CLIENT_ID="$REDDIT_CLIENT_ID" \
--build-arg REDDIT_CLIENT_SECRET="$REDDIT_CLIENT_SECRET" \ --build-arg REDDIT_CLIENT_SECRET="$REDDIT_CLIENT_SECRET" \
-t $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA . -t $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA .
echo "Docker image built successfully!"
echo "Docker image built successfully."
rules: rules:
- if: '$CI_COMMIT_BRANCH' - if: '$CI_COMMIT_BRANCH'
when: always when: always
...@@ -72,14 +77,17 @@ deploy: ...@@ -72,14 +77,17 @@ deploy:
script: | script: |
echo "Logging in to Docker registry..." echo "Logging in to Docker registry..."
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin
echo "Pushing Docker image to Docker Hub..."
echo "Pushing Docker image..."
docker push $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA docker push $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA
# Optional: push latest tag if on default branch
if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then
echo "Tagging as 'latest'..."
docker tag $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA $DOCKERHUB_REPO:latest docker tag $DOCKERHUB_REPO:$CI_COMMIT_SHORT_SHA $DOCKERHUB_REPO:latest
docker push $DOCKERHUB_REPO:latest docker push $DOCKERHUB_REPO:latest
fi fi
echo "Deploy completed."
rules: rules:
- if: '$CI_COMMIT_BRANCH' - if: '$CI_COMMIT_BRANCH'
when: always when: always
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment