Used Claude to refactor pipeline code

This commit is contained in:
Murtadha 2024-07-19 18:03:39 -04:00
parent dc4cca6523
commit 1ded3aaba9

View file

@ -6,7 +6,21 @@ pipeline:
- npm run build - npm run build
- echo "VERSION=$(cat version.txt)" > .env - echo "VERSION=$(cat version.txt)" > .env
ssh-copy-to-host: clear-from-host:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- rm -rf /home/mnisyif/docker-containers/mnisyif/frontend/*
- echo "Target directory cleared"
copy-to-host:
image: appleboy/drone-scp image: appleboy/drone-scp
settings: settings:
host: host:
@ -23,7 +37,7 @@ pipeline:
- nginx.conf - nginx.conf
- version.txt - version.txt
webserver-docker-deploy: webserver-deploy:
image: appleboy/drone-ssh image: appleboy/drone-ssh
settings: settings:
host: host:
@ -36,44 +50,22 @@ pipeline:
script: script:
- cd /home/mnisyif/docker-containers/mnisyif/frontend - cd /home/mnisyif/docker-containers/mnisyif/frontend
- VERSION=$(cat version.txt) - VERSION=$(cat version.txt)
- echo "Current directory contents:" # Build the new Docker image with the current version tag
- ls -la - docker build -t frontend:$VERSION .
- echo "Dockerfile contents:" # Stop and remove the existing container if it exists
- cat Dockerfile
- echo "nginx.conf contents:"
- cat nginx.conf
- echo "Checking dist directory:"
- ls -la dist
- echo "Building Docker image..."
- docker build --no-cache -t frontend:$VERSION . || { echo "Docker build failed"; exit 1; }
- echo "Verifying image was created:"
- docker images | grep frontend
- echo "Stopping existing Docker container..."
- docker stop frontend || true - docker stop frontend || true
- echo "Removing existing Docker container..."
- docker rm frontend || true - docker rm frontend || true
- echo "Running new Docker container..." # Run the new container with the current version
- docker run -d --name frontend -p 5173:80 frontend:$VERSION
# Remove dangling images
- docker image prune -f
# Clean up unused containers, images, and volumes
- docker system prune -f --volumes
# Remove older versions of the Docker image
- > - >
docker run -d --name frontend -p 5173:80 for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do
-v /home/mnisyif/docker-containers/mnisyif/frontend/dist:/usr/share/nginx/html:ro docker rmi frontend:$img;
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro done
frontend:$VERSION || { echo "Docker run failed"; exit 1; }
- echo "Checking container status:"
- docker ps -a | grep frontend
- echo "Container logs:"
- docker logs frontend
- echo "Nginx error logs:"
- docker exec frontend cat /var/log/nginx/error.log
- echo "Nginx access logs:"
- docker exec frontend cat /var/log/nginx/access.log
- echo "Checking mounted volumes:"
- docker inspect -f '{{ .Mounts }}' frontend
- echo "Checking Nginx configuration:"
- docker exec frontend nginx -T
- echo "Checking content of /usr/share/nginx/html:"
- docker exec frontend ls -la /usr/share/nginx/html
- echo "Deployment completed. Container status:"
- docker ps | grep frontend || echo "Container is not running"
trigger: trigger:
event: event: