mnisyif_frontend/.woodpecker.yml

76 lines
2.4 KiB
YAML

# kind: pipeline
# type: docker
# name: frontend-deployment
pipeline:
build:
image: node:22
commands:
- npm ci
- npm run build
ssh-copy-to-host:
image: appleboy/drone-scp
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
target: /home/mnisyif/docker-containers/mnisyif/frontend
source:
- dist/
- Dockerfile
- nginx.conf
- version.txt
webserver-docker-deploy:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- cd /home/mnisyif/docker-containers/mnisyif/frontend
- VERSION=$(cat version.txt)
# Build the Docker image (no dist or nginx.conf needed in image)
- echo "Building Docker image..."
- docker build -t frontend:$VERSION . || { echo "Docker build failed"; exit 1; }
- echo "Docker image built successfully: frontend:$VERSION"
# Stop and remove the existing container if it exists
- echo "Stopping existing Docker container..."
- docker stop frontend || true
- echo "Removing existing Docker container..."
- docker rm frontend || true
# Run the new container with bind mounts for dist and nginx.conf
- 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 \
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf \
frontend:$VERSION || { echo "Docker run failed"; exit 1; }
- echo "Docker container is running"
# Remove dangling images
- echo "Removing dangling images..."
- docker image prune -f
# Clean up unused containers, images, and volumes
- echo "Cleaning up Docker system..."
- docker system prune -f --volumes
# Remove older versions of the Docker image
- echo "Removing older Docker images..."
- >
for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do
docker rmi frontend:$img;
done
- echo "Deployment completed successfully"
trigger:
event:
- push
branch:
- master