Skip to content

Commit

Permalink
Switch Docker 🐳 to non-root (#7)
Browse files Browse the repository at this point in the history
* Chore [Terminal] [Chat Session] add newline

- [+] chore(session.go): add newline after user's input

* Switch Docker 🐳 to non-root

- [+] chore(Dockerfile): optimize Dockerfile by combining COPY commands for go.mod and go.sum files
- [+] feat(Dockerfile): create non-root user and switch to it for improved security
- [+] feat(Dockerfile): set working directory to user's home directory
- [+] feat(Dockerfile): copy pre-built binary file from previous stage to /usr/local/bin/
- [+] feat(Dockerfile): update ENTRYPOINT to use the correct binary name

* Docs [README] add installation instructions

- [+] docs(README.md): add installation instructions for Docker
- [+] docs(README.md): add usage instructions for starting a chat session with GoGenAI
- [+] docs(README.md): add environment variables section to explain API_KEY usage

* Fix Docker 🐳 in Unix-System

- [+] fix(Dockerfile): fix COPY command to copy the contents of /app/cmd/ directory instead of the directory itself
  • Loading branch information
H0llyW00dzZ authored Jan 3, 2024
1 parent a0326bc commit d05b240
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ FROM golang:1.21.5 as builder
WORKDIR /app

# Copy the go.mod and go.sum to download all dependencies.
COPY go.mod ./
COPY go.sum ./
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed.
RUN go mod download
Expand All @@ -27,10 +26,15 @@ FROM alpine:latest
# Install ca-certificates in case the application makes HTTPS requests.
RUN apk --no-cache add ca-certificates

WORKDIR /root/
# Create a non-root user and switch to it.
RUN adduser -D gogenaiterminal
USER gogenaiterminal

# Set the working directory to the user's home directory.
WORKDIR /home/gogenaiterminal

# Copy the pre-built binary file from the previous stage.
COPY --from=builder /app/cmd/ .
COPY --from=builder /app/cmd/ /usr/local/bin/

# Run the binary.
ENTRYPOINT ["./goaiterminal-chat"]
ENTRYPOINT ["gogenaiterminal-chat"]
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,37 @@ Interesting to built it in terminal after touring journey through the Go program
- **Session Chat History**: Maintain a transcript of your dialogue, capturing both queries and AI responses for a continuous conversational flow.
- **Intelligent Shutdown**: Benefit from built-in signal handling for a smooth exit process, ensuring your session ends without disruption and with proper resource cleanup.
- **Realistic Typing Animation**: Enjoy a more lifelike interaction with a simulated typing effect that mimics human conversation timing.
- **Ease of Deployment**: Quickly deploy the chat application using Docker, minimizing setup time and complexity.

> [!NOTE]
> Subject to add more in future without any complex of each functions.
> Subject planning to continuously improve and add features, enhancing functionality without adding unnecessary complexity. Stay tuned for updates!
**`Go`** is designed to be straightforward and efficient, avoiding the unnecessary complexities (fuck complexities, this is `go` anti complexities) often encountered in other programming languages.

## Installation

To use GoGenAI Terminal Chat, you need to have Docker installed on your machine. If you don't have Docker installed, please follow the [official Docker installation guide](https://docs.docker.com/get-docker/).

Once Docker is set up, you can pull the image from GitHub Packages by running:

```sh
docker pull ghcr.io/h0llyw00dzz/gogenai-terminal-chat:latest
```

## Usage

To start a chat session with GoGenAI, run the following command in your terminal. Make sure to replace `YOUR_API_KEY` with the actual API key provided to you.

```sh
docker run -it --rm --name mychatapp -e API_KEY=YOUR_API_KEY ghcr.io/h0llyw00dzz/gogenai-terminal-chat:latest
```

This command will start the GoGenAI Terminal Chat application in interactive mode. You will be able to type your messages and receive responses from the AI.

### Environment Variables

- `API_KEY`: Your API key for accessing the generative AI model. This is a required environment variable.


## Example how it wok

Expand Down
3 changes: 3 additions & 0 deletions terminal/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (s *Session) Start() {
userInput = strings.TrimSpace(userInput)
s.ChatHistory.AddMessage(YouNerd, userInput)

// Add a newline right after the user's input
fmt.Println()

// Pass the entire chat history as context for the AI's response
chatContext := s.ChatHistory.GetHistory()
aiResponse, err := SendMessage(s.Ctx, s.Client, chatContext)
Expand Down

0 comments on commit d05b240

Please sign in to comment.