update bug fix

This commit is contained in:
2025-02-10 15:27:39 +01:00
parent 18e2268e0e
commit 82953ea1b3
2 changed files with 25 additions and 17 deletions

View File

@@ -39,25 +39,28 @@ jobs:
IMAGE_NAME="my-nextjs-app:$DEPLOY_ENV" IMAGE_NAME="my-nextjs-app:$DEPLOY_ENV"
NEW_CONTAINER_NAME="$CONTAINER_NAME-new" NEW_CONTAINER_NAME="$CONTAINER_NAME-new"
# Pull latest image version if exists # Prüft, ob der alte Container existiert und entfernt ihn
docker pull $IMAGE_NAME || true if [ $(docker ps -aq -f name=$NEW_CONTAINER_NAME) ]; then
echo "Removing existing new container ($NEW_CONTAINER_NAME)..."
docker rm -f "$NEW_CONTAINER_NAME" || true
fi
# Run new container on a different port # Führt den neuen Container auf einem temporären internen Port aus
docker run -d --name "$NEW_CONTAINER_NAME" -p 30000:3000 $IMAGE_NAME docker run -d --name "$NEW_CONTAINER_NAME" -p 30000:3000 $IMAGE_NAME
# Wait to ensure the new container is up and running # Warten, um sicherzustellen, dass der neue Container läuft
sleep 10 sleep 10
# Check if new container is healthy and running # Prüfen, ob der neue Container erfolgreich läuft
if [ $(docker inspect --format='{{.State.Running}}' $NEW_CONTAINER_NAME) == "true" ]; then if [ $(docker inspect --format='{{.State.Running}}' $NEW_CONTAINER_NAME) == "true" ]; then
# Stop and remove the old container # Stoppt und entfernt den alten Container, falls vorhanden
if [ $(docker ps -aq -f name=$CONTAINER_NAME) ]; then
docker stop "$CONTAINER_NAME" || true docker stop "$CONTAINER_NAME" || true
docker rm "$CONTAINER_NAME" || true docker rm "$CONTAINER_NAME" || true
fi
# Rename new container to the old containers name # Benennt den neuen Container zum alten Namen um und weist den gewünschten Port zu
docker rename "$NEW_CONTAINER_NAME" "$CONTAINER_NAME" docker rename "$NEW_CONTAINER_NAME" "$CONTAINER_NAME"
# Reassign the desired port (e.g., 3000 for production branch) to the new container
docker run -d --name "$CONTAINER_NAME" -p $PORT:3000 $IMAGE_NAME docker run -d --name "$CONTAINER_NAME" -p $PORT:3000 $IMAGE_NAME
else else
echo "New container failed to start." echo "New container failed to start."

View File

@@ -1,21 +1,26 @@
# Use Node.js LTS image as the base
FROM node:current-alpine FROM node:current-alpine
# Set working directory
WORKDIR /app WORKDIR /app
# npm Cache reinigen, npm aktualisieren und danach die Abhängigkeiten installieren # Copy package.json and package-lock.json
RUN npm cache clean --force
RUN npm install -g npm@latest
COPY package*.json ./ COPY package*.json ./
RUN npm install --loglevel verbose || npm install --force # Install dependencies
RUN npm install
# Copy the application code
COPY . . COPY . .
# Build the Next.js application
RUN npm run build RUN npm run build
# Set environmental variable for production mode
ENV NODE_ENV=production ENV NODE_ENV=production
# Expose the port the app runs on
EXPOSE 3000 EXPOSE 3000
# Run the app with the start script
CMD ["npm", "start"] CMD ["npm", "start"]