Attempt to fix webserver deployment

This commit is contained in:
Murtadha 2024-07-19 17:39:15 -04:00
parent 7777d290b2
commit c4bf00050d
2 changed files with 18 additions and 4 deletions

View file

@ -1,3 +1,7 @@
# kind: pipeline
# type: docker
# name: frontend-deployment
pipeline:
build:
image: node:22
@ -36,27 +40,37 @@ pipeline:
- cd /home/mnisyif/docker-containers/mnisyif/frontend
- VERSION=$(cat version.txt)
# Build the Docker image (no dist or nginx.conf needed in image)
- docker build -t frontend:$VERSION .
- 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
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
- master