diff --git a/.woodpecker.yml b/.woodpecker.yml index 460a2ce..5856f83 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,120 +1,119 @@ pipeline: - build: - image: node:22 - commands: - - npm ci - - npm run build - - echo "VERSION=$(cat version.txt)" > .env - - 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" + build: + image: node:22 + commands: + - npm ci + - npm run build + - echo "VERSION=$(cat version.txt)" > .env - copy-to-host: - image: appleboy/drone-scp - settings: - host: - from_secret: ssh_host - username: - from_secret: ssh_username - key: - from_secret: ssh_key - port: 2332 - target: /home/mnisyif/docker-containers/mnisyif/frontend - source: - - dist/ - - nginx.conf - - version.txt + 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" - 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) - - echo "Nginx configuration:" - - cat nginx.conf - - echo "Contents of dist directory:" - - ls -la dist - # 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, mounting the files - - > - 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 - nginx:alpine - # Tag the running container with the version - - docker tag nginx:alpine frontend:$VERSION - - echo "Deployment completed" + copy-to-host: + image: appleboy/drone-scp + settings: + host: + from_secret: ssh_host + username: + from_secret: ssh_username + key: + from_secret: ssh_key + port: 2332 + target: /home/mnisyif/docker-containers/mnisyif/frontend + source: + - dist/ + - nginx.conf + - version.txt - confirm-deployment: - image: appleboy/drone-ssh - settings: - host: - from_secret: ssh_host - username: - from_secret: ssh_username - key: - from_secret: ssh_key - port: 2332 - script: - - echo "Verifying deployment..." - # Verify the container is running - - docker ps | grep frontend || { echo "Container failed to start"; exit 1; } - # Display container logs - - docker logs frontend - # Test Nginx configuration - - docker exec frontend nginx -t - # Check Nginx process - - docker exec frontend ps aux | grep nginx - # Check contents of /usr/share/nginx/html in the container - - docker exec frontend ls -la /usr/share/nginx/html - # Perform a simple HTTP request to check if the server is responding - - curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; } - - echo "Deployment confirmed successfully" + 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) + - echo "Nginx configuration:" + - cat nginx.conf + - echo "Contents of dist directory:" + - ls -la dist + # 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, mounting the files + - > + 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 + nginx:alpine + # Tag the running container with the version + - docker tag nginx:alpine frontend:$VERSION + - echo "Deployment completed" - cleanup: - image: appleboy/drone-ssh - settings: - host: - from_secret: ssh_host - username: - from_secret: ssh_username - key: - from_secret: ssh_key - port: 2332 - script: - - echo "Performing cleanup..." - # 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 $(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)); do - docker rmi frontend:$img || true; - done - - echo "Cleanup completed" + confirm-deployment: + image: appleboy/drone-ssh + settings: + host: + from_secret: ssh_host + username: + from_secret: ssh_username + key: + from_secret: ssh_key + port: 2332 + script: + - echo "Verifying deployment..." + # Verify the container is running + - docker ps | grep frontend || { echo "Container failed to start"; exit 1; } + # Display container logs and test nginx configuration + - docker logs frontend + - docker exec frontend nginx -t + - docker exec frontend ps aux | grep nginx + + # Check contents of /usr/share/nginx/html in the container + - docker exec frontend ls -la /usr/share/nginx/html + # Perform a simple HTTP request to check if the server is responding + - curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; } + - echo "Deployment confirmed successfully" + + cleanup: + image: appleboy/drone-ssh + settings: + host: + from_secret: ssh_host + username: + from_secret: ssh_username + key: + from_secret: ssh_key + port: 2332 + script: + - echo "Performing cleanup..." + # 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 $(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)); do + docker rmi frontend:$img || true; + done + - echo "Cleanup completed" trigger: - event: - - push - branch: - - master \ No newline at end of file + event: + - push + branch: + - master