AurelioAguirre commited on
Commit
2f48b4a
·
1 Parent(s): de31f51

Updated run.sh again

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -4
  2. run.sh +24 -9
Dockerfile CHANGED
@@ -13,16 +13,15 @@ RUN dnf install -y \
13
  && dnf clean all \
14
  && rm -rf /var/cache/dnf
15
 
16
- # Create application user (using Red Hat standard practices)
17
- RUN useradd -u 1001 -g 0 -M -d /app user && \
18
- mkdir -p /app && \
19
  chown -R 1001:0 /app && \
20
  chmod -R g=u /app
21
 
22
  # Set working directory
23
  WORKDIR /app
24
 
25
- # Switch to non-root user
26
  USER 1001
27
 
28
  # Copy requirements first to leverage Docker cache
 
13
  && dnf clean all \
14
  && rm -rf /var/cache/dnf
15
 
16
+ # Set up application directory
17
+ RUN mkdir -p /app && \
 
18
  chown -R 1001:0 /app && \
19
  chmod -R g=u /app
20
 
21
  # Set working directory
22
  WORKDIR /app
23
 
24
+ # Switch to non-root user (default in UBI image)
25
  USER 1001
26
 
27
  # Copy requirements first to leverage Docker cache
run.sh CHANGED
@@ -1,5 +1,7 @@
1
  #!/bin/bash
2
 
 
 
3
  # Default values
4
  PORT=7860
5
  ENV_FILE=".env"
@@ -18,6 +20,12 @@ usage() {
18
  exit 1
19
  }
20
 
 
 
 
 
 
 
21
  # Parse command line arguments
22
  while getopts "p:e:n:bh" opt; do
23
  case $opt in
@@ -50,8 +58,7 @@ fi
50
 
51
  # Check if docker is installed
52
  if ! command -v docker &> /dev/null; then
53
- echo "Error: docker is not installed"
54
- exit 1
55
  fi
56
 
57
  # Check if .env file exists
@@ -66,7 +73,7 @@ fi
66
 
67
  # Build the Docker image
68
  echo "Building Docker image..."
69
- docker build $PLATFORM_ARG -t $CONTAINER_NAME .
70
 
71
  # Exit if build only
72
  if [ "$BUILD_ONLY" = true ]; then
@@ -77,23 +84,31 @@ fi
77
  # Check if container is already running
78
  if docker ps -q -f name=$CONTAINER_NAME | grep -q .; then
79
  echo "Stopping existing container..."
80
- docker stop $CONTAINER_NAME
81
  fi
82
 
83
  # Remove existing container
84
  if docker ps -aq -f name=$CONTAINER_NAME | grep -q .; then
85
  echo "Removing existing container..."
86
- docker rm $CONTAINER_NAME
87
  fi
88
 
89
  # Run the container
90
  echo "Starting container on port $PORT..."
91
- docker run -d \
92
  --name $CONTAINER_NAME \
93
  --env-file $ENV_FILE \
94
  -p $PORT:7860 \
95
  -v $HOME/.cache/huggingface:/app/.cache/huggingface \
96
- $CONTAINER_NAME
 
 
 
 
 
 
 
97
 
98
- echo "Container started! API should be available at http://localhost:$PORT"
99
- echo "To view logs, run: docker logs -f $CONTAINER_NAME"
 
 
1
  #!/bin/bash
2
 
3
+ set -e # Exit on error
4
+
5
  # Default values
6
  PORT=7860
7
  ENV_FILE=".env"
 
20
  exit 1
21
  }
22
 
23
+ # Function to handle errors
24
+ handle_error() {
25
+ echo "Error: $1"
26
+ exit 1
27
+ }
28
+
29
  # Parse command line arguments
30
  while getopts "p:e:n:bh" opt; do
31
  case $opt in
 
58
 
59
  # Check if docker is installed
60
  if ! command -v docker &> /dev/null; then
61
+ handle_error "Docker is not installed"
 
62
  fi
63
 
64
  # Check if .env file exists
 
73
 
74
  # Build the Docker image
75
  echo "Building Docker image..."
76
+ docker build $PLATFORM_ARG -t $CONTAINER_NAME . || handle_error "Failed to build Docker image"
77
 
78
  # Exit if build only
79
  if [ "$BUILD_ONLY" = true ]; then
 
84
  # Check if container is already running
85
  if docker ps -q -f name=$CONTAINER_NAME | grep -q .; then
86
  echo "Stopping existing container..."
87
+ docker stop $CONTAINER_NAME || handle_error "Failed to stop existing container"
88
  fi
89
 
90
  # Remove existing container
91
  if docker ps -aq -f name=$CONTAINER_NAME | grep -q .; then
92
  echo "Removing existing container..."
93
+ docker rm $CONTAINER_NAME || handle_error "Failed to remove existing container"
94
  fi
95
 
96
  # Run the container
97
  echo "Starting container on port $PORT..."
98
+ if ! docker run -d \
99
  --name $CONTAINER_NAME \
100
  --env-file $ENV_FILE \
101
  -p $PORT:7860 \
102
  -v $HOME/.cache/huggingface:/app/.cache/huggingface \
103
+ $CONTAINER_NAME; then
104
+ handle_error "Failed to start container"
105
+ fi
106
+
107
+ # Verify container is running
108
+ if ! docker ps | grep -q $CONTAINER_NAME; then
109
+ handle_error "Container failed to start. Check logs with: docker logs $CONTAINER_NAME"
110
+ fi
111
 
112
+ echo "Container started successfully!"
113
+ echo "API should be available at http://localhost:$PORT"
114
+ echo "To view logs, run: docker logs -f $CONTAINER_NAME"