111 lines
3.5 KiB
YAML
111 lines
3.5 KiB
YAML
---
|
|
# kind: pipeline
|
|
# type: docker
|
|
# name: default
|
|
|
|
steps:
|
|
- name: build
|
|
image: node:22
|
|
commands:
|
|
- npm ci
|
|
- npm run build
|
|
- echo "VERSION=$(cat version.txt)" > .env
|
|
|
|
- name: 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:
|
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
|
- rm -rf data index-*.js index-*.css logos papers pp projects
|
|
- find . -maxdepth 1 -type f -delete
|
|
- echo "Target directory cleared, resumes folder preserved"
|
|
|
|
- name: 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
|
|
|
|
- name: 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)
|
|
- docker stop frontend-$VERSION || true
|
|
- docker rm frontend-$VERSION || true
|
|
- >
|
|
docker run -d --name frontend-$VERSION -p 5173:80
|
|
--mount type=bind,source=$PWD,target=/usr/share/nginx/html,readonly
|
|
-v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
nginx:alpine
|
|
- echo "Deployment completed"
|
|
|
|
- name: 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:
|
|
- VERSION=$(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)
|
|
- docker ps | grep frontend-$VERSION || { echo "Container failed to start"; exit 1; }
|
|
- docker logs frontend-$VERSION
|
|
- docker exec frontend-$VERSION nginx -t
|
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html
|
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html/resumes
|
|
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
|
- echo "Deployment confirmed successfully"
|
|
|
|
- name: 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..."
|
|
- docker system prune -f --volumes
|
|
- >
|
|
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:
|
|
branch:
|
|
- master
|
|
event:
|
|
- push
|