diff --git a/.woodpecker.yml b/.woodpecker.yml index 58d03b6..1cb493b 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -6,7 +6,21 @@ pipeline: - npm run build - 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 settings: host: @@ -23,57 +37,35 @@ pipeline: - nginx.conf - version.txt - webserver-docker-deploy: - image: appleboy/drone-ssh - settings: - host: - from_secret: ssh_host - username: - from_secret: ssh_username - key: - from_secret: ssh_key - port: 2332 - script: - - cd /home/mnisyif/docker-containers/mnisyif/frontend - - VERSION=$(cat version.txt) - - echo "Current directory contents:" - - ls -la - - echo "Dockerfile contents:" - - 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 - - echo "Removing existing Docker container..." - - docker rm frontend || true - - echo "Running new Docker container..." - - > - docker run -d --name frontend -p 5173:80 - -v /home/mnisyif/docker-containers/mnisyif/frontend/dist:/usr/share/nginx/html:ro - -v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro - 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" + webserver-deploy: + image: appleboy/drone-ssh + settings: + host: + from_secret: ssh_host + username: + from_secret: ssh_username + key: + from_secret: ssh_key + port: 2332 + script: + - cd /home/mnisyif/docker-containers/mnisyif/frontend + - VERSION=$(cat version.txt) + # Build the new Docker image with the current version tag + - docker build -t frontend:$VERSION . + # Stop and remove the existing container if it exists + - docker stop frontend || true + - docker rm frontend || true + # 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 + - > + for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do + docker rmi frontend:$img; + done trigger: event: