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:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: node:22
|
image: node:22
|
||||||
commands:
|
commands:
|
||||||
- npm ci
|
- npm ci
|
||||||
|
|
@ -12,6 +15,9 @@ steps:
|
||||||
- echo "VERSION=$(cat version.txt)" > .env
|
- echo "VERSION=$(cat version.txt)" > .env
|
||||||
|
|
||||||
- name: clear-from-host
|
- name: clear-from-host
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -28,6 +34,9 @@ steps:
|
||||||
- echo "Target directory cleared, resumes folder preserved"
|
- echo "Target directory cleared, resumes folder preserved"
|
||||||
|
|
||||||
- name: copy-to-host
|
- name: copy-to-host
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: appleboy/drone-scp
|
image: appleboy/drone-scp
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -43,7 +52,10 @@ steps:
|
||||||
- nginx.conf
|
- nginx.conf
|
||||||
- version.txt
|
- version.txt
|
||||||
|
|
||||||
- name: webserver-deploy
|
- name: build-and-deploy
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -56,16 +68,24 @@ steps:
|
||||||
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 "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 stop frontend-$VERSION || true
|
||||||
- docker rm frontend-$VERSION || true
|
- docker rm frontend-$VERSION || true
|
||||||
- >
|
- docker run -d --name frontend-$VERSION -p 5173:80 frontend:$VERSION
|
||||||
docker run -d --name frontend-$VERSION -p 5173:80
|
- echo "Deployment attempt completed"
|
||||||
--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
|
- name: confirm-deployment
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -76,16 +96,29 @@ steps:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- VERSION=$(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
- docker ps | grep frontend-$VERSION || { echo "Container failed to start"; exit 1; }
|
- VERSION=$(cat version.txt)
|
||||||
- docker logs frontend-$VERSION
|
- echo "Confirming deployment for version: $VERSION"
|
||||||
- docker exec frontend-$VERSION nginx -t
|
- 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
|
||||||
- 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; }
|
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
||||||
- echo "Deployment confirmed successfully"
|
- echo "Deployment confirmed successfully"
|
||||||
|
|
||||||
- name: cleanup
|
- name: cleanup
|
||||||
|
when:
|
||||||
|
- branch: master
|
||||||
|
event: push
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -104,8 +137,8 @@ steps:
|
||||||
done
|
done
|
||||||
- echo "Cleanup completed"
|
- echo "Cleanup completed"
|
||||||
|
|
||||||
trigger:
|
# trigger:
|
||||||
branch:
|
# branch:
|
||||||
- master
|
# - master
|
||||||
event:
|
# event:
|
||||||
- push
|
# - push
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue