Skip to content

Commit 7d9d47e

Browse files
authored
Merge pull request #160 from Dogtiti/fix/docker
fix: docker compose
2 parents bbee80b + fcf0dce commit 7d9d47e

File tree

5 files changed

+93
-42
lines changed

5 files changed

+93
-42
lines changed

Dockerfile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ FROM node:19-alpine
44

55
RUN apk update && apk add --no-cache openssl
66

7-
8-
ARG DATABASE_URL
9-
ENV DATABASE_URL=$DATABASE_URL
10-
ARG NEXTAUTH_SECRET=$(openssl rand -base64 32)
11-
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
12-
ARG NEXTAUTH_URL
13-
ENV NEXTAUTH_URL=$NEXTAUTH_URL
14-
ENV NODE_ENV=production
15-
ARG SKIP_ENV_VALIDATION
16-
ENV SKIP_ENV_VALIDATION=$SKIP_ENV_VALIDATION
17-
187
# Set the working directory
198
WORKDIR /app
209

@@ -23,6 +12,12 @@ COPY package*.json ./
2312

2413
# Copy the rest of the application code
2514
COPY . .
15+
COPY entrypoint.sh ./
16+
17+
# Ensure correct line endings after these files are edited by windows
18+
RUN apk add --no-cache dos2unix\
19+
&& dos2unix entrypoint.sh
20+
2621

2722
# Expose the port the app will run on
2823
EXPOSE 3000

docker-compose-local.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ services:
77
autogpt:
88
build:
99
context: .
10-
args:
11-
NEXTAUTH_URL: http://localhost:3000
12-
DATABASE_URL: file:../db/db.sqlite
13-
SKIP_ENV_VALIDATION: 1 # omit this property to enable schema validation for the environment variables
1410
container_name: autogpt
15-
environment:
16-
OPENAI_API_KEY: ${OPENAI_API_KEY} # openai api key
17-
NEXT_PUBLIC_WEB_SEARCH_ENABLED: ${NEXT_PUBLIC_WEB_SEARCH_ENABLED} # enable web search
18-
SERP_API_KEY: ${SERP_API_KEY} # serp api key
19-
NEXT_PUBLIC_GUEST_KEY: ${NEXT_PUBLIC_GUEST_KEY} # guest key
2011
ports:
2112
- 3000:3000
2213
volumes:
2314
- db:/app/db
15+
- .env:/app/.env
2416
restart: unless-stopped

docker-compose.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ services:
77
autogpt:
88
image: dogtititi/autogpt-next-web:latest
99
container_name: autogpt
10-
environment:
11-
OPENAI_API_KEY: ${OPENAI_API_KEY} # openai api key
12-
NEXT_PUBLIC_WEB_SEARCH_ENABLED: ${NEXT_PUBLIC_WEB_SEARCH_ENABLED} # enable web search
13-
SERP_API_KEY: ${SERP_API_KEY} # serp api key
14-
NEXT_PUBLIC_GUEST_KEY: ${NEXT_PUBLIC_GUEST_KEY} # guest key
1510
ports:
1611
- 3000:3000
1712
volumes:
1813
- db:/app/db
14+
- .env:/app/.env
1915
restart: unless-stopped

entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#!/bin/env sh
22

3+
# copy .env file if not exists
4+
[ ! -f .env ] && [ -f .env.example ] && cp .env.example .env
5+
cp .env .env.temp
6+
dos2unix .env.temp
7+
cat .env.temp > .env
8+
rm .env.temp
9+
10+
source .env
11+
312
# change schema.prisma
413
sed -ie 's/mysql/sqlite/g' prisma/schema.prisma
514
sed -ie 's/@db.Text//' prisma/schema.prisma

setup.sh

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,98 @@
11
#!/bin/bash
22
cd "$(dirname "$0")" || exit
33

4+
# Color escape sequences
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
NC='\033[0m' # No Color
8+
9+
# Check if we are running in a terminal that supports colors
10+
if [ -t 1 ]; then
11+
# Use colors
12+
RED=$(printf '\033[31m')
13+
GREEN=$(printf '\033[32m')
14+
NC=$(printf '\033[0m')
15+
fi
16+
17+
# Check if a string matches the "sk-" key pattern
418
is_valid_sk_key() {
519
local api_key=$1
620
local pattern="^sk-[a-zA-Z0-9]{48}$"
721
[[ $api_key =~ $pattern ]] && return 0 || return 1
822
}
923

10-
echo -n "Enter your OpenAI Key (eg: sk...) or press enter to continue with no key: "
11-
read OPENAI_API_KEY
24+
# Set value for NEXT_PUBLIC_WEB_SEARCH_ENABLED
25+
select_web_search_enabled() {
26+
PS3="${GREEN}Do you want to enable web search?${NC} "
27+
options=("true" "false")
28+
select opt in "${options[@]}"; do
29+
case $opt in
30+
"true")
31+
NEXT_PUBLIC_WEB_SEARCH_ENABLED=true
32+
read_variable "${GREEN}Enter your SERP API Key (required):${NC} " "^.+$" "SERP_API_KEY"
33+
break
34+
;;
35+
"false")
36+
NEXT_PUBLIC_WEB_SEARCH_ENABLED=false
37+
break
38+
;;
39+
*) echo "${RED}Please enter a valid option.${NC}" ;;
40+
esac
41+
done
42+
}
43+
44+
# Ask for user input and validate variable values
45+
read_variable() {
46+
local prompt="$1"
47+
local pattern="$2"
48+
local var_name="$3"
49+
local var_val=""
50+
while true; do
51+
read -p "$prompt" var_val
52+
if [[ -z "$var_val" ]]; then
53+
echo -e "${RED}Error: Please enter a valid value for $var_name.${NC}"
54+
elif [[ ! $var_val =~ $pattern ]]; then
55+
echo -e "${RED}Error: Invalid format for $var_name.${NC}"
56+
else
57+
eval "$var_name=$var_val"
58+
echo -e "${GREEN}$var_name set. ✔${NC}"
59+
break
60+
fi
61+
done
62+
}
1263

13-
if is_valid_sk_key $OPENAI_API_KEY || [ -z "$OPENAI_API_KEY" ]; then
14-
echo "Valid API key"
15-
else
16-
echo "Invalid API key. Please ensure that you have billing set up on your OpenAI account"
17-
exit
18-
fi
64+
# Get user input for OPENAI_API_KEY
65+
read_variable "${GREEN}Enter your OpenAI API Key (required):${NC} " "^sk-[a-zA-Z0-9]{48}$" "OPENAI_API_KEY"
1966

20-
echo -n "Enable web search (true/false):"
21-
read NEXT_PUBLIC_WEB_SEARCH_ENABLED
67+
# Get user input for OPENAI_API_KEY
68+
read_variable "${GREEN}Enter your Guest Key (required):${NC} " "^.+$" "NEXT_PUBLIC_GUEST_KEY"
2269

23-
echo -n "Enter your serp api key to use web search :"
24-
read SERP_API_KEY
70+
# Get user input for NEXT_PUBLIC_WEB_SEARCH_ENABLED
71+
select_web_search_enabled
72+
73+
echo -e "${GREEN}All required variables set. ✔${NC}"
2574

2675
NEXTAUTH_SECRET=$(openssl rand -base64 32)
2776

28-
ENV="NODE_ENV=development\n\
29-
NEXTAUTH_SECRET=$NEXTAUTH_SECRET\n\
77+
ENV="NEXTAUTH_SECRET=$NEXTAUTH_SECRET\n\
3078
NEXTAUTH_URL=http://localhost:3000\n\
3179
OPENAI_API_KEY=$OPENAI_API_KEY\n\
3280
DATABASE_URL=file:../db/db.sqlite\n\
81+
NEXT_PUBLIC_GUEST_KEY=$NEXT_PUBLIC_GUEST_KEY\n\
3382
SERP_API_KEY=$SERP_API_KEY\n\
3483
NEXT_PUBLIC_WEB_SEARCH_ENABLED=$NEXT_PUBLIC_WEB_SEARCH_ENABLED\n"
3584

85+
86+
87+
3688
printf $ENV > .env
37-
./prisma/useSqlite.sh
38-
npm install
39-
npm run dev
89+
90+
if [ "$1" = "--docker-compose-local" ]; then
91+
docker-compose -f docker-compose-local.yml up -d --remove-orphans
92+
elif [ "$1" = "--docker-compose" ]; then
93+
docker-compose up -d --remove-orphans
94+
else
95+
./prisma/useSqlite.sh
96+
npm install
97+
npm run dev
98+
fi

0 commit comments

Comments
 (0)