New from Gemini
This commit is contained in:
@@ -1,52 +1,58 @@
|
||||
kind: pipeline
|
||||
type: docker # Essential for Docker execution
|
||||
type: docker # All steps will run in Docker containers.
|
||||
|
||||
name: restart-discord-bot
|
||||
name: update-and-restart-discord-bot # A descriptive name for the pipeline.
|
||||
|
||||
when:
|
||||
- branch: main
|
||||
- branch: main # This pipeline triggers on pushes to the 'main' branch.
|
||||
event: push
|
||||
|
||||
steps:
|
||||
# - name: debug-compose-environment # A new step for diagnostics
|
||||
# image: docker
|
||||
# volumes:
|
||||
# - /var/run/docker.sock:/var/run/docker.sock
|
||||
# - /home/gary/Discord/Acrybot:/app
|
||||
# commands:
|
||||
# - echo "--- Checking environment within pipeline container ---"
|
||||
# - pwd # Should be /
|
||||
# - cd /app
|
||||
# - pwd # Should be /app
|
||||
# - echo "Contents of /app (your mounted Docker Compose directory):"
|
||||
# - ls -la # Verify docker-compose.yml is here
|
||||
# - echo "--- Displaying content of docker-compose.yml (for verification) ---"
|
||||
# - cat docker-compose.yml # Display the content of the Compose file
|
||||
# - echo "Docker CLI Version:"
|
||||
# - docker --version
|
||||
# - echo "Docker Compose CLI Version:"
|
||||
# - docker compose version
|
||||
# - echo "--- Listing Docker Compose services (running and stopped) in this project context ---"
|
||||
# # This command lists all services (running and stopped) that docker compose finds in /app
|
||||
# - docker compose ps -a
|
||||
# # IMPORTANT: If 'docker compose ps -a' shows an empty list or doesn't list your service,
|
||||
# # it means Docker Compose isn't managing the running bot service from this specific
|
||||
# # docker-compose.yml file.
|
||||
# - echo "--- Listing ALL Docker containers on the host (regardless of Compose project) ---"
|
||||
# - docker ps -a # This lists ALL containers, including those not managed by Compose.
|
||||
# - echo "--- Attempting to restart the specific bot service ---"
|
||||
|
||||
- name: restart-bot
|
||||
image: docker # Image with Docker Compose
|
||||
- name: pull-latest-source # Step 1: Pull the latest code from Gitea.
|
||||
image: alpine/git # A lightweight image that includes the 'git' command.
|
||||
volumes:
|
||||
# Using the short syntax to reference globally defined named volumes
|
||||
- /var/run/docker.sock:/var/run/docker.sock # Maps named volume 'docker_sock' to container path
|
||||
- /home/gary/Discord/Acrybot:/app # Maps named volume 'docker_compose_dir' to container path
|
||||
# Mount your bot's source code directory with read-write permissions.
|
||||
# This is crucial for 'git pull' to update the files on your host machine.
|
||||
- /home/gary/Discord/Acrybot:/app:rw # ':rw' ensures read-write access.
|
||||
commands:
|
||||
- cd /app
|
||||
- echo "--- Pulling latest source code from Git ---"
|
||||
- cd /app # Navigate to the mounted project directory.
|
||||
# Configure Git to trust the mounted directory to avoid 'unsafe repository' warnings.
|
||||
- git config --global --add safe.directory /app
|
||||
- docker compose down
|
||||
- docker ps
|
||||
- git pull
|
||||
- docker compose up -d
|
||||
- docker ps
|
||||
- git pull # Pull the latest changes from the 'main' branch.
|
||||
- echo "Source code updated."
|
||||
- ls -la /app # Verify files were updated.
|
||||
|
||||
- name: manage-bot-containers # Step 2: Manage your bot's Docker containers.
|
||||
image: docker # This image provides the 'docker compose' CLI.
|
||||
volumes:
|
||||
# Mount the Docker socket from the host to allow control over host Docker daemon.
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
# Mount your Docker Compose project directory into the container.
|
||||
- /home/gary/Discord/Acrybot:/app
|
||||
environment:
|
||||
# IMPORTANT: Explicitly set the Docker Compose project name.
|
||||
# This ensures containers are managed with the 'Acrybot' prefix,
|
||||
# matching your existing containers.
|
||||
# If your actual project name (from 'docker inspect <container_id>')
|
||||
# is different, replace 'Acrybot' here.
|
||||
- COMPOSE_PROJECT_NAME=Acrybot
|
||||
commands:
|
||||
- echo "--- Managing Docker Compose services ---"
|
||||
- cd /app # Navigate to the mounted project directory.
|
||||
|
||||
# Stop the specific Discord bot service.
|
||||
# Replace 'your_bot_service_name' with the EXACT service name from your docker-compose.yml.
|
||||
- echo "--- Stopping Discord bot service your_bot_service_name ---"
|
||||
- docker compose stop python-app
|
||||
|
||||
# Bring the specific Discord bot service back up.
|
||||
# '--build' is essential if your docker-compose.yml uses 'build: .' to create the image,
|
||||
# as it ensures the image is rebuilt with the newly pulled source code.
|
||||
- echo "--- Bringing Discord bot service up your_bot_service_name ---"
|
||||
- docker compose up -d your_bot_service_name --build
|
||||
|
||||
- echo "--- Verification after actions ---"
|
||||
- docker compose ps -a # Show all services in this project again.
|
||||
# Directly grep for the expected container name to confirm.
|
||||
- docker ps -a | grep Acrybot-python-app
|
||||
|
||||
Reference in New Issue
Block a user