Refactor pipeline script
This commit is contained in:
parent
2af2d81115
commit
5fabaa88e8
1 changed files with 98 additions and 101 deletions
199
.woodpecker.yml
199
.woodpecker.yml
|
|
@ -1,33 +1,30 @@
|
||||||
---
|
---
|
||||||
# kind: pipeline
|
|
||||||
# type: docker
|
|
||||||
# name: default
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
build:
|
||||||
image: node:22
|
image: node:22
|
||||||
commands:
|
commands:
|
||||||
- npm ci
|
- npm ci
|
||||||
- npm run build
|
- npm run build
|
||||||
- echo "VERSION=$(cat version.txt)" > .env
|
- echo "VERSION=$(cat version.txt)" > .env
|
||||||
|
|
||||||
- name: clear-from-host
|
clear-from-host:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
- rm -rf data index-*.js index-*.css logos papers pp projects
|
- rm -rf data index-*.js index-*.css logos papers pp projects
|
||||||
- find . -maxdepth 1 -type f -delete
|
- find . -maxdepth 1 -type f -delete
|
||||||
- echo "Target directory cleared, resumes folder preserved"
|
- echo "Target directory cleared, resumes folder preserved"
|
||||||
|
|
||||||
- name: copy-to-host
|
copy-to-host:
|
||||||
image: appleboy/drone-scp
|
image: appleboy/drone-scp
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -43,84 +40,84 @@ steps:
|
||||||
- nginx.conf
|
- nginx.conf
|
||||||
- version.txt
|
- version.txt
|
||||||
|
|
||||||
- name: deploy
|
deploy:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
- VERSION=$(cat version.txt)
|
- VERSION=$(cat version.txt)
|
||||||
- echo "Nginx configuration:"
|
- echo "Nginx configuration:"
|
||||||
- cat nginx.conf
|
- cat nginx.conf
|
||||||
- echo "Contents of dist directory:"
|
- echo "Contents of dist directory:"
|
||||||
- ls -la dist
|
- ls -la dist
|
||||||
# Stop and remove the existing container if it exists
|
# Stop and remove the existing container if it exists
|
||||||
- docker stop frontend || true
|
- docker stop frontend || true
|
||||||
- docker rm frontend || true
|
- docker rm frontend || true
|
||||||
# Run the new container with the current version, mounting the files
|
# Run the new container with the current version, mounting the files
|
||||||
- >
|
- >
|
||||||
docker run -d --name frontend -p 5173:80
|
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/dist:/usr/share/nginx/html:ro
|
||||||
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro
|
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||||
nginx:alpine
|
nginx:alpine
|
||||||
# Tag the running container with the version
|
# Tag the running container with the version
|
||||||
- docker tag nginx:alpine frontend:$VERSION
|
- docker tag nginx:alpine frontend:$VERSION
|
||||||
- echo "Deployment completed"
|
- echo "Deployment completed"
|
||||||
|
|
||||||
- name: confirm-deployment
|
confirm-deployment:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
- VERSION=$(cat version.txt)
|
- VERSION=$(cat version.txt)
|
||||||
- echo "Confirming deployment for version: $VERSION"
|
- echo "Confirming deployment for version: $VERSION"
|
||||||
- docker ps -a
|
- docker ps -a
|
||||||
- if ! docker ps | grep -q frontend-$VERSION; then
|
- if ! docker ps | grep -q frontend-$VERSION; then
|
||||||
echo "Container failed to start";
|
echo "Container failed to start";
|
||||||
docker logs frontend-$VERSION;
|
docker logs frontend-$VERSION;
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
- echo "Container is running, checking Nginx configuration..."
|
- echo "Container is running, checking Nginx configuration..."
|
||||||
- docker exec frontend-$VERSION nginx -t || { echo "Nginx configuration test failed"; exit 1; }
|
- docker exec frontend-$VERSION nginx -t || { echo "Nginx configuration test failed"; exit 1; }
|
||||||
- echo "Listing contents of /usr/share/nginx/html"
|
- echo "Listing contents of /usr/share/nginx/html"
|
||||||
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html
|
||||||
- echo "Listing contents of /usr/share/nginx/html/resumes"
|
- 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"
|
- docker exec frontend-$VERSION ls -la /usr/share/nginx/html/resumes || echo "Resumes directory not found"
|
||||||
- echo "Checking HTTP response..."
|
- echo "Checking HTTP response..."
|
||||||
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
||||||
- echo "Deployment confirmed successfully"
|
- echo "Deployment confirmed successfully"
|
||||||
|
|
||||||
- name: cleanup
|
cleanup:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- echo "Performing cleanup..."
|
- echo "Performing cleanup..."
|
||||||
- docker system prune -f --volumes
|
- 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
|
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;
|
docker rmi frontend:$img || true;
|
||||||
done
|
done
|
||||||
- echo "Cleanup completed"
|
- echo "Cleanup completed"
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue