Skip to content

Commit

Permalink
Merge pull request #160 from Dogtiti/fix/docker
Browse files Browse the repository at this point in the history
fix: docker compose
  • Loading branch information
Dogtiti authored May 15, 2023
2 parents bbee80b + fcf0dce commit 7d9d47e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 42 deletions.
17 changes: 6 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ FROM node:19-alpine

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


ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NEXTAUTH_SECRET=$(openssl rand -base64 32)
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
ARG NEXTAUTH_URL
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV NODE_ENV=production
ARG SKIP_ENV_VALIDATION
ENV SKIP_ENV_VALIDATION=$SKIP_ENV_VALIDATION

# Set the working directory
WORKDIR /app

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

# Copy the rest of the application code
COPY . .
COPY entrypoint.sh ./

# Ensure correct line endings after these files are edited by windows
RUN apk add --no-cache dos2unix\
&& dos2unix entrypoint.sh


# Expose the port the app will run on
EXPOSE 3000
Expand Down
10 changes: 1 addition & 9 deletions docker-compose-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ services:
autogpt:
build:
context: .
args:
NEXTAUTH_URL: http://localhost:3000
DATABASE_URL: file:../db/db.sqlite
SKIP_ENV_VALIDATION: 1 # omit this property to enable schema validation for the environment variables
container_name: autogpt
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY} # openai api key
NEXT_PUBLIC_WEB_SEARCH_ENABLED: ${NEXT_PUBLIC_WEB_SEARCH_ENABLED} # enable web search
SERP_API_KEY: ${SERP_API_KEY} # serp api key
NEXT_PUBLIC_GUEST_KEY: ${NEXT_PUBLIC_GUEST_KEY} # guest key
ports:
- 3000:3000
volumes:
- db:/app/db
- .env:/app/.env
restart: unless-stopped
6 changes: 1 addition & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ services:
autogpt:
image: dogtititi/autogpt-next-web:latest
container_name: autogpt
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY} # openai api key
NEXT_PUBLIC_WEB_SEARCH_ENABLED: ${NEXT_PUBLIC_WEB_SEARCH_ENABLED} # enable web search
SERP_API_KEY: ${SERP_API_KEY} # serp api key
NEXT_PUBLIC_GUEST_KEY: ${NEXT_PUBLIC_GUEST_KEY} # guest key
ports:
- 3000:3000
volumes:
- db:/app/db
- .env:/app/.env
restart: unless-stopped
9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/env sh

# copy .env file if not exists
[ ! -f .env ] && [ -f .env.example ] && cp .env.example .env
cp .env .env.temp
dos2unix .env.temp
cat .env.temp > .env
rm .env.temp

source .env

# change schema.prisma
sed -ie 's/mysql/sqlite/g' prisma/schema.prisma
sed -ie 's/@db.Text//' prisma/schema.prisma
Expand Down
93 changes: 76 additions & 17 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,98 @@
#!/bin/bash
cd "$(dirname "$0")" || exit

# Color escape sequences
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Check if we are running in a terminal that supports colors
if [ -t 1 ]; then
# Use colors
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
NC=$(printf '\033[0m')
fi

# Check if a string matches the "sk-" key pattern
is_valid_sk_key() {
local api_key=$1
local pattern="^sk-[a-zA-Z0-9]{48}$"
[[ $api_key =~ $pattern ]] && return 0 || return 1
}

echo -n "Enter your OpenAI Key (eg: sk...) or press enter to continue with no key: "
read OPENAI_API_KEY
# Set value for NEXT_PUBLIC_WEB_SEARCH_ENABLED
select_web_search_enabled() {
PS3="${GREEN}Do you want to enable web search?${NC} "
options=("true" "false")
select opt in "${options[@]}"; do
case $opt in
"true")
NEXT_PUBLIC_WEB_SEARCH_ENABLED=true
read_variable "${GREEN}Enter your SERP API Key (required):${NC} " "^.+$" "SERP_API_KEY"
break
;;
"false")
NEXT_PUBLIC_WEB_SEARCH_ENABLED=false
break
;;
*) echo "${RED}Please enter a valid option.${NC}" ;;
esac
done
}

# Ask for user input and validate variable values
read_variable() {
local prompt="$1"
local pattern="$2"
local var_name="$3"
local var_val=""
while true; do
read -p "$prompt" var_val
if [[ -z "$var_val" ]]; then
echo -e "${RED}Error: Please enter a valid value for $var_name.${NC}"
elif [[ ! $var_val =~ $pattern ]]; then
echo -e "${RED}Error: Invalid format for $var_name.${NC}"
else
eval "$var_name=$var_val"
echo -e "${GREEN}$var_name set. ✔${NC}"
break
fi
done
}

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

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

echo -n "Enter your serp api key to use web search :"
read SERP_API_KEY
# Get user input for NEXT_PUBLIC_WEB_SEARCH_ENABLED
select_web_search_enabled

echo -e "${GREEN}All required variables set. ✔${NC}"

NEXTAUTH_SECRET=$(openssl rand -base64 32)

ENV="NODE_ENV=development\n\
NEXTAUTH_SECRET=$NEXTAUTH_SECRET\n\
ENV="NEXTAUTH_SECRET=$NEXTAUTH_SECRET\n\
NEXTAUTH_URL=http://localhost:3000\n\
OPENAI_API_KEY=$OPENAI_API_KEY\n\
DATABASE_URL=file:../db/db.sqlite\n\
NEXT_PUBLIC_GUEST_KEY=$NEXT_PUBLIC_GUEST_KEY\n\
SERP_API_KEY=$SERP_API_KEY\n\
NEXT_PUBLIC_WEB_SEARCH_ENABLED=$NEXT_PUBLIC_WEB_SEARCH_ENABLED\n"




printf $ENV > .env
./prisma/useSqlite.sh
npm install
npm run dev

if [ "$1" = "--docker-compose-local" ]; then
docker-compose -f docker-compose-local.yml up -d --remove-orphans
elif [ "$1" = "--docker-compose" ]; then
docker-compose up -d --remove-orphans
else
./prisma/useSqlite.sh
npm install
npm run dev
fi

1 comment on commit 7d9d47e

@vercel
Copy link

@vercel vercel bot commented on 7d9d47e May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

auto-gpt-next-web – ./

auto-gpt-next-web-dogtiti.vercel.app
auto-gpt-next-web-git-main-dogtiti.vercel.app
auto-agentgpt.com

Please sign in to comment.