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" 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 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) # 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 # Verify the container is running - docker ps | grep frontend || echo "Container failed to start" # Display container logs - docker logs frontend # Clean up unused containers, images, and volumes - docker system prune -f --volumes # Tag the running container with the version - docker tag nginx:alpine frontend:$VERSION # Remove older versions of the Docker image - > for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do docker rmi frontend:$img || true; done - echo "Deployment completed" trigger: event: - push branch: - master