Refactor pipeline script

This commit is contained in:
Murtadha 2024-07-27 21:11:20 -04:00
parent c865f926b0
commit 2af2d81115

View file

@ -43,7 +43,7 @@ steps:
- nginx.conf - nginx.conf
- version.txt - version.txt
- name: build-and-deploy - name: deploy
image: appleboy/drone-ssh image: appleboy/drone-ssh
settings: settings:
host: host:
@ -55,20 +55,23 @@ steps:
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 "Building and deploying version: $VERSION" - echo "Nginx configuration:"
- | - cat nginx.conf
cat << EOF > Dockerfile - echo "Contents of dist directory:"
FROM nginx:alpine - ls -la dist
COPY nginx.conf /etc/nginx/nginx.conf # Stop and remove the existing container if it exists
COPY dist /usr/share/nginx/html - docker stop frontend || true
COPY resumes /usr/share/nginx/html/resumes - docker rm frontend || true
EOF # Run the new container with the current version, mounting the files
- docker build -t frontend:$VERSION . - >
- docker stop frontend-$VERSION || true docker run -d --name frontend -p 5173:80
- docker rm frontend-$VERSION || true -v /home/mnisyif/docker-containers/mnisyif/frontend/dist:/usr/share/nginx/html:ro
- docker run -d --name frontend-$VERSION -p 5173:80 frontend:$VERSION -v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro
- echo "Deployment attempt completed" nginx:alpine
# Tag the running container with the version
- docker tag nginx:alpine frontend:$VERSION
- echo "Deployment completed"
- name: confirm-deployment - name: confirm-deployment
image: appleboy/drone-ssh image: appleboy/drone-ssh