126 lines
4.2 KiB
YAML
126 lines
4.2 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: build-and-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 "Building and deploying version: $VERSION"
|
|
- |
|
|
cat << EOF > Dockerfile
|
|
FROM nginx:alpine
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
COPY dist /usr/share/nginx/html
|
|
COPY resumes /usr/share/nginx/html/resumes
|
|
EOF
|
|
- docker build -t frontend:$VERSION .
|
|
- docker stop frontend-$VERSION || true
|
|
- docker rm frontend-$VERSION || true
|
|
- docker run -d --name frontend-$VERSION -p 5173:80 frontend:$VERSION
|
|
- echo "Deployment attempt 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:
|
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
|
- VERSION=$(cat version.txt)
|
|
- echo "Confirming deployment for version: $VERSION"
|
|
- docker ps -a
|
|
- if ! docker ps | grep -q frontend-$VERSION; then
|
|
echo "Container failed to start";
|
|
docker logs frontend-$VERSION;
|
|
exit 1;
|
|
fi
|
|
- echo "Container is running, checking Nginx configuration..."
|
|
- docker exec frontend-$VERSION nginx -t || { echo "Nginx configuration test failed"; exit 1; }
|
|
- echo "Listing contents of /usr/share/nginx/html"
|
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html
|
|
- echo "Listing contents of /usr/share/nginx/html/resumes"
|
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html/resumes || echo "Resumes directory not found"
|
|
- echo "Checking HTTP response..."
|
|
- 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
|