Skip to content

Commit 194d668

Browse files
committed
Docker deploy script (./src/extras/)
1 parent 4b903c1 commit 194d668

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

docker_setup.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ echo "1. Build the Docker image by running the following command:"
8686
echo " sudo docker build -t telegrambot-openai-api ."
8787
echo
8888
echo "2. After building the image, start the bot container using:"
89-
echo " sudo docker run --env-file .env -d telegrambot-openai-api"
89+
echo " sudo docker run --env-file .env --name telegrambot-openai-api -d telegrambot-openai-api"
9090
echo
9191
echo "3. Check the container status with:"
9292
echo " sudo docker ps"
9393
echo
94-
echo "4. Stop the container with:"
94+
echo "4. Check the logs with:"
95+
echo " sudo docker logs telegrambot-openai-api"
96+
echo
97+
echo "5. Stop the container with:"
9598
echo " sudo docker stop <container_id>"
9699
echo
97100
echo "After that, you're all set! Enjoy, and don't forget to start the repository if you like it. :-)"

src/extras/deploy.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
CONTAINER_NAME="telegrambot-openai-api"
4+
IMAGE_NAME="telegrambot-openai-api"
5+
6+
# Function to stop and remove existing container
7+
cleanup() {
8+
echo "Stopping container if it's running..."
9+
sudo docker stop ${CONTAINER_NAME} || true
10+
11+
echo "Removing container if it exists..."
12+
sudo docker rm ${CONTAINER_NAME} || true
13+
}
14+
15+
# Function to build and run the container
16+
deploy() {
17+
echo "Building Docker image..."
18+
sudo docker build --no-cache -t ${IMAGE_NAME} .
19+
if [[ $? -ne 0 ]]; then
20+
echo "Error: Docker image build failed."
21+
exit 1
22+
fi
23+
24+
echo "Running Docker container..."
25+
sudo docker run --env-file .env --name ${CONTAINER_NAME} -d ${IMAGE_NAME}
26+
if [[ $? -ne 0 ]]; then
27+
echo "Error: Failed to run the Docker container."
28+
exit 1
29+
fi
30+
31+
echo "Deployment complete."
32+
}
33+
34+
# Execute the functions
35+
cleanup
36+
deploy

0 commit comments

Comments
 (0)