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: pipeline:
build: build:
image: node:22 image: node:22
@ -36,24 +40,34 @@ pipeline:
- cd /home/mnisyif/docker-containers/mnisyif/frontend - cd /home/mnisyif/docker-containers/mnisyif/frontend
- VERSION=$(cat version.txt) - VERSION=$(cat version.txt)
# Build the Docker image (no dist or nginx.conf needed in image) # 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 # Stop and remove the existing container if it exists
- echo "Stopping existing Docker container..."
- docker stop frontend || true - docker stop frontend || true
- echo "Removing existing Docker container..."
- docker rm frontend || true - docker rm frontend || true
# Run the new container with bind mounts for dist and nginx.conf # 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 \ - 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/dist:/usr/share/nginx/html \
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf \ -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 # Remove dangling images
- echo "Removing dangling images..."
- docker image prune -f - docker image prune -f
# Clean up unused containers, images, and volumes # Clean up unused containers, images, and volumes
- echo "Cleaning up Docker system..."
- docker system prune -f --volumes - docker system prune -f --volumes
# Remove older versions of the Docker image # Remove older versions of the Docker image
- echo "Removing older Docker images..."
- > - >
for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do for img in $(docker images frontend --format "{{.Tag}}" | grep -v $VERSION); do
docker rmi frontend:$img; docker rmi frontend:$img;
done done
- echo "Deployment completed successfully"
trigger: trigger:
event: event:

View file

@ -3,7 +3,7 @@ server {
location / { location / {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; # index index.html;
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
} }
} }