Refactor pipeline script
This commit is contained in:
parent
be6c34cb53
commit
3daf036a89
1 changed files with 50 additions and 17 deletions
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
steps:
|
||||
- name: build
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: node:22
|
||||
commands:
|
||||
- npm ci
|
||||
|
|
@ -12,6 +15,9 @@ steps:
|
|||
- echo "VERSION=$(cat version.txt)" > .env
|
||||
|
||||
- name: clear-from-host
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
|
|
@ -28,6 +34,9 @@ steps:
|
|||
- echo "Target directory cleared, resumes folder preserved"
|
||||
|
||||
- name: copy-to-host
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
|
|
@ -43,7 +52,10 @@ steps:
|
|||
- nginx.conf
|
||||
- version.txt
|
||||
|
||||
- name: webserver-deploy
|
||||
- name: build-and-deploy
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
|
|
@ -56,16 +68,24 @@ steps:
|
|||
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
|
||||
--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"
|
||||
- docker run -d --name frontend-$VERSION -p 5173:80 frontend:$VERSION
|
||||
- echo "Deployment attempt completed"
|
||||
|
||||
- name: confirm-deployment
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
|
|
@ -76,16 +96,29 @@ steps:
|
|||
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
|
||||
- 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
|
||||
- docker exec frontend-$VERSION ls -la /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"
|
||||
- echo "Checking HTTP response..."
|
||||
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
||||
- echo "Deployment confirmed successfully"
|
||||
|
||||
- name: cleanup
|
||||
when:
|
||||
- branch: master
|
||||
event: push
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
|
|
@ -104,8 +137,8 @@ steps:
|
|||
done
|
||||
- echo "Cleanup completed"
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
# trigger:
|
||||
# branch:
|
||||
# - master
|
||||
# event:
|
||||
# - push
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue