Used Claude to refactor pipeline code
This commit is contained in:
parent
dc4cca6523
commit
1ded3aaba9
1 changed files with 44 additions and 52 deletions
|
|
@ -6,7 +6,21 @@ pipeline:
|
||||||
- npm run build
|
- npm run build
|
||||||
- echo "VERSION=$(cat version.txt)" > .env
|
- echo "VERSION=$(cat version.txt)" > .env
|
||||||
|
|
||||||
ssh-copy-to-host:
|
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:
|
||||||
|
- rm -rf /home/mnisyif/docker-containers/mnisyif/frontend/*
|
||||||
|
- echo "Target directory cleared"
|
||||||
|
|
||||||
|
copy-to-host:
|
||||||
image: appleboy/drone-scp
|
image: appleboy/drone-scp
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
|
|
@ -23,57 +37,35 @@ pipeline:
|
||||||
- nginx.conf
|
- nginx.conf
|
||||||
- version.txt
|
- version.txt
|
||||||
|
|
||||||
webserver-docker-deploy:
|
webserver-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 "Current directory contents:"
|
# Build the new Docker image with the current version tag
|
||||||
- ls -la
|
- docker build -t frontend:$VERSION .
|
||||||
- echo "Dockerfile contents:"
|
# Stop and remove the existing container if it exists
|
||||||
- cat Dockerfile
|
- docker stop frontend || true
|
||||||
- echo "nginx.conf contents:"
|
- docker rm frontend || true
|
||||||
- cat nginx.conf
|
# Run the new container with the current version
|
||||||
- echo "Checking dist directory:"
|
- docker run -d --name frontend -p 5173:80 frontend:$VERSION
|
||||||
- ls -la dist
|
# Remove dangling images
|
||||||
- echo "Building Docker image..."
|
- docker image prune -f
|
||||||
- docker build --no-cache -t frontend:$VERSION . || { echo "Docker build failed"; exit 1; }
|
# Clean up unused containers, images, and volumes
|
||||||
- echo "Verifying image was created:"
|
- docker system prune -f --volumes
|
||||||
- docker images | grep frontend
|
# Remove older versions of the Docker image
|
||||||
- echo "Stopping existing Docker container..."
|
- >
|
||||||
- docker stop frontend || true
|
for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do
|
||||||
- echo "Removing existing Docker container..."
|
docker rmi frontend:$img;
|
||||||
- docker rm frontend || true
|
done
|
||||||
- echo "Running new Docker container..."
|
|
||||||
- >
|
|
||||||
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/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
||||||
frontend:$VERSION || { echo "Docker run failed"; exit 1; }
|
|
||||||
- echo "Checking container status:"
|
|
||||||
- docker ps -a | grep frontend
|
|
||||||
- echo "Container logs:"
|
|
||||||
- docker logs frontend
|
|
||||||
- echo "Nginx error logs:"
|
|
||||||
- docker exec frontend cat /var/log/nginx/error.log
|
|
||||||
- echo "Nginx access logs:"
|
|
||||||
- docker exec frontend cat /var/log/nginx/access.log
|
|
||||||
- echo "Checking mounted volumes:"
|
|
||||||
- docker inspect -f '{{ .Mounts }}' frontend
|
|
||||||
- echo "Checking Nginx configuration:"
|
|
||||||
- docker exec frontend nginx -T
|
|
||||||
- echo "Checking content of /usr/share/nginx/html:"
|
|
||||||
- docker exec frontend ls -la /usr/share/nginx/html
|
|
||||||
- echo "Deployment completed. Container status:"
|
|
||||||
- docker ps | grep frontend || echo "Container is not running"
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue