Skip to content

Add Docker support using Alpine base image #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ go.opencensus.io
go.uber.org
testfiles
gopkg.in

Dockerfile
71 changes: 71 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Stage 1: Build Go backend
FROM golang:1.18.9-alpine3.17 AS backend-builder

# Install necessary build dependencies
RUN apk add --no-cache build-base gcc g++ musl-dev

WORKDIR /go/src/app

# Set Go environment variables taken from scripts/source-me.sh
ENV GO111MODULE=on \
GOBIN=/go/src/app/bin \
GOPATH=/root/go \
PATH=$PATH:/go/src/app/bin:/go/src/app/tools/protoc-3.6.1/bin \
DOCKER_BUILDKIT=1

# Copy Go module files and download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy Go source files
COPY errorlist errorlist/
COPY form form/
COPY serverutil serverutil/
COPY validator validator/
COPY vault-web-server vault-web-server/

# Build Go application
RUN go build -o main ./vault-web-server

# Stage 2: Build React frontend
FROM node:19-alpine3.17 AS frontend-builder

WORKDIR /app

# Copy JavaScript package files and install dependencies
COPY package*.json ./
RUN npm install --ignore-scripts


# Copy React source files and other assets
COPY components components/
COPY config config/
COPY static static/
COPY webpack.config.js .

# Build React frontend
RUN npx webpack --config webpack.config.js

# Stage 3: Assemble the final image
FROM alpine:3.17

# Install only required runtime dependencies
RUN apk add --no-cache ca-certificates poppler-utils

# Copy Go binary from the backend-builder stage
COPY --from=backend-builder /go/src/app/main /app/main

# Copy static files from the frontend-builder stage
COPY --from=frontend-builder /app/static /static
COPY config/websites.json /config/websites.json

# Copy scripts directory
COPY scripts scripts/

# Expose the application port
EXPOSE 8100

# Set the file permission for go-compile.sh and execute Go binary
RUN chmod +x scripts/go-compile.sh
CMD ["/app/main"]

20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ With The Vault, you can:

## Setup

### Install manual dependencies
### Approach 1: Manual Setup

#### Install manual dependencies

1. Install go:

Expand All @@ -42,7 +44,7 @@ I recommend [installing nvm and using it to install node v19](https://medium.com

`sudo apt-get install -y poppler-utils` on Ubuntu, or `brew install poppler` on Mac

### Set up your API keys and endpoints in the `secret` folder
#### Set up your API keys and endpoints in the `secret` folder

1. Create a new file `secret/openai_api_key` and paste your [OpenAI API key](https://platform.openai.com/docs/api-reference/authentication) into it:

Expand All @@ -58,7 +60,7 @@ When setting up your pinecone index, use a vector size of `1536` and keep all th

`echo "https://example-50709b5.svc.asia-southeast1-gcp.pinecone.io" > secret/pinecone_api_endpoint`

### Running the development environment
#### Running the development environment

1. Install javascript package dependencies:

Expand All @@ -74,6 +76,18 @@ When setting up your pinecone index, use a vector size of `1536` and keep all th

4. Visit the local version of the site at http://localhost:8100

### Approach 2: Docker Compose Setup

1. Make sure you have Docker and Docker Compose installed on your system

2. Set up your API keys and endpoints in the `docker-compose.yml` file's environment section

3. Run `docker-compose up` in the project's root directory

4. Visit the local version of the site at http://localhost:8100



## Screenshots:

In the example screenshots, I uploaded a couple of books by Plato and some letters by Alexander Hamilton, showcasing the ability of OP Vault to answer questions based on the uploaded content.
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'

services:
opvault:
build: .
ports:
- "8100:8100"
environment:
- OPENAI_API_KEY=your_openai_api_key
- PINECONE_API_KEY=your_pinecone_api_key
- PINECONE_API_ENDPOINT=your_pinecone_api_endpoint
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"scripts": {
"start": "source ./scripts/source-me.sh && ./scripts/go-compile.sh ./vault-web-server && echo && ./bin/vault-web-server",
"dev": "webpack --progress --watch",
"postinstall": "source ./scripts/source-me.sh && ./scripts/go-compile.sh ./vault-web-server"
},
"postinstall": "source ./scripts/source-me.sh && ./scripts/go-compile.sh ./vault-web-server",
"docker-start": "./scripts/go-compile.sh ./vault-web-server && npm run dev && ./bin/vault-web-server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pashpashpash/vault.git"
Expand Down